ソースを参照

HDDS-1684. OM should create Ratis related dirs only if ratis is enabled (#965)

Hanisha Koneru 6 年 前
コミット
2dfa932818

+ 1 - 1
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestHddsDispatcher.java

@@ -74,12 +74,12 @@ public class TestHddsDispatcher {
     String testDir = GenericTestUtils.getTempPath(
     String testDir = GenericTestUtils.getTempPath(
         TestHddsDispatcher.class.getSimpleName());
         TestHddsDispatcher.class.getSimpleName());
     OzoneConfiguration conf = new OzoneConfiguration();
     OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(HDDS_DATANODE_DIR_KEY, testDir);
     DatanodeDetails dd = randomDatanodeDetails();
     DatanodeDetails dd = randomDatanodeDetails();
     VolumeSet volumeSet = new VolumeSet(dd.getUuidString(), conf);
     VolumeSet volumeSet = new VolumeSet(dd.getUuidString(), conf);
 
 
     try {
     try {
       UUID scmId = UUID.randomUUID();
       UUID scmId = UUID.randomUUID();
-      conf.set(HDDS_DATANODE_DIR_KEY, testDir);
       ContainerSet containerSet = new ContainerSet();
       ContainerSet containerSet = new ContainerSet();
 
 
       DatanodeStateMachine stateMachine = Mockito.mock(
       DatanodeStateMachine stateMachine = Mockito.mock(

+ 0 - 22
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManager.java

@@ -85,7 +85,6 @@ import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRE
 import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
 import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
-import org.apache.ratis.util.LifeCycle;
 import org.junit.After;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Before;
@@ -1365,27 +1364,6 @@ public class TestOzoneManager {
         conf.get(OZONE_SCM_CLIENT_ADDRESS_KEY)), scmAddress);
         conf.get(OZONE_SCM_CLIENT_ADDRESS_KEY)), scmAddress);
   }
   }
 
 
-  /**
-   * Test that OM Ratis server is started only when OZONE_OM_RATIS_ENABLE_KEY is
-   * set to true.
-   */
-  @Test
-  public void testRatisServerOnOMInitialization() throws IOException {
-    // OM Ratis server should not be started when OZONE_OM_RATIS_ENABLE_KEY
-    // is not set to true
-    Assert.assertNull("OM Ratis server started though OM Ratis is disabled.",
-        cluster.getOzoneManager().getOmRatisServerState());
-
-    // Enable OM Ratis and restart OM
-    conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, true);
-    cluster.restartOzoneManager();
-
-    // On enabling OM Ratis, the Ratis server should be started
-    Assert.assertEquals("OM Ratis server did not start",
-        LifeCycle.State.RUNNING,
-        cluster.getOzoneManager().getOmRatisServerState());
-  }
-
   @Test
   @Test
   public void testVersion() {
   public void testVersion() {
     String expectedVersion = OzoneVersionInfo.OZONE_VERSION_INFO.getVersion();
     String expectedVersion = OzoneVersionInfo.OZONE_VERSION_INFO.getVersion();

+ 1 - 0
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerSnapshotProvider.java

@@ -63,6 +63,7 @@ public class TestOzoneManagerSnapshotProvider {
     clusterId = UUID.randomUUID().toString();
     clusterId = UUID.randomUUID().toString();
     scmId = UUID.randomUUID().toString();
     scmId = UUID.randomUUID().toString();
     conf.setBoolean(OMConfigKeys.OZONE_OM_HTTP_ENABLED_KEY, true);
     conf.setBoolean(OMConfigKeys.OZONE_OM_HTTP_ENABLED_KEY, true);
+    conf.setBoolean(OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY, true);
     cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf)
     cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf)
         .setClusterId(clusterId)
         .setClusterId(clusterId)
         .setScmId(scmId)
         .setScmId(scmId)

+ 24 - 27
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java

@@ -313,12 +313,33 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
         ProtobufRpcEngine.class);
         ProtobufRpcEngine.class);
 
 
     metadataManager = new OmMetadataManagerImpl(configuration);
     metadataManager = new OmMetadataManagerImpl(configuration);
