Gargi-jais11 commented on code in PR #9318:
URL: https://github.com/apache/ozone/pull/9318#discussion_r2605181328
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestServerUtils.java:
##########
@@ -263,4 +266,211 @@ public void ozoneMetadataDirRejectsList() {
() -> ServerUtils.getOzoneMetaDirPath(conf));
}
+ /**
+ * Test that SCM, OM, and Datanode colocated on the same host with only
+ * ozone.metadata.dirs configured don't conflict with Ratis directories.
+ */
+ @Test
+ public void testColocatedComponentsWithSharedMetadataDir() {
+ final File metaDir = new File(folder.toFile(), "sharedMetaDir");
+ final OzoneConfiguration conf = new OzoneConfiguration();
+
+ // Only configure ozone.metadata.dirs (the fallback config)
+ conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
+
+ try {
+ assertFalse(metaDir.exists());
+
+ // Test Ratis directories - each component should get its own with flat
naming
+ String scmRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.SCM);
+ String omRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.OM);
+ String dnRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.DATANODE);
+
+ // Verify Ratis directories use flat naming pattern (component.ratis)
+ assertEquals(new File(metaDir, "scm.ratis").getPath(), scmRatisDir);
+ assertEquals(new File(metaDir, "om.ratis").getPath(), omRatisDir);
+ assertEquals(new File(metaDir, "datanode.ratis").getPath(), dnRatisDir);
+
+ // Verify all Ratis directories are different
+ assertNotEquals(scmRatisDir, omRatisDir);
+ assertNotEquals(scmRatisDir, dnRatisDir);
+ assertNotEquals(omRatisDir, dnRatisDir);
+
+ // Verify the base metadata dir exists
+ assertTrue(metaDir.exists());
+
+ } finally {
+ FileUtils.deleteQuietly(metaDir);
+ }
+ }
+
+ /**
+ * Test backward compatibility: old shared /ratis directory should be used
+ * when it exists and is non-empty (simulating upgrade from version 2.0.0).
+ */
+ @Test
+ public void testBackwardCompatibilityWithOldSharedRatisDir() throws
IOException {
+ final File metaDir = new File(folder.toFile(), "upgradeMetaDir");
+ final File oldSharedRatisDir = new File(metaDir, "ratis");
+ final OzoneConfiguration conf = new OzoneConfiguration();
+ conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
+
+ try {
+ // Create old shared ratis directory with some files (simulating
existing data)
+ assertTrue(oldSharedRatisDir.mkdirs());
+ File testFile = new File(oldSharedRatisDir, "test-file");
+ assertTrue(testFile.createNewFile());
+
+ // Test that all components use the old shared location
+ String scmRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.SCM);
+ String omRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.OM);
+ String dnRatisDir = ServerUtils.getDefaultRatisDirectory(conf,
HddsProtos.NodeType.DATANODE);
+
+ // All should use the old shared location
+ assertEquals(oldSharedRatisDir.getPath(), scmRatisDir);
+ assertEquals(oldSharedRatisDir.getPath(), omRatisDir);
+ assertEquals(oldSharedRatisDir.getPath(), dnRatisDir);
+
+ } finally {
+ FileUtils.deleteQuietly(metaDir);
+ }
+ }
+
+ /**
+ * Test that SCM and OM colocated on the same host with only
+ * ozone.metadata.dirs configured get separate Ratis snapshot directories.
+ */
+ @Test
+ public void testColocatedComponentsWithSharedMetadataDirForSnapshots() {
+ final File metaDir = new File(folder.toFile(), "sharedMetaDir");
+ final OzoneConfiguration conf = new OzoneConfiguration();
+
+ // Only configure ozone.metadata.dirs (the fallback config)
+ conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
+
+ try {
+ assertFalse(metaDir.exists());
+
+ // Test Ratis snapshot directories - OM and SCM should get their own
+ String scmSnapshotDir =
ServerUtils.getDefaultRatisSnapshotDirectory(conf, HddsProtos.NodeType.SCM);
+ String omSnapshotDir =
ServerUtils.getDefaultRatisSnapshotDirectory(conf, HddsProtos.NodeType.OM);
+
+ // Verify snapshot directories use:
<ozone.metadata.dirs>/<component>.ratis.snapshot
+ assertEquals(new File(metaDir, "scm.ratis.snapshot").getPath(),
scmSnapshotDir);
+ assertEquals(new File(metaDir, "om.ratis.snapshot").getPath(),
omSnapshotDir);
+
+ // Verify snapshot directories are different
+ assertNotEquals(scmSnapshotDir, omSnapshotDir);
+
+ // Verify the base metadata dir exists
+ assertTrue(metaDir.exists());
+
+ } finally {
+ FileUtils.deleteQuietly(metaDir);
+ }
+ }
+
+ /**
+ * Test backward compatibility: snapshot directory inside old shared /ratis
directory
+ * should be used when it exists and is non-empty (nested structure).
+ * Note: This tests OM and SCM backward compatibility. SCM checks
/ratis/snapshot
+ * after checking /scm-ha/snapshot (which is tested separately).
+ */
+ @Test
+ public void testBackwardCompatibilityWithSnapshotInOldRatisDir() throws
IOException {
+ final File metaDir = new File(folder.toFile(), "upgradeMetaDir");
+ final File oldRatisDir = new File(metaDir, "ratis");
Review Comment:
Yaa sure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]