This is an automated email from the ASF dual-hosted git repository.

jojochuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 29758e4ac1d HDDS-16441. Orphaned snapshot diff task marks a 
resubmitted job DONE with another run's metadata (#11321)
29758e4ac1d is described below

commit 29758e4ac1d433f6aa7016bfddc67cb13f9bb081
Author: Siyao Meng <[email protected]>
AuthorDate: Thu Oct 1 12:35:46 2026 -0700

    HDDS-16441. Orphaned snapshot diff task marks a resubmitted job DONE with 
another run's metadata (#11321)
    
    Generated-by: Claude Code (Opus 5)
---
 .../hadoop/ozone/om/snapshot/SnapshotDiffManager.java  | 15 +++++++++++----
 .../ozone/om/snapshot/TestSnapshotDiffManager.java     | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java
index 1452999bb5c..d37fcab50c3 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java
@@ -1185,7 +1185,7 @@ void generateSnapshotDiffReport(final String jobKey,
                 LOG.debug("Generated snapshot diff report, entry count: {}, 
elapsed: {}ms, jobId: {}",
                     reportEntries.getKey(), Time.monotonicNow() - 
reportGenStart, jobId);
               }
-              updateJobStatusToDone(jobKey, reportEntries.getKey(), 
reportEntries.getValue());
+              updateJobStatusToDone(jobKey, jobId, reportEntries.getKey(), 
reportEntries.getValue());
             }
             return null;
           }
@@ -1744,10 +1744,17 @@ private synchronized void 
updateJobStatusToFailed(String jobKey,
     snapDiffJobTable.put(jobKey, snapshotDiffJob);
   }
 
-  private synchronized void updateJobStatusToDone(String jobKey,
-                                                  long totalDiffEntries,
-                                                  String largestJobKey) {
+  synchronized void updateJobStatusToDone(String jobKey,
+                                          String jobId,
+                                          long totalDiffEntries,
+                                          String largestJobKey) {
     SnapshotDiffJob snapshotDiffJob = snapDiffJobTable.get(jobKey);
+    // A cancelled job's task keeps running, and a resubmit reuses the jobKey 
with a new jobId.
+    if (!snapshotDiffJob.getJobId().equals(jobId)) {
+      LOG.warn("Not marking snapshot diff job {} as DONE: task jobId {} was 
superseded by jobId {}.",
+          jobKey, jobId, snapshotDiffJob.getJobId());
+      return;
+    }
     if (snapshotDiffJob.getStatus() != IN_PROGRESS) {
       throw new IllegalStateException("Invalid job status for jobID: " +
           snapshotDiffJob.getJobId() + ". Job's current status is '" +
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
index f391125fe06..2bc474d5be1 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
@@ -1564,6 +1564,24 @@ public void 
testSubmitSnapshotDiffResubmitsWhenPreviouslyCancelled()
     assertEquals(IN_PROGRESS, updated.getStatus());
   }
 
+  @Test
+  public void testUpdateJobStatusToDoneSkipsSupersededJob() throws IOException 
{
+    SnapDiffTestContext ctx = setupRandomSnapDiffTestContext();
+    String liveJobId = UUID.randomUUID().toString();
+    snapshotDiffManager.getSnapDiffJobTable().put(ctx.diffJobKey,
+        new SnapshotDiffJob(0L, liveJobId, IN_PROGRESS, ctx.volumeName, 
ctx.bucketName,
+            ctx.fromSnapshotName, ctx.toSnapshotName, false, false, 0L, null, 
0.0, null));
+
+    // A superseded task's publish is ignored, the live job's own publish goes 
through.
+    snapshotDiffManager.updateJobStatusToDone(ctx.diffJobKey, 
UUID.randomUUID().toString(), 5L, "staleKey");
+    assertEquals(IN_PROGRESS, 
snapshotDiffManager.getSnapDiffJobTable().get(ctx.diffJobKey).getStatus());
+
+    snapshotDiffManager.updateJobStatusToDone(ctx.diffJobKey, liveJobId, 5L, 
"liveKey");
+    SnapshotDiffJob done = 
snapshotDiffManager.getSnapDiffJobTable().get(ctx.diffJobKey);
+    assertEquals(DONE, done.getStatus());
+    assertEquals("liveKey", done.getLargestEntryKey());
+  }
+
   @Test
   public void testSubmitSnapshotDiffResubmitsWhenPreviouslyRejected()
       throws IOException {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to