+
+    // This is a temporary check. Once fully implemented, all OM state change
+    // should go through Ratis - be it standalone (for non-HA) or replicated
+    // (for HA).
+    isRatisEnabled = configuration.getBoolean(
+        OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
+        OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
     startRatisServer();
     startRatisServer();
     startRatisClient();
     startRatisClient();
 
 
-    if (peerNodes != null && !peerNodes.isEmpty()) {
-      this.omSnapshotProvider = new OzoneManagerSnapshotProvider(configuration,
-          omRatisSnapshotDir, peerNodes);
+    if (isRatisEnabled) {
+      // Create Ratis storage dir
+      String omRatisDirectory = OmUtils.getOMRatisDirectory(configuration);
+      if (omRatisDirectory == null || omRatisDirectory.isEmpty()) {
+        throw new IllegalArgumentException(HddsConfigKeys.OZONE_METADATA_DIRS +
+            " must be defined.");
+      }
+      OmUtils.createOMDir(omRatisDirectory);
+
+      // Create Ratis snapshot dir
+      omRatisSnapshotDir = OmUtils.createOMDir(
+          OmUtils.getOMRatisSnapshotDirectory(configuration));
+
+      if (peerNodes != null && !peerNodes.isEmpty()) {
+        this.omSnapshotProvider = new OzoneManagerSnapshotProvider(
+            configuration, omRatisSnapshotDir, peerNodes);
+      }
     }
     }
 
 
     this.ratisSnapshotFile = new File(omStorage.getCurrentDir(),
     this.ratisSnapshotFile = new File(omStorage.getCurrentDir(),
@@ -542,18 +563,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
     configuration.set(OZONE_OM_ADDRESS_KEY,
     configuration.set(OZONE_OM_ADDRESS_KEY,
         NetUtils.getHostPortString(rpcAddress));
         NetUtils.getHostPortString(rpcAddress));
 
 
-    // Create Ratis storage dir
-    String omRatisDirectory = OmUtils.getOMRatisDirectory(configuration);
-    if (omRatisDirectory == null || omRatisDirectory.isEmpty()) {
-      throw new IllegalArgumentException(HddsConfigKeys.OZONE_METADATA_DIRS +
-          " must be defined.");
-    }
-    OmUtils.createOMDir(omRatisDirectory);
-
-    // Create Ratis snapshot dir
-    omRatisSnapshotDir = OmUtils.createOMDir(
-        OmUtils.getOMRatisSnapshotDirectory(configuration));
-
     // Get and set Http(s) address of local node. If base config keys are
     // Get and set Http(s) address of local node. If base config keys are
     // not set, check for keys suffixed with OM serivce ID and node ID.
     // not set, check for keys suffixed with OM serivce ID and node ID.
     setOMNodeSpecificConfigs(serviceId, nodeId);
     setOMNodeSpecificConfigs(serviceId, nodeId);
@@ -1253,12 +1262,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
    * Creates an instance of ratis server.
    * Creates an instance of ratis server.
    */
    */
   private void startRatisServer() throws IOException {
   private void startRatisServer() throws IOException {
-    // This is a temporary check. Once fully implemented, all OM state change
-    // should go through Ratis - be it standalone (for non-HA) or replicated
-    // (for HA).
-    isRatisEnabled = configuration.getBoolean(
-        OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
-        OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
     if (isRatisEnabled) {
     if (isRatisEnabled) {
       if (omRatisServer == null) {
       if (omRatisServer == null) {
         omRatisServer = OzoneManagerRatisServer.newOMRatisServer(
         omRatisServer = OzoneManagerRatisServer.newOMRatisServer(
@@ -1277,12 +1280,6 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
    * Creates an instance of ratis client.
    * Creates an instance of ratis client.
    */
    */
   private void startRatisClient() throws IOException {
   private void startRatisClient() throws IOException {
-    // This is a temporary check. Once fully implemented, all OM state change
-    // should go through Ratis - be it standalone (for non-HA) or replicated
-    // (for HA).
-    isRatisEnabled = configuration.getBoolean(
-      OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
-      OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
     if (isRatisEnabled) {
     if (isRatisEnabled) {
       if (omRatisClient == null) {
       if (omRatisClient == null) {
         omRatisClient = OzoneManagerRatisClient.newOzoneManagerRatisClient(
         omRatisClient = OzoneManagerRatisClient.newOzoneManagerRatisClient(