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

SaketaChalamchala 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 c15b66ea605 HDDS-17742. Gate optimized full snapshot diff on the from 
snapshot's creation transaction. (#12037)
c15b66ea605 is described below

commit c15b66ea605debc693f4bcaee9b64518e3e532de
Author: SaketaChalamchala <[email protected]>
AuthorDate: Fri Nov 13 14:56:32 2026 -0800

    HDDS-17742. Gate optimized full snapshot diff on the from snapshot's 
creation transaction. (#12037)
    
    Co-authored-by: Doroszlai, Attila <[email protected]>
---
 .../hadoop/ozone/om/snapshot/OmSnapshotTests.java  |  6 +-
 .../om/snapshot/TestOptimizedSnapshotDiff.java     | 95 ++++++++++++++++++++--
 .../ozone/om/snapshot/SnapshotDiffManager.java     | 17 +++-
 .../om/snapshot/diff/FullDiffSequentialReader.java |  9 +-
 4 files changed, 108 insertions(+), 19 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotTests.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotTests.java
index 04c0f934471..4efa5674c62 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotTests.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotTests.java
@@ -3988,10 +3988,10 @@ public void testSnapshotDiffMPUMixedCreateAndModify() 
throws Exception {
     assertEquals(expectedDiffs, diff.getDiffList());
   }
 
-  protected SnapshotDiffResponse waitForDoneReportAfterOrderedSubmit(String 
volume, String bucket,
-      String fromSnap, String toSnap, boolean orderedReport)
+  protected SnapshotDiffResponse waitForDoneReportAfterSubmit(String volume, 
String bucket,
+      String fromSnap, String toSnap, boolean forceFullDiff, boolean 
orderedReport)
       throws IOException, InterruptedException, TimeoutException {
-    store.submitSnapshotDiff(volume, bucket, fromSnap, toSnap, false, false, 
orderedReport);
+    store.submitSnapshotDiff(volume, bucket, fromSnap, toSnap, forceFullDiff, 
false, orderedReport);
     AtomicReference<SnapshotDiffResponse> responseRef = new 
AtomicReference<>();
     GenericTestUtils.waitFor(() -> {
       try {
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOptimizedSnapshotDiff.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOptimizedSnapshotDiff.java
index f8402487840..40cf0cfe43a 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOptimizedSnapshotDiff.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOptimizedSnapshotDiff.java
@@ -32,6 +32,7 @@
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
 import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
 import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry;
 import org.apache.hadoop.ozone.DataTestUtil;
@@ -39,6 +40,8 @@
 import org.apache.hadoop.ozone.client.OzoneBucket;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.ozone.om.service.SnapshotDeletingService;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse;
 import org.apache.ozone.test.GenericTestUtils;
@@ -85,13 +88,13 @@ public void testOptimizedDiffUnorderedThenOrdered() throws 
Exception {
             SnapshotDiffReport.DiffType.RENAME, "dir1/dir2/key1", 
"dir1/dir3/renamed_key"),
         
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.DELETE, 
"dir1/dir2"));
 
-    SnapshotDiffResponse unordered = waitForDoneReportAfterOrderedSubmit(
-        getVolumeName(), getBucketName(), snap1, snap2, false);
+    SnapshotDiffResponse unordered = waitForDoneReportAfterSubmit(
+        getVolumeName(), getBucketName(), snap1, snap2, false, false);
     assertEquals("Report is dependency unordered.", unordered.getReason());
     assertEquals(expectedUnordered, 
unordered.getSnapshotDiffReport().getDiffList());
 
-    SnapshotDiffResponse ordered = waitForDoneReportAfterOrderedSubmit(
-        getVolumeName(), getBucketName(), snap1, snap2, true);
+    SnapshotDiffResponse ordered = waitForDoneReportAfterSubmit(
+        getVolumeName(), getBucketName(), snap1, snap2, false, true);
     assertEquals("Report is dependency ordered.", ordered.getReason());
     assertEquals(expectedOrdered, 
ordered.getSnapshotDiffReport().getDiffList());
   }
@@ -112,8 +115,8 @@ public void testOptimizedDiffWithUnchangedDirectoryTable() 
throws Exception {
     }
 
     for (boolean ordered : new boolean[] {false, true}) {
-      SnapshotDiffResponse response = waitForDoneReportAfterOrderedSubmit(
-          getVolumeName(), getBucketName(), snap1, snap2, ordered);
+      SnapshotDiffResponse response = waitForDoneReportAfterSubmit(
+          getVolumeName(), getBucketName(), snap1, snap2, false, ordered);
       
assertThat(response.getSnapshotDiffReport().getDiffList()).containsExactlyInAnyOrder(
           
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.DELETE, 
"unchanged-dirs/dir/old"),
           
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.CREATE, 
"unchanged-dirs/dir/new"));
@@ -147,8 +150,8 @@ public void testOptimizedObsDiff() throws Exception {
       obsBucket.deleteKey(key1);
       createSnapshot(volume, bucket, snap2);
 
-      SnapshotDiffResponse response = waitForDoneReportAfterOrderedSubmit(
-          volume, bucket, snap1, snap2, false);
+      SnapshotDiffResponse response = waitForDoneReportAfterSubmit(
+          volume, bucket, snap1, snap2, false, false);
       assertEquals("Report is dependency ordered.", response.getReason());
       
assertThat(response.getSnapshotDiffReport().getDiffList()).containsExactlyInAnyOrder(
           
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.DELETE, 
key1),
@@ -156,6 +159,82 @@ public void testOptimizedObsDiff() throws Exception {
     }
   }
 
+  @Test
+  public void testForcedFullDiffAfterSnapshotPurge() throws Exception {
+    String snap0 = "snap-purge-0";
+    String snap1 = "snap-purge-1";
+    String snap2 = "snap-purge-2";
+    String rootPath = String.format("%s://%s.%s/",
+        OzoneConsts.OZONE_URI_SCHEME, getBucketName(), getVolumeName());
+    try (FileSystem fs = FileSystem.get(new URI(rootPath), 
getCluster().getConf())) {
+      createFileKey(fs, "/purge/k1");
+      createSnapshot(getVolumeName(), getBucketName(), snap0);
+      createSnapshot(getVolumeName(), getBucketName(), snap1);
+      assertThat(fs.rename(new Path("/purge/k1"), new 
Path("/purge/k1r"))).isTrue();
+      createFileKey(fs, "/purge/k2");
+      createSnapshot(getVolumeName(), getBucketName(), snap2);
+    }
+
+    // Purging snap0 moves lastTransactionInfo of the next snapshot (snap1) 
past the changes above.
+    try (OzoneClient client = getCluster().newClient()) {
+      client.getObjectStore().deleteSnapshot(getVolumeName(), getBucketName(), 
snap0);
+    }
+    SnapshotDeletingService snapshotDeletingService =
+        new SnapshotDeletingService(1000, 60000, 
getCluster().getOzoneManager());
+    try {
+      GenericTestUtils.waitFor(() -> {
+        try {
+          snapshotDeletingService.runPeriodicalTaskNow();
+          return getSnapshotInfo(snap0) == null;
+        } catch (Exception e) {
+          throw new RuntimeException(e);
+        }
+      }, 500, 60000);
+    } finally {
+      snapshotDeletingService.shutdown();
+    }
+    SnapshotInfo fromSnapshot = getSnapshotInfo(snap1);
+    
assertThat(TransactionInfo.fromByteString(fromSnapshot.getLastTransactionInfo()).getTransactionIndex())
+        
.isGreaterThan(TransactionInfo.fromByteString(fromSnapshot.getCreateTransactionInfo()).getTransactionIndex());
+
+    for (boolean ordered : new boolean[] {false, true}) {
+      SnapshotDiffResponse response = waitForDoneReportAfterSubmit(
+          getVolumeName(), getBucketName(), snap1, snap2, true, ordered);
+      
assertThat(response.getSnapshotDiffReport().getDiffList()).containsExactlyInAnyOrder(
+          
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.RENAME, 
"purge/k1", "purge/k1r"),
+          
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.CREATE, 
"purge/k2"));
+    }
+  }
+
+  @Test
+  public void testForcedFullDiffFromNewerToOlderSnapshot() throws Exception {
+    String snap1 = "snap-reverse-1";
+    String snap2 = "snap-reverse-2";
+    String rootPath = String.format("%s://%s.%s/",
+        OzoneConsts.OZONE_URI_SCHEME, getBucketName(), getVolumeName());
+    try (FileSystem fs = FileSystem.get(new URI(rootPath), 
getCluster().getConf())) {
+      createFileKey(fs, "/reverse/k1");
+      createSnapshot(getVolumeName(), getBucketName(), snap1);
+      assertThat(fs.rename(new Path("/reverse/k1"), new 
Path("/reverse/k1r"))).isTrue();
+      createFileKey(fs, "/reverse/k2");
+      createSnapshot(getVolumeName(), getBucketName(), snap2);
+    }
+
+    // Every row of the older (to) snapshot was written before the newer 
(from) snapshot was created.
+    for (boolean ordered : new boolean[] {false, true}) {
+      SnapshotDiffResponse response = waitForDoneReportAfterSubmit(
+          getVolumeName(), getBucketName(), snap2, snap1, true, ordered);
+      
assertThat(response.getSnapshotDiffReport().getDiffList()).containsExactlyInAnyOrder(
+          
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.RENAME, 
"reverse/k1r", "reverse/k1"),
+          
SnapshotDiffReportOzone.getDiffReportEntry(SnapshotDiffReport.DiffType.DELETE, 
"reverse/k2"));
+    }
+  }
+
+  private SnapshotInfo getSnapshotInfo(String snapshotName) throws IOException 
{
+    return 
getCluster().getOzoneManager().getMetadataManager().getSnapshotInfoTable()
+        .get(SnapshotInfo.getTableKey(getVolumeName(), getBucketName(), 
snapshotName));
+  }
+
   private static void createObsKey(OzoneBucket bucket, String key) throws 
