You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "priyeshkaratha (via GitHub)" <gi...@apache.org> on 2026/06/20 15:44:08 UTC
[PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
priyeshkaratha opened a new pull request, #10565:
URL: https://github.com/apache/ozone/pull/10565
## What changes were proposed in this pull request?
When the container metadata scanner detects a MISSING_METADATA_DIR corruption, it attempts to persist the UNHEALTHY state by writing the .container file. However, writeToContainerFile creates a temp file inside the metadata directory itself — the very directory that is missing — causing a secondary StorageContainerException: Failed to create tmp file. This produces a spurious WARN and leaves the UNHEALTHY state un-persisted on disk; the state is lost on the next datanode restart.
The fix adds a single guard in KeyValueContainer.writeToContainerFile: if the metadata directory does not exist, recreate it with mkdirs() before attempting to create the temp file. This allows the .container file to be written and the UNHEALTHY state to survive a restart.
## What is the link to the Apache JIRA
HDDS-14577
## How was this patch tested?
Added new testcases
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "ArafatKhan2198 (via GitHub)" <gi...@apache.org>.
ArafatKhan2198 merged PR #10565:
URL: https://github.com/apache/ozone/pull/10565
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3479545506
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java:
##########
Review Comment:
make sense I will remove these code comments since its skipping the write.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "ArafatKhan2198 (via GitHub)" <gi...@apache.org>.
ArafatKhan2198 commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3465223514
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java:
##########
@@ -391,7 +391,18 @@ public void markContainerUnhealthy() throws StorageContainerException {
writeLock();
final State prevState = containerData.getState();
try {
- updateContainerState(UNHEALTHY);
+ if (!getContainerFile().getParentFile().exists()) {
Review Comment:
PR description contradicts the implementation. The "What changes were proposed" text says the fix calls mkdirs() to recreate the metadata directory and persist the .container file so the UNHEALTHY state survives a restart. The actual diff does the opposite: it skips the file write and explicitly does not recreate the directory or persist.
##########
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());
}
+ /**
Review Comment:
Can we test this out locally as well? by manually deleting the metadata folder?
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java:
##########
Review Comment:
> // Attempting to write the .container file would fail, and writing a partial file // with only the state field is more harmful than not writing one at all.
>
`ContainerDataYaml.createContainerFile()` serializes the **entire** in-memory `containerData` (all fields loaded at startup), not "only the state field." So the "partial file with only the state field" rationale doesn't hold.
##########
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:
`assertFalse(keyValueContainer.getContainerFile().exists())` (`:788`) is trivially true regardless of the fix - the file can't exist when its parent dir was just deleted, and the *old* buggy code also never created it (it threw). The assertion that carries the fix is "does not throw" (`:780`) plus the state check (`:783`). The file/dir assertions mainly serve as a regression guard against a future `mkdirs`/persist approach - fine to keep, but they don't prove the bug is fixed on their own.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "sreejasahithi (via GitHub)" <gi...@apache.org>.
sreejasahithi commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3449726519
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueContainer.java:
##########
@@ -759,6 +759,40 @@ public void testReportOfUnhealthyContainer(
assertNotNull(keyValueContainer.getContainerReport());
}
+ /**
+ * When a container's metadata directory is missing (MISSING_METADATA_DIR), marking the container
+ * UNHEALTHY must succeed and persist the state to disk. Previously the call failed with
+ * StorageContainerException because writeToContainerFile tried to create a temp file inside
+ * the missing directory.
+ */
+ @ContainerTestVersionInfo.ContainerTest
+ public void testMarkUnhealthyWithMissingMetadataDir(ContainerTestVersionInfo versionInfo) throws Exception {
+ init(versionInfo);
+ keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
+
+ // Simulate MISSING_METADATA_DIR: delete the entire metadata directory.
+ File metadataDir = new File(keyValueContainerData.getMetadataPath());
+ assertTrue(metadataDir.exists(), "Metadata dir should exist before corruption");
+ FileUtils.deleteDirectory(metadataDir);
Review Comment:
nit: you could use MISSING_METADATA_DIR.applyTo(keyValueContainer) instead because it is already used in scanner tests (TestKeyValueContainerCheck). Reusing it keeps corruption simulation consistent and avoids duplicating delete logic.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3541582913
##########
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());
}
+ /**
Review Comment:
Yes
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #10565:
URL: https://github.com/apache/ozone/pull/10565#issuecomment-4771090205
Hi @priyeshkaratha, the container scanner is not designed to repair containers it finds issues with, so I don't think we want to implement this. The `.container` file has other metadata, not just the container state which will be missing in this newly created file, and I think having partial `.container` files floating around the system is more problematic than the original issue.
Note that the metadata scanner runs more frequently than the data scanner, so both SCM (which gets the unhealthy ICR and sends the delete) and DN would need to be restarted every time the metadata scanner runs for this container to remain indefinitely.
If it doesn't make the code too messy we could clean up the logging by not attempting to update the file if the directory does not exist, but note that this is not a common case so we should not do anything too disruptive to the main code flow to accommodate this.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3456967867
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestKeyValueContainer.java:
##########
@@ -759,6 +759,40 @@ public void testReportOfUnhealthyContainer(
assertNotNull(keyValueContainer.getContainerReport());
}
+ /**
+ * When a container's metadata directory is missing (MISSING_METADATA_DIR), marking the container
+ * UNHEALTHY must succeed and persist the state to disk. Previously the call failed with
+ * StorageContainerException because writeToContainerFile tried to create a temp file inside
+ * the missing directory.
+ */
+ @ContainerTestVersionInfo.ContainerTest
+ public void testMarkUnhealthyWithMissingMetadataDir(ContainerTestVersionInfo versionInfo) throws Exception {
+ init(versionInfo);
+ keyValueContainer.create(volumeSet, volumeChoosingPolicy, scmId);
+
+ // Simulate MISSING_METADATA_DIR: delete the entire metadata directory.
+ File metadataDir = new File(keyValueContainerData.getMetadataPath());
+ assertTrue(metadataDir.exists(), "Metadata dir should exist before corruption");
+ FileUtils.deleteDirectory(metadataDir);
Review Comment:
Addressed.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on PR #10565:
URL: https://github.com/apache/ozone/pull/10565#issuecomment-4775520281
> If it doesn't make the code too messy we could clean up the logging by not attempting to update the file if the directory does not exist, but note that this is not a common case so we should not do anything too disruptive to the main code flow to accommodate this.
Thanks @errose28 for pointing out this. It makes sense. I am justing skipping the creation of temp file in this scenario and instead adding a debug log.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3465280463
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java:
##########
@@ -391,7 +391,18 @@ public void markContainerUnhealthy() throws StorageContainerException {
writeLock();
final State prevState = containerData.getState();
try {
- updateContainerState(UNHEALTHY);
+ if (!getContainerFile().getParentFile().exists()) {
Review Comment:
updated description.
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org
Re: [PR] HDDS-14577. Handle missing metadata dir when updating container state [ozone]
Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #10565:
URL: https://github.com/apache/ozone/pull/10565#discussion_r3541582913
##########
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());
}
+ /**
Review Comment:
Yes, Updated description with manual steps tried
--
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: issues-unsubscribe@ozone.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org