|
@@ -18,22 +18,30 @@
|
|
|
|
|
|
package org.apache.hadoop.ozone.container.common.volume;
|
|
package org.apache.hadoop.ozone.container.common.volume;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
+import org.apache.hadoop.fs.FileUtil;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
-import org.apache.hadoop.hdds.protocol.DatanodeDetails;
|
|
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
|
|
import org.apache.hadoop.ozone.container.common.utils.HddsVolumeUtil;
|
|
import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
|
|
import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
|
|
|
|
+
|
|
|
|
+import static org.apache.hadoop.ozone.container.common.volume.HddsVolume
|
|
|
|
+ .HDDS_VOLUME_DIR;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
+
|
|
|
|
+import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.rules.Timeout;
|
|
import org.junit.rules.Timeout;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
@@ -69,6 +77,28 @@ public class TestVolumeSet {
|
|
initializeVolumeSet();
|
|
initializeVolumeSet();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @After
|
|
|
|
+ public void shutdown() throws IOException {
|
|
|
|
+ // Delete the hdds volume root dir
|
|
|
|
+ List<HddsVolume> volumes = new ArrayList<>();
|
|
|
|
+ volumes.addAll(volumeSet.getVolumesList());
|
|
|
|
+ volumes.addAll(volumeSet.getFailedVolumesList());
|
|
|
|
+
|
|
|
|
+ for (HddsVolume volume : volumes) {
|
|
|
|
+ FileUtils.deleteDirectory(volume.getHddsRootDir());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean checkVolumeExistsInVolumeSet(String volume) {
|
|
|
|
+ for (HddsVolume hddsVolume : volumeSet.getVolumesList()) {
|
|
|
|
+ if (hddsVolume.getHddsRootDir().getPath().equals(
|
|
|
|
+ HddsVolumeUtil.getHddsRoot(volume))) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testVolumeSetInitialization() throws Exception {
|
|
public void testVolumeSetInitialization() throws Exception {
|
|
|
|
|
|
@@ -84,14 +114,18 @@ public class TestVolumeSet {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void testAddVolume() throws Exception {
|
|
|
|
|
|
+ public void testAddVolume() {
|
|
|
|
|
|
assertEquals(2, volumeSet.getVolumesList().size());
|
|
assertEquals(2, volumeSet.getVolumesList().size());
|
|
|
|
|
|
// Add a volume to VolumeSet
|
|
// Add a volume to VolumeSet
|
|
String volume3 = baseDir + "disk3";
|
|
String volume3 = baseDir + "disk3";
|
|
- volumeSet.addVolume(volume3);
|
|
|
|
|
|
+// File dir3 = new File(volume3, "hdds");
|
|
|
|
+// File[] files = dir3.listFiles();
|
|
|
|
+// System.out.println("------ " + files[0].getPath());
|
|
|
|
+ boolean success = volumeSet.addVolume(volume3);
|
|
|
|
|
|
|
|
+ assertTrue(success);
|
|
assertEquals(3, volumeSet.getVolumesList().size());
|
|
assertEquals(3, volumeSet.getVolumesList().size());
|
|
assertTrue("AddVolume did not add requested volume to VolumeSet",
|
|
assertTrue("AddVolume did not add requested volume to VolumeSet",
|
|
checkVolumeExistsInVolumeSet(volume3));
|
|
checkVolumeExistsInVolumeSet(volume3));
|
|
@@ -122,7 +156,6 @@ public class TestVolumeSet {
|
|
@Test
|
|
@Test
|
|
public void testRemoveVolume() throws Exception {
|
|
public void testRemoveVolume() throws Exception {
|
|
|
|
|
|
- List<HddsVolume> volumesList = volumeSet.getVolumesList();
|
|
|
|
assertEquals(2, volumeSet.getVolumesList().size());
|
|
assertEquals(2, volumeSet.getVolumesList().size());
|
|
|
|
|
|
// Remove a volume from VolumeSet
|
|
// Remove a volume from VolumeSet
|
|
@@ -141,13 +174,34 @@ public class TestVolumeSet {
|
|
+ expectedLogMessage, logs.getOutput().contains(expectedLogMessage));
|
|
+ expectedLogMessage, logs.getOutput().contains(expectedLogMessage));
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean checkVolumeExistsInVolumeSet(String volume) {
|
|
|
|
- for (HddsVolume hddsVolume : volumeSet.getVolumesList()) {
|
|
|
|
- if (hddsVolume.getHddsRootDir().getPath().equals(
|
|
|
|
- HddsVolumeUtil.getHddsRoot(volume))) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testVolumeInInconsistentState() throws Exception {
|
|
|
|
+ assertEquals(2, volumeSet.getVolumesList().size());
|
|
|
|
+
|
|
|
|
+ // Add a volume to VolumeSet
|
|
|
|
+ String volume3 = baseDir + "disk3";
|
|
|
|
+
|
|
|
|
+ // Create the root volume dir and create a sub-directory within it.
|
|
|
|
+ File newVolume = new File(volume3, HDDS_VOLUME_DIR);
|
|
|
|
+ System.out.println("new volume root: " + newVolume);
|
|
|
|
+ newVolume.mkdirs();
|
|
|
|
+ assertTrue("Failed to create new volume root", newVolume.exists());
|
|
|
|
+ File dataDir = new File(newVolume, "chunks");
|
|
|
|
+ dataDir.mkdirs();
|
|
|
|
+ assertTrue(dataDir.exists());
|
|
|
|
+
|
|
|
|
+ // The new volume is in an inconsistent state as the root dir is
|
|
|
|
+ // non-empty but the version file does not exist. Add Volume should
|
|
|
|
+ // return false.
|
|
|
|
+ boolean success = volumeSet.addVolume(volume3);
|
|
|
|
+
|
|
|
|
+ assertFalse(success);
|
|
|
|
+ assertEquals(2, volumeSet.getVolumesList().size());
|
|
|
|
+ assertTrue("AddVolume should fail for an inconsistent volume",
|
|
|
|
+ !checkVolumeExistsInVolumeSet(volume3));
|
|
|
|
+
|
|
|
|
+ // Delete volume3
|
|
|
|
+ File volume = new File(volume3);
|
|
|
|
+ FileUtils.deleteDirectory(volume);
|
|
}
|
|
}
|
|
}
|
|
}
|