From 6b9bc0bfe5364ad5b1cbd711239affba05158059 Mon Sep 17 00:00:00 2001 From: "linchen.23" Date: Tue, 7 Apr 2026 21:09:13 +0800 Subject: [PATCH] [core] Optimize the printing of error logs for snapshot expiration --- .../paimon/utils/NextSnapshotFetcher.java | 44 +++++++++++++++++-- .../paimon/table/SimpleTableTestBase.java | 5 ++- .../paimon/utils/NextSnapshotFetcherTest.java | 3 +- 3 files changed, 47 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 9c82b42e930e..23664216b7e6 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 @@ -87,12 +87,50 @@ private void rangeCheck(long nextSnapshotId) { nextSnapshotId); } else { if (!changelogDecoupled) { + long earliestTime = -1; + long latestTime = -1; + + if (earliestSnapshotId != null) { + try { + if (snapshotManager.snapshotExists(earliestSnapshotId)) { + earliestTime = + snapshotManager.snapshot(earliestSnapshotId).timeMillis(); + } + } catch (Exception e) { + LOG.warn( + "Failed to get snapshot time for ID earliest: {}", + earliestSnapshotId, + e); + } + } + + if (latestSnapshotId != null) { + try { + if (snapshotManager.snapshotExists(latestSnapshotId)) { + latestTime = snapshotManager.snapshot(latestSnapshotId).timeMillis(); + } + } catch (Exception e) { + LOG.warn( + "Failed to get snapshot time for ID latest: {}", + latestSnapshotId, + e); + } + } + throw new OutOfRangeException( String.format( - "The snapshot with id %d has expired. You can: " - + "1. increase the snapshot or changelog expiration time. " + "The wanted read snapshot with id %d has expired.\n" + + "Current status:\n" + + " Earliest Snapshot ID: %s, Time: %d\n" + + " Latest Snapshot ID: %s, Time: %d\n" + + "You can: \n" + + "1. increase the snapshot or changelog expiration time. \n" + "2. use consumer-id to ensure that unconsumed snapshots will not be expired.", - nextSnapshotId)); + nextSnapshotId, + earliestSnapshotId, + earliestTime, + latestSnapshotId == null ? "N/A" : latestSnapshotId, + latestTime)); } } } diff --git a/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java b/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java index c4ff1ca51a52..7681443b143e 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java @@ -736,7 +736,10 @@ public void testConsumeId() throws Exception { }) .satisfies( anyCauseMatches( - OutOfRangeException.class, "The snapshot with id 5 has expired.")); + OutOfRangeException.class, + "The wanted read snapshot with id 5 has expired.")) + .hasMessageContaining("Earliest Snapshot ID:") + .hasMessageContaining("Latest Snapshot ID:"); write.close(); commit.close(); diff --git a/paimon-core/src/test/java/org/apache/paimon/utils/NextSnapshotFetcherTest.java b/paimon-core/src/test/java/org/apache/paimon/utils/NextSnapshotFetcherTest.java index 98f202d5feed..42c4fb998282 100644 --- a/paimon-core/src/test/java/org/apache/paimon/utils/NextSnapshotFetcherTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/utils/NextSnapshotFetcherTest.java @@ -127,7 +127,8 @@ public void testRangeCheckThrowsExceptionForExpiredSnapshot() { assertThatThrownBy(() -> fetcher.getNextSnapshot(nextSnapshotId)) .isInstanceOf(OutOfRangeException.class) .hasMessageContaining( - "The snapshot with id 2 has expired. You can: 1. increase the snapshot or changelog expiration time. " + "You can: \n" + + "1. increase the snapshot or changelog expiration time. \n" + "2. use consumer-id to ensure that unconsumed snapshots will not be expired."); }