diff --git a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java index 6184dbdad6ac..0c7d36d5eaac 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java @@ -45,6 +45,7 @@ import org.apache.paimon.utils.ProjectedRow; import org.apache.paimon.utils.SerializationUtils; import org.apache.paimon.utils.SnapshotManager; +import org.apache.paimon.utils.SnapshotNotExistException; import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators; @@ -195,7 +196,16 @@ private static List allManifests(FileStoreTable dataTable) { SnapshotManager snapshotManager = dataTable.snapshotManager(); Long snapshotId = coreOptions.scanSnapshotId(); Snapshot snapshot = null; - if (snapshotId != null && snapshotManager.snapshotExists(snapshotId)) { + if (snapshotId != null) { + // reminder user with snapshot id range + if (!snapshotManager.snapshotExists(snapshotId)) { + Long earliestSnapshotId = snapshotManager.earliestSnapshotId(); + Long latestSnapshotId = snapshotManager.latestSnapshotId(); + throw new SnapshotNotExistException( + String.format( + "Specified scan.snapshot-id %s is not exist, you can set it in range from %s to %s", + snapshotId, earliestSnapshotId, latestSnapshotId)); + } snapshot = snapshotManager.snapshot(snapshotId); } else if (snapshotId == null) { snapshot = snapshotManager.latestSnapshot(); diff --git a/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java b/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java index edca0831d168..32dd0d24888d 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java @@ -36,6 +36,7 @@ import org.apache.paimon.table.TableTestBase; import org.apache.paimon.types.DataTypes; import org.apache.paimon.utils.SnapshotManager; +import org.apache.paimon.utils.SnapshotNotExistException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,6 +47,7 @@ import static org.apache.paimon.utils.FileStorePathFactoryTest.createNonPartFactory; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertThrows; /** Unit tests for {@link ManifestsTable}. */ public class ManifestsTableTest extends TableTestBase { @@ -118,8 +120,10 @@ public void testReadManifestsFromNotExistSnapshot() throws Exception { (ManifestsTable) manifestsTable.copy( Collections.singletonMap(CoreOptions.SCAN_SNAPSHOT_ID.key(), "3")); - List result = read(manifestsTable); - assertThat(result).isEmpty(); + assertThrows( + "Specified scan.snapshot-id 3 is not exist, you can set it in range from 1 to 2", + SnapshotNotExistException.class, + () -> read(manifestsTable)); } private List getExpectedResult(long snapshotId) {