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

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


The following commit(s) were added to refs/heads/master by this push:
     new d6a10faa4 [core] Skip non-existent snapshots in rollback (#3733)
d6a10faa4 is described below

commit d6a10faa4c6e87cb926518059cabd91cccf27dc7
Author: Fang Yong <[email protected]>
AuthorDate: Mon Jul 15 10:05:57 2024 +0800

    [core] Skip non-existent snapshots in rollback (#3733)
---
 .../org/apache/paimon/table/RollbackHelper.java    |  7 ++++--
 .../paimon/table/FileStoreTableTestBase.java       | 25 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java 
b/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java
index bd608cdca..499631836 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/RollbackHelper.java
@@ -119,8 +119,11 @@ public class RollbackHelper {
         List<Snapshot> toBeCleaned = new ArrayList<>();
         long to = Math.max(earliest, retainedSnapshot.id() + 1);
         for (long i = latest; i >= to; i--) {
-            toBeCleaned.add(snapshotManager.snapshot(i));
-            fileIO.deleteQuietly(snapshotManager.snapshotPath(i));
+            // Ignore the non-existent snapshots
+            if (snapshotManager.snapshotExists(i)) {
+                toBeCleaned.add(snapshotManager.snapshot(i));
+                fileIO.deleteQuietly(snapshotManager.snapshotPath(i));
+            }
         }
 
         // delete data files of snapshots
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/FileStoreTableTestBase.java 
b/paimon-core/src/test/java/org/apache/paimon/table/FileStoreTableTestBase.java
index 53559b843..fce09392c 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/table/FileStoreTableTestBase.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/table/FileStoreTableTestBase.java
@@ -114,6 +114,7 @@ import static 
org.apache.paimon.CoreOptions.SNAPSHOT_NUM_RETAINED_MAX;
 import static org.apache.paimon.CoreOptions.SNAPSHOT_NUM_RETAINED_MIN;
 import static org.apache.paimon.CoreOptions.WRITE_ONLY;
 import static 
org.apache.paimon.testutils.assertj.PaimonAssertions.anyCauseMatches;
+import static org.apache.paimon.utils.Preconditions.checkNotNull;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -761,6 +762,30 @@ public abstract class FileStoreTableTestBase {
         commit.close();
     }
 
+    @Test
+    public void testRollbackToSnapshotSkipNonExistentSnapshot() throws 
Exception {
+        int commitTimes = ThreadLocalRandom.current().nextInt(100) + 5;
+        FileStoreTable table = prepareRollbackTable(commitTimes);
+
+        SnapshotManager snapshotManager = table.snapshotManager();
+        table.snapshotManager()
+                
.commitLatestHint(checkNotNull(snapshotManager.latestSnapshotId()) + 100);
+        table.rollbackTo(1L);
+        ReadBuilder readBuilder = table.newReadBuilder();
+        List<String> result =
+                getResult(
+                        readBuilder.newRead(),
+                        readBuilder.newScan().plan().splits(),
+                        BATCH_ROW_TO_STRING);
+        assertThat(result)
+                
.containsExactlyInAnyOrder("0|0|0|binary|varbinary|mapKey:mapVal|multiset");
+
+        List<java.nio.file.Path> files =
+                Files.walk(new File(tablePath.toUri().getPath()).toPath())
+                        .collect(Collectors.toList());
+        assertThat(files.size()).isEqualTo(14);
+    }
+
     // All tags are after the rollback snapshot
     @Test
     public void testRollbackToSnapshotCase0() throws Exception {

Reply via email to