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

JingsongLi 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 9fa4ac6994 [python] Move EARLIEST back when rollback_to restores an 
expired tag snapshot (#10934)
9fa4ac6994 is described below

commit 9fa4ac699495706c62e1ff3c06d9a4b72530c9fc
Author: ZIHAN DAI <[email protected]>
AuthorDate: Tue Nov 3 01:41:58 2026 +1100

    [python] Move EARLIEST back when rollback_to restores an expired tag 
snapshot (#10934)
---
 paimon-python/pypaimon/table/rollback_helper.py    |  7 ++++
 .../pypaimon/tests/table/simple_table_test.py      | 45 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/paimon-python/pypaimon/table/rollback_helper.py 
b/paimon-python/pypaimon/table/rollback_helper.py
index 56f57eaf49..889bc991e5 100644
--- a/paimon-python/pypaimon/table/rollback_helper.py
+++ b/paimon-python/pypaimon/table/rollback_helper.py
@@ -91,3 +91,10 @@ class RollbackHelper:
         if not self._file_io.exists(snapshot_path):
             self._file_io.write_file(
                 snapshot_path, JSON.to_json(tagged_snapshot), overwrite=False)
+            # The snapshot file is missing because it was expired, so EARLIEST
+            # still points past it. Move the hint back to the restored 
snapshot,
+            # as the Java RollbackHelper does: otherwise, once new commits 
reach
+            # the old EARLIEST id, readers treat that id as the earliest 
snapshot
+            # and skip the restored snapshot and the commits after it.
+            earliest_file = 
"{}/EARLIEST".format(self._snapshot_manager.snapshot_dir)
+            self._file_io.overwrite_file_utf8(earliest_file, 
str(tagged_snapshot.id))
diff --git a/paimon-python/pypaimon/tests/table/simple_table_test.py 
b/paimon-python/pypaimon/tests/table/simple_table_test.py
index 4a4fd3efd8..73ed008939 100644
--- a/paimon-python/pypaimon/tests/table/simple_table_test.py
+++ b/paimon-python/pypaimon/tests/table/simple_table_test.py
@@ -627,6 +627,51 @@ class SimpleTableTest(unittest.TestCase):
         # Tag v3 should still exist
         self.assertTrue(tag_mgr.tag_exists("v3"))
 
+    def test_table_rollback_to_tag_after_snapshot_expired(self):
+        """Rolling back to a tag whose snapshot expired must move EARLIEST 
back to it."""
+        schema = Schema.from_pyarrow_schema(self.pa_schema)
+        self.catalog.create_table('default.test_rollback_expired_tag', schema, 
False)
+        table = self.catalog.get_table('default.test_rollback_expired_tag')
+
+        def write(k):
+            write_builder = table.new_batch_write_builder()
+            table_write = write_builder.new_write()
+            table_commit = write_builder.new_commit()
+            table_write.write_arrow(pa.Table.from_pydict(
+                {'pt': [1], 'k': [k], 'v': [k * 100]}, schema=self.pa_schema))
+            table_commit.commit(table_write.prepare_commit())
+            table_write.close()
+            table_commit.close()
+
+        def read_k(options):
+            read_builder = table.copy(options).new_read_builder()
+            splits = read_builder.new_scan().plan().splits()
+            return 
sorted(read_builder.new_read().to_arrow(splits)['k'].to_pylist())
+
+        for k in range(1, 6):
+            write(k)
+        table.create_tag("v2", 2)
+
+        # Expire snapshots 1-4 the way snapshot expiration leaves the snapshot
+        # directory: their files are gone and EARLIEST points at snapshot 5.
+        # The tag keeps the metadata and data files of snapshot 2.
+        snapshot_mgr = table.snapshot_manager()
+        for snapshot_id in range(1, 5):
+            table.file_io.delete(snapshot_mgr.get_snapshot_path(snapshot_id))
+        earliest_file = "{}/EARLIEST".format(snapshot_mgr.snapshot_dir)
+        table.file_io.overwrite_file_utf8(earliest_file, "5")
+
+        table.rollback_to("v2")
+        for k in range(6, 9):
+            write(k)
+
+        s2, s3, s5 = (snapshot_mgr.get_snapshot_by_id(i).time_millis for i in 
(2, 3, 5))
+        self.assertEqual(
+            read_k({'incremental-between-timestamp': '{},{}'.format(s2, s5)}), 
[6, 7, 8])
+        self.assertEqual(read_k({'scan.timestamp-millis': str(s3)}), [1, 2, 6])
+        self.assertEqual(table.file_io.read_file_utf8(earliest_file).strip(), 
"2")
+        self.assertEqual(snapshot_mgr.try_get_earliest_snapshot().id, 2)
+
     def test_table_rollback_to_nonexistent_snapshot(self):
         """Test that rollback to a non-existent snapshot raises ValueError."""
         schema = Schema.from_pyarrow_schema(

Reply via email to