diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java index a4f4503070..1f86bd0143 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/StorageContainerManager.java @@ -226,9 +226,8 @@ private StorageContainerManager(OzoneConfiguration conf) StorageContainerManager.initMetrics(); scmStorage = new SCMStorage(conf); - String clusterId = scmStorage.getClusterID(); - if (clusterId == null) { - throw new SCMException("clusterId not found", + if (scmStorage.getState() != StorageState.INITIALIZED) { + throw new SCMException("SCM not initialized.", ResultCodes.SCM_NOT_INITIALIZED); } scmNodeManager = new SCMNodeManager(conf, scmStorage.getClusterID()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java index 305eb2996e..e42065d772 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java @@ -34,6 +34,7 @@ import org.apache.hadoop.ozone.scm.StorageContainerManager.StartupOption; import org.apache.hadoop.ozone.scm.block.DeletedBlockLog; import org.apache.hadoop.ozone.scm.block.SCMBlockDeletingService; +import org.apache.hadoop.ozone.scm.exceptions.SCMException; import org.apache.hadoop.ozone.scm.node.NodeManager; import org.apache.hadoop.scm.XceiverClientManager; import org.apache.hadoop.scm.container.common.helpers.Pipeline; @@ -396,4 +397,17 @@ public void testSCMReinitialization() throws Exception { Assert.assertEquals(OzoneConsts.NodeType.SCM, scmStore.getNodeType()); Assert.assertNotEquals("testClusterId", scmStore.getClusterID()); } + + @Test + public void testSCMInitializationFailure() throws IOException { + OzoneConfiguration conf = new OzoneConfiguration(); + final String path = + GenericTestUtils.getTempPath(UUID.randomUUID().toString()); + Path scmPath = Paths.get(path, "scm-meta"); + conf.set(OzoneConfigKeys.OZONE_METADATA_DIRS, scmPath.toString()); + conf.setBoolean(OzoneConfigKeys.OZONE_ENABLED, true); + exception.expect(SCMException.class); + exception.expectMessage("SCM not initialized."); + StorageContainerManager.createSCM(null, conf); + } }