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 f1a54a890a [core] Optimize getNextSnapshot in NextSnapshotFetcher to
return fast
f1a54a890a is described below
commit f1a54a890af8d3ceba4340f23568ae31c98780f0
Author: JingsongLi <[email protected]>
AuthorDate: Tue Jul 22 12:00:38 2025 +0800
[core] Optimize getNextSnapshot in NextSnapshotFetcher to return fast
---
.../org/apache/paimon/utils/NextSnapshotFetcher.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
b/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
index 205846b1b5..7eb13bc485 100644
--- a/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
+++ b/paimon-core/src/main/java/org/apache/paimon/utils/NextSnapshotFetcher.java
@@ -26,6 +26,8 @@ import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
+import java.io.FileNotFoundException;
+
/** Fetcher for getting the next snapshot by snapshot id. */
public class NextSnapshotFetcher {
@@ -46,21 +48,27 @@ public class NextSnapshotFetcher {
@Nullable
public Snapshot getNextSnapshot(long nextSnapshotId) {
- if (snapshotManager.snapshotExists(nextSnapshotId)) {
- return snapshotManager.snapshot(nextSnapshotId);
+ Snapshot latest = snapshotManager.latestSnapshot();
+
+ if (latest != null && latest.id() == nextSnapshotId) {
+ return latest;
+ }
+
+ try {
+ return snapshotManager.tryGetSnapshot(nextSnapshotId);
+ } catch (FileNotFoundException ignored) {
}
Long earliestSnapshotId = snapshotManager.earliestSnapshotId();
- Long latestSnapshotId = snapshotManager.latestSnapshotId();
// No snapshot now
if (earliestSnapshotId == null || earliestSnapshotId <=
nextSnapshotId) {
if ((earliestSnapshotId == null && nextSnapshotId > 1)
- || (latestSnapshotId != null && nextSnapshotId >
latestSnapshotId + 1)) {
+ || (latest != null && nextSnapshotId > latest.id() + 1)) {
throw new OutOfRangeException(
String.format(
"The next expected snapshot is too big! Most
possible cause might be the table had been recreated."
+ "The next snapshot id is %d, while
the latest snapshot id is %s",
- nextSnapshotId, latestSnapshotId));
+ nextSnapshotId, latest.id()));
}
LOG.debug(