From fa2945e7a9d9cccb0c6ccaf531c6a34d9d09b489 Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Thu, 6 Sep 2018 12:44:08 -0700 Subject: [PATCH] HDDS-405. User/volume mapping is not cleaned up during the deletion of the last volume. Contributed by Elek, Marton. --- .../hadoop/ozone/om/TestOzoneManager.java | 26 ++++++++++++++++--- .../hadoop/ozone/om/VolumeManagerImpl.java | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManager.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManager.java index b6ade60190..f309715608 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManager.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManager.java @@ -276,10 +276,28 @@ public void testDeleteVolume() throws IOException, OzoneException { Assert.assertTrue(volumeInfo.getVolumeName().equals(volumeName2)); // Make sure volume with _A suffix is successfully deleted. - exception.expect(IOException.class); - exception.expectMessage("Info Volume failed, error:VOLUME_NOT_FOUND"); - volumeArgs = new VolumeArgs(volumeName1, userArgs); - storageHandler.getVolumeInfo(volumeArgs); + try { + volumeArgs = new VolumeArgs(volumeName1, userArgs); + storageHandler.getVolumeInfo(volumeArgs); + Assert.fail("Volume is not deleted"); + } catch (IOException ex) { + Assert.assertEquals("Info Volume failed, error:VOLUME_NOT_FOUND", + ex.getMessage()); + } + //delete the _AA volume, too + storageHandler.deleteVolume(new VolumeArgs(volumeName2, userArgs)); + + //Make sure there is no volume information for the specific user + OMMetadataManager metadataManager = + cluster.getOzoneManager().getMetadataManager(); + + byte[] userKey = metadataManager.getUserKey(userName); + byte[] volumes = metadataManager.getUserTable().get(userKey); + + //that was the last volume of the user, shouldn't be any record here + Assert.assertNull(volumes); + + } // Create a volume and a bucket inside the volume, diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/VolumeManagerImpl.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/VolumeManagerImpl.java index 419b0aaf18..cf25215da7 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/VolumeManagerImpl.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/VolumeManagerImpl.java @@ -110,7 +110,7 @@ private void delVolumeFromOwnerList(String volume, String owner, // Remove the volume from the list prevVolList.remove(volume); if (prevVolList.size() == 0) { - batch.delete(dbUserKey); + batch.delete(metadataManager.getUserTable().getHandle(), dbUserKey); } else { VolumeList newVolList = VolumeList.newBuilder() .addAllVolumeNames(prevVolList).build();