priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3479587551
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueContainer.java:
##########
@@ -759,6 +760,35 @@ public void testReportOfUnhealthyContainer(
assertNotNull(keyValueContainer.getContainerReport());
}
+ /**
+ * When a container's metadata directory is missing (MISSING_METADATA_DIR
detected by the scanner),
+ * markContainerUnhealthy must succeed without throwing. Writing a partial
.container file with only
+ * the state field would lose other metadata and is more harmful than
writing nothing. The in-memory
+ * UNHEALTHY state is sufficient for SCM to receive it via ICR and schedule
deletion.
+ */
+ @ContainerTestVersionInfo.ContainerTest
+ public void testMarkUnhealthyWithMissingMetadataDir(ContainerTestVersionInfo
versionInfo) throws Exception {
+ init(versionInfo);
+ keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
+
+ // Simulate MISSING_METADATA_DIR using the same corruption helper used in
scanner tests.
+ File metadataDir = new File(keyValueContainerData.getMetadataPath());
+ assertTrue(metadataDir.exists(), "Metadata dir should exist before
corruption");
+ MISSING_METADATA_DIR.applyTo(keyValueContainer);
+
+ // markContainerUnhealthy must not throw even though the metadata dir is
absent.
+ keyValueContainer.markContainerUnhealthy();
+
+ // In-memory state must be UNHEALTHY.
+ assertEquals(ContainerProtos.ContainerDataProto.State.UNHEALTHY,
+ keyValueContainer.getContainerState());
+
+ // The metadata directory must NOT be recreated; no partial .container
file should be written.
+ assertFalse(metadataDir.exists(), "Metadata dir should not be recreated by
markContainerUnhealthy");
Review Comment:
Make sense. Let me change the comments to accurately describe their role and
thiswill guards against a future implementation that accidentally recreates
the directory or writes a partial .container file.
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueContainer.java:
##########
@@ -759,6 +760,35 @@ public void testReportOfUnhealthyContainer(
assertNotNull(keyValueContainer.getContainerReport());
}
+ /**
+ * When a container's metadata directory is missing (MISSING_METADATA_DIR
detected by the scanner),
+ * markContainerUnhealthy must succeed without throwing. Writing a partial
.container file with only
+ * the state field would lose other metadata and is more harmful than
writing nothing. The in-memory
+ * UNHEALTHY state is sufficient for SCM to receive it via ICR and schedule
deletion.
+ */
+ @ContainerTestVersionInfo.ContainerTest
+ public void testMarkUnhealthyWithMissingMetadataDir(ContainerTestVersionInfo
versionInfo) throws Exception {
+ init(versionInfo);
+ keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
+
+ // Simulate MISSING_METADATA_DIR using the same corruption helper used in
scanner tests.
+ File metadataDir = new File(keyValueContainerData.getMetadataPath());
+ assertTrue(metadataDir.exists(), "Metadata dir should exist before
corruption");
+ MISSING_METADATA_DIR.applyTo(keyValueContainer);
+
+ // markContainerUnhealthy must not throw even though the metadata dir is
absent.
+ keyValueContainer.markContainerUnhealthy();
+
+ // In-memory state must be UNHEALTHY.
+ assertEquals(ContainerProtos.ContainerDataProto.State.UNHEALTHY,
+ keyValueContainer.getContainerState());
+
+ // The metadata directory must NOT be recreated; no partial .container
file should be written.
+ assertFalse(metadataDir.exists(), "Metadata dir should not be recreated by
markContainerUnhealthy");
Review Comment:
Make sense. Let me change the comments to accurately describe their role and
this will guards against a future implementation that accidentally recreates
the directory or writes a partial .container file.
--
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]