yandrey321 commented on code in PR #12139:
URL: https://github.com/apache/ozone/pull/12139#discussion_r4688639921
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -2539,21 +2542,24 @@ private void deleteInternal(Container container,
boolean force)
HddsVolume hddsVolume = keyValueContainerData.getVolume();
// Steps to delete
- // 1. container marked deleted
- // 2. container is removed from container set
+ // 1. witnessed container DB entry set to DELETED, container is
removed from container set
+ // 2. container marked deleted
// 3. container db handler and content removed from db
// 4. container moved to tmp folder
// 5. container content deleted from tmp folder
+ long waitTime = clock.millis() - startTime;
+ if (waitTime > maxDeleteLockWaitMs) {
+ LOG.warn("An attempt to delete container {} took {} ms acquiring
locks and pre-checks. " +
+ "The delete has been skipped and should be retried
automatically by SCM.",
+ containerLocked.getContainerData().getContainerID(), waitTime);
+ return;
+ }
+ // Step 1 is first and outside the try below. If the entry cannot be
written, nothing has changed yet: the
+ // delete fails with the witnessed container DB error and the replica
stays as it was. If the datanode stops
+ // after step 1, the replica on disk is intact and is loaded again at
startup.
+ containerSet.removeContainer(containerId);
Review Comment:
+1 here: reorder leaves a half-deleted replica when
`markContainerForDelete` fails.
`removeContainer` (DELETED entry + removal from the map and volume) now runs
before `markContainerForDelete` and outside the try. If
`markContainerForDelete` throws (writing the .container file on a failing
disk), the catch at 2563+ triggers a volume scan and throws. The replica is
then out of containerSet but CLOSED with its data on disk: no ICR, no
`decrementUsedSpace`, not missing, and writes are refused. On restart it loads
again, the DELETED entry is overwritten, and SCM sees it come back. This also
inverts the "on-disk delete mark wins" precedence that sumitagrawl raised.
It would be better to keep master's order (mark on disk, then
`removeContainer`; the entry is still written before the map removal, so the
race fix holds). Close the crash window in `ContainerReader.cleanupContainer`
(DELETED-on-disk path) by writing the DELETED entry. Without that, a crash
between the two steps leaves a non-DELETED entry. OzoneContainer then marks the
container missing on every restart, and a late Ratis write gets
`CONTAINER_MISSING`, which applyTransaction does not tolerate, so the pipeline
closes. Catch a witnessed-DB failure separately so it is not logged as "Failed
to move container" and does not trigger a volume scan (errose28's point).
--
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]