sodonnel commented on code in PR #10109:
URL: https://github.com/apache/ozone/pull/10109#discussion_r3146281529


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/statemachine/background/BlockDeletingTask.java:
##########
@@ -139,24 +140,38 @@ public BackgroundTaskResult call() throws Exception {
 
   private ContainerBackgroundTaskResult handleDeleteTask() throws Exception {
     ContainerBackgroundTaskResult crr;
-    final Container container = ozoneContainer.getContainerSet()
-        .getContainer(containerData.getContainerID());
+    ContainerSet cs = ozoneContainer.getContainerSet();
+    final Container container = 
cs.getContainer(containerData.getContainerID());
+    if (container == null) {
+      return new ContainerBackgroundTaskResult();
+    }
     container.writeLock();
-    File dataDir = new File(containerData.getChunksPath());
-    long startTime = Time.monotonicNow();
-    // Scan container's db and get list of under deletion blocks
-    try (DBHandle meta = BlockUtils.getDB(containerData, conf)) {
-      if (containerData.hasSchema(SCHEMA_V1)) {
-        crr = deleteViaSchema1(meta, container, dataDir, startTime);
-      } else if (containerData.hasSchema(SCHEMA_V2)) {
-        crr = deleteViaSchema2(meta, container, dataDir, startTime);
-      } else if (containerData.hasSchema(SCHEMA_V3)) {
-        crr = deleteViaSchema3(meta, container, dataDir, startTime);
-      } else {
-        throw new UnsupportedOperationException(
-            "Only schema version 1,2,3 are supported.");
+    try {
+      // Re-fetch AFTER lock to verify the container is not having stale 
references while waiting for lock.
+      Container<?> current = cs.getContainer(containerData.getContainerID());
+      if (current == null || current.getContainerData() != containerData) {
+        LOG.warn("Container {} reference is stale. Aborting delete. SCM will 
retry with" +
+            " the current replica.", containerData.getContainerID());
+        return new ContainerBackgroundTaskResult();

Review Comment:
   I don't think this should just fail the task. We can try again, perhaps 
wrapping the logic in a retry loop, because it's highly likely it will work the 
next time around.



-- 
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]

Reply via email to