Exception {
     byte[] value = RandomStringUtils.secure().nextAscii(10240).getBytes(UTF_8);
     OzoneOutputStream fileKey = bucket.createKey(key, value.length);
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 f2a700a7e36..fbcdf0139f3 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
@@ -1420,7 +1420,8 @@ private void scanTablesForDiff(CompositeDeltaDiffComputer 
deltaDiffComputer, boo
     long estimatedFromTableKeys = Math.max(1L, 
fromTable.getEstimatedKeyCount());
 
     if (fullDiff) {
-      FullDiffSequentialReader reader = new FullDiffSequentialReader(store, 
resolveFullDiffUpdateIdGate(fsInfo));
+      FullDiffSequentialReader reader =
+          new FullDiffSequentialReader(store, 
resolveFullDiffUpdateIdGate(fsInfo, tsInfo));
       if (fromTable.getName().equals(DIRECTORY_TABLE)) {
         reader.scanDirectoryTables(fromTable, toTable, tablePrefix, 
stageProgress,
             estimatedToTableKeys, estimatedFromTableKeys);
@@ -1440,11 +1441,19 @@ private void 
scanTablesForDiff(CompositeDeltaDiffComputer deltaDiffComputer, boo
     }
   }
 
-  private Long resolveFullDiffUpdateIdGate(SnapshotInfo fromSnapshot) throws 
IOException {
-    if (fromSnapshot.getLastTransactionInfo() == null || 
fromSnapshot.getLastTransactionInfo().isEmpty()) {
+  private Long resolveFullDiffUpdateIdGate(SnapshotInfo fromSnapshot, 
SnapshotInfo toSnapshot) throws IOException {
+    // Not lastTransactionInfo: purges and moves into the snapshot advance it 
past later changes.
+    Long fromIndex = getCreateTransactionIndex(fromSnapshot);
+    Long toIndex = getCreateTransactionIndex(toSnapshot);
+    // A from snapshot newer than the to snapshot (reverse diff) has every to 
row at or below its index.
+    return fromIndex != null && toIndex != null && fromIndex < toIndex ? 
fromIndex : null;
+  }
+
+  private static Long getCreateTransactionIndex(SnapshotInfo snapshot) throws 
IOException {
+    if (snapshot.getCreateTransactionInfo() == null || 
snapshot.getCreateTransactionInfo().isEmpty()) {
       return null;
     }
-    return 
TransactionInfo.fromByteString(fromSnapshot.getLastTransactionInfo()).getTransactionIndex();
+    return 
TransactionInfo.fromByteString(snapshot.getCreateTransactionInfo()).getTransactionIndex();
   }
 
   private long resolveFromSnapshotDbTxSequenceNumber(SnapshotInfo 
fromSnapshot) throws IOException {
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/FullDiffSequentialReader.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/FullDiffSequentialReader.java
index d4f11fc2f03..7cc3bdbab8c 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/FullDiffSequentialReader.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/diff/FullDiffSequentialReader.java
@@ -47,13 +47,14 @@
  * signature.
  *
  * <p>When an update-id gate is supplied (HA OM), to-side gating normally 
admits
- * rows with {@code updateID > fromSnapshotDbTxSequenceNumber}. HA OM write 
paths
+ * rows with {@code updateID} above the from snapshot's creation transaction 
index. HA OM write paths
  * are expected to bump {@code updateID} on every meaningful metadata change.
  * Rows with a missing {@code updateID}, {@code updateID == 0}, or
  * {@code updateID == DEFAULT_OM_UPDATE_ID} ({@code -1}) are always treated as
  * candidates as a conservative fallback for legacy or ambiguous rows.
  *
- * <p>When no gate is supplied (non-HA), every to-side row is a candidate and a
+ * <p>When no gate is supplied (non-HA or reverse diff or missing creation 
transaction index),
+ * every to-side row is a candidate and a
  * compare signature is computed for each.
  */
 public class FullDiffSequentialReader {
@@ -73,8 +74,8 @@ public FullDiffSequentialReader(SnapDiffJobStore store) {
 
   /**
    * @param store        per-job temp column families for this full diff job
-   * @param updateIdGate when non-null, enables HA gating using this 
from-snapshot
-   *                     transaction index; when null, gating is disabled 
(non-HA)
+   * @param updateIdGate when non-null, enables HA gating using the from 
snapshot's creation
+   *                     transaction index; when null, gating is disabled
    */
   public FullDiffSequentialReader(SnapDiffJobStore store, Long updateIdGate) {
     this.store = store;


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

Reply via email to