-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-13572. SCMSnapshotProvider should not auto-create Ratis directory #9689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.protobuf.BlockingService; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.math.BigInteger; | ||
| import java.net.InetAddress; | ||
|
|
@@ -374,8 +375,25 @@ private StorageContainerManager(OzoneConfiguration conf, | |
| // This is for the clusters which got upgraded from older version of Ozone. | ||
| // We enable Ratis by default. | ||
| if (!scmStorageConfig.isSCMHAEnabled()) { | ||
| // Create Ratis snapshot directory for upgrade scenario. | ||
| // This must be done before initializeRatis() since SCMSnapshotProvider | ||
| // expects the directory to already exist during normal startup. | ||
| String snapshotDir = SCMHAUtils.getSCMRatisSnapshotDirectory(conf); | ||
| HddsUtils.createDir(snapshotDir); | ||
| LOG.info("Upgrade: created Ratis snapshot directory: {}", snapshotDir); | ||
|
|
||
| // Since we have initialized Ratis, we have to reload StorageConfig | ||
| scmStorageConfig = initializeRatis(conf); | ||
| } else { | ||
| // For clusters upgraded from older versions that already have SCMHAEnabled | ||
| // but may not have the snapshot directory (it was auto-created by | ||
|
Comment on lines
+388
to
+389
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could older versions with HA do not have the snapshot directory? I guess it is possible only if older versions is non-HA, then it does not have the snapshot directory. Further, if it is updated to a newer version and enable HA at the same time, it could hit this case. Is it the case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Integration Test (Upgrade) covers this scenario. See driver.sh:
In step 2, the cluster already has |
||
| // SCMSnapshotProvider in older versions), ensure the directory exists. | ||
| String snapshotDir = SCMHAUtils.getSCMRatisSnapshotDirectory(conf); | ||
| File snapshotDirFile = new File(snapshotDir); | ||
| if (!snapshotDirFile.exists()) { | ||
| HddsUtils.createDir(snapshotDir); | ||
| LOG.info("Created missing Ratis snapshot directory for upgraded cluster: {}", snapshotDir); | ||
| } | ||
| } | ||
|
|
||
| threadNamePrefix = getScmNodeDetails().threadNamePrefix(); | ||
|
|
@@ -1210,6 +1228,16 @@ public static boolean scmBootstrap(OzoneConfiguration conf) | |
| scmStorageConfig.setPrimaryScmNodeId(scmInfo.getScmId()); | ||
| scmStorageConfig.setSCMHAFlag(true); | ||
| scmStorageConfig.initialize(); | ||
|
|
||
| // Create Ratis storage and snapshot directories during bootstrap | ||
| // This ensures they exist before the bootstrapped SCM starts normally | ||
| String ratisStorageDir = SCMHAUtils.getSCMRatisDirectory(conf); | ||
| String ratisSnapshotDir = SCMHAUtils.getSCMRatisSnapshotDirectory(conf); | ||
| HddsUtils.createDir(ratisStorageDir); | ||
| HddsUtils.createDir(ratisSnapshotDir); | ||
| LOG.info("Created Ratis storage directory: {}", ratisStorageDir); | ||
| LOG.info("Created Ratis snapshot directory: {}", ratisSnapshotDir); | ||
|
|
||
| LOG.info("SCM BootStrap is successful for ClusterID {}, SCMID {}", | ||
| scmInfo.getClusterId(), scmStorageConfig.getScmId()); | ||
| LOG.info("Primary SCM Node ID {}", | ||
|
|
@@ -1290,6 +1318,14 @@ public static boolean scmInit(OzoneConfiguration conf, | |
|
|
||
| scmStorageConfig.setPrimaryScmNodeId(scmStorageConfig.getScmId()); | ||
| scmStorageConfig.initialize(); | ||
|
|
||
| // Create Ratis snapshot directory during init. | ||
| // This must be done before SCM starts normally since SCMSnapshotProvider | ||
| // expects the directory to already exist. | ||
| String snapshotDir = SCMHAUtils.getSCMRatisSnapshotDirectory(conf); | ||
| HddsUtils.createDir(snapshotDir); | ||
| LOG.info("Init: created Ratis snapshot directory: {}", snapshotDir); | ||
|
|
||
| scmStorageConfig = initializeRatis(conf); | ||
|
|
||
| LOG.info("SCM initialization succeeded. Current cluster id for sd={}" | ||
|
|
@@ -1340,6 +1376,7 @@ private static SCMStorageConfig initializeRatis(OzoneConfiguration conf) | |
| final SCMHANodeDetails haDetails = SCMHANodeDetails.loadSCMHAConfig(conf, storageConfig); | ||
| SCMRatisServerImpl.initialize(storageConfig.getClusterID(), | ||
| storageConfig.getScmId(), haDetails.getLocalNodeDetails(), conf); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this whitespace change.. |
||
| storageConfig.setSCMHAFlag(true); | ||
| storageConfig.setPrimaryScmNodeId(storageConfig.getScmId()); | ||
| storageConfig.forceInitialize(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.hdds.scm.ha; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.file.Path; | ||
| import org.apache.hadoop.hdds.HddsConfigKeys; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.scm.ScmConfigKeys; | ||
| import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| /** | ||
| * Test cases for {@link SCMSnapshotProvider}. | ||
| */ | ||
| class TestSCMSnapshotProvider { | ||
|
|
||
| /** | ||
| * Test constructor succeeds when both Ratis storage and snapshot directories exist. | ||
| */ | ||
| @Test | ||
| void testConstructorSucceedsWithExistingDirectories(@TempDir Path tempDir) { | ||
| // Setup: Create both directories (simulating initialized SCM) | ||
| OzoneConfiguration conf = createConfig(tempDir); | ||
| String ratisDir = SCMHAUtils.getSCMRatisDirectory(conf); | ||
| String snapshotDir = SCMHAUtils.getSCMRatisSnapshotDirectory(conf); | ||
|
|
||
| assertTrue(new File(ratisDir).mkdirs()); | ||
| assertTrue(new File(snapshotDir).mkdirs()); | ||
|
|
||
| CertificateClient certClient = mock(CertificateClient.class); | ||
|
|
||
| // Test | ||
| SCMSnapshotProvider provider = new SCMSnapshotProvider( | ||
| conf, null, certClient); | ||
|
|
||
| // Verify | ||
| assertNotNull(provider); | ||
| assertNotNull(provider.getScmSnapshotDir()); | ||
| assertTrue(provider.getScmSnapshotDir().exists()); | ||
| assertEquals(snapshotDir, provider.getScmSnapshotDir().getAbsolutePath()); | ||
| } | ||
|
|
||
| /** | ||
| * Test constructor fails when snapshot directory does not exist. | ||
| */ | ||
| @Test | ||
| void testConstructorFailsWhenSnapshotDirMissing(@TempDir Path tempDir) { | ||
| // Setup: Create only Ratis storage directory, not snapshot directory | ||
| OzoneConfiguration conf = createConfig(tempDir); | ||
| String ratisDir = SCMHAUtils.getSCMRatisDirectory(conf); | ||
| assertTrue(new File(ratisDir).mkdirs()); | ||
|
|
||
| CertificateClient certClient = mock(CertificateClient.class); | ||
|
|
||
| // Test & Verify | ||
| IllegalStateException exception = assertThrows( | ||
| IllegalStateException.class, | ||
| () -> new SCMSnapshotProvider(conf, null, certClient)); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Ratis snapshot directory does not exist")); | ||
| } | ||
|
|
||
| /** | ||
| * Test constructor fails when Ratis storage directory does not exist. | ||
| */ | ||
| @Test | ||
| void testConstructorFailsWhenRatisDirMissing(@TempDir Path tempDir) { | ||
| // Setup: Don't create any directories | ||
| OzoneConfiguration conf = createConfig(tempDir); | ||
| CertificateClient certClient = mock(CertificateClient.class); | ||
|
|
||
| // Test & Verify | ||
| IllegalStateException exception = assertThrows( | ||
| IllegalStateException.class, | ||
| () -> new SCMSnapshotProvider(conf, null, certClient)); | ||
|
|
||
| assertTrue(exception.getMessage().contains("Ratis storage directory does not exist")); | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to create OzoneConfiguration with temp directories. | ||
| */ | ||
| private OzoneConfiguration createConfig(Path tempDir) { | ||
| OzoneConfiguration conf = new OzoneConfiguration(); | ||
|
|
||
| String metadataDir = tempDir.resolve("metadata").toString(); | ||
| String ratisStorageDir = tempDir.resolve("ratis").toString(); | ||
| String ratisSnapshotDir = tempDir.resolve("ratis-snapshot").toString(); | ||
|
|
||
| conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metadataDir); | ||
| conf.set(ScmConfigKeys.OZONE_SCM_HA_RATIS_STORAGE_DIR, ratisStorageDir); | ||
| conf.set(ScmConfigKeys.OZONE_SCM_HA_RATIS_SNAPSHOT_DIR, ratisSnapshotDir); | ||
|
|
||
| return conf; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has only whitespace changes. Please revert them.