This is an automated email from the ASF dual-hosted git repository. hexiaoqiao pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new 9ac498e HDFS-15416. Improve DataStorage#addStorageLocations() for empty locations. Contibuted by jianghua zhu. 9ac498e is described below commit 9ac498e30057de1291c3e3128bceaa1af9547c67 Author: He Xiaoqiao <hexiaoq...@apache.org> AuthorDate: Wed Jul 1 12:30:10 2020 +0800 HDFS-15416. Improve DataStorage#addStorageLocations() for empty locations. Contibuted by jianghua zhu. --- .../hadoop/hdfs/server/datanode/DataStorage.java | 5 ++++ .../hdfs/server/datanode/TestDataStorage.java | 28 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java index 2447fd7..b7faecb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java @@ -388,6 +388,11 @@ public class DataStorage extends Storage { try { final List<StorageLocation> successLocations = loadDataStorage( datanode, nsInfo, dataDirs, startOpt, executor); + + if (successLocations.isEmpty()) { + return Lists.newArrayList(); + } + return loadBlockPoolSliceStorage( datanode, nsInfo, successLocations, startOpt, executor); } finally { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java index 6c49451..f82462a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java @@ -44,6 +44,7 @@ import static org.junit.Assert.fail; public class TestDataStorage { private final static String DEFAULT_BPID = "bp-0"; private final static String CLUSTER_ID = "cluster0"; + private final static String CLUSTER_ID2 = "cluster1"; private final static String BUILD_VERSION = "2.0"; private final static String SOFTWARE_VERSION = "2.0"; private final static long CTIME = 1; @@ -166,6 +167,33 @@ public class TestDataStorage { } @Test + public void testAddStorageDirectoriesFailure() throws IOException { + final int numLocations = 1; + List<StorageLocation> locations = createStorageLocations(numLocations); + assertEquals(numLocations, locations.size()); + + NamespaceInfo namespaceInfo = new NamespaceInfo(0, CLUSTER_ID, + DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); + List<StorageDirectory> successLocations = storage.addStorageLocations( + mockDN, namespaceInfo, locations, START_OPT); + assertEquals(1, successLocations.size()); + + // After the DataNode restarts, the value of the clusterId is different + // from the value before the restart. + storage.unlockAll(); + DataNode newMockDN = Mockito.mock(DataNode.class); + Mockito.when(newMockDN.getConf()).thenReturn(new HdfsConfiguration()); + DataStorage newStorage = new DataStorage(); + NamespaceInfo newNamespaceInfo = new NamespaceInfo(0, CLUSTER_ID2, + DEFAULT_BPID, CTIME, BUILD_VERSION, SOFTWARE_VERSION); + successLocations = newStorage.addStorageLocations( + newMockDN, newNamespaceInfo, locations, START_OPT); + assertEquals(0, successLocations.size()); + newStorage.unlockAll(); + newMockDN.shutdown(); + } + + @Test public void testMissingVersion() throws IOException, URISyntaxException { final int numLocations = 1; --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org