Skip to content

[lake/paimon] Explictly snapshotId setting to improve scan-based lookup performance - #4480

Open
zuston wants to merge 2 commits into
apache:mainfrom
zuston:snapshotIdScan
Open

zuston wants to merge 2 commits into
apache:mainfrom
zuston:snapshotIdScan

Conversation

@zuston

@zuston zuston commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Purpose

this is the followup PR for #4124 .

Each scan-based lookup plans a new Paimon scan. When no snapshot ID is provided, Paimon resolves the latest snapshot first, adding metadata I/O. Passing the snapshot ID already known to Fluss avoids that discovery step. Manifest reads may still add latency on cache misses.

Brief change log

Tests

API and Format

Documentation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Adds explicit lake snapshot pinning for Paimon scan-based historical lookups, improving consistency and avoiding unnecessary latest-snapshot scans.

Changes:

  • Propagates required snapshot IDs from the historical lookup manager.
  • Adds snapshot-aware Paimon scan contexts and tests.
  • Updates lookup context and table configuration APIs.
File Description
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​replica/​historical/​HistoricalLakeLookupManager.java Updated as part of this pull request.
fluss-lake/​fluss-lake-paimon/​src/​test/​java/​org/​apache/​fluss/​lake/​paimon/​lookup/​PaimonLakeTableLookuperTest.java Updated as part of this pull request.
fluss-lake/​fluss-lake-paimon/​src/​main/​java/​org/​apache/​fluss/​lake/​paimon/​lookup/​PaimonScanBasedTableLookuper.java Updated as part of this pull request.
fluss-common/​src/​main/​java/​org/​apache/​fluss/​lake/​lakestorage/​LakeTableLookuper.java Updated as part of this pull request.
fluss-common/​src/​main/​java/​org/​apache/​fluss/​config/​TableConfig.java Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

schemaInfo.getSchema().getRowType(),
lookupMetricRecorder);
lookupMetricRecorder,
requiredLakeSnapshotIds.get(tableInfo.getTableId()));

@zuston zuston Sep 24, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the modification origins from the fluss, so this won't happen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a stale-snapshot case here even when the context and acquireLookuper() observe the same snapshot ID:

  1. The historical bucket records requiredLakeSnapshotIds[tableId] = S1, and its leader remains unchanged.
  2. A regular partition P writes a new key and tiers it to snapshot S2. If the historical bucket has no progress in that commit, its lookup manager can still retain S1.
  3. P expires, and the first historical lookup for that key misses the local historical state.
  4. Both context creation and acquireLookuper() see S1. SCAN explicitly reads S1 and misses the key committed in S2.

This can happen even while S1 is still retained, without concurrent writes. Making snapshot capture and acquire atomic would still select S1.

SST avoids this particular case because its file cache is keyed by the original partition and bucket. On the first lookup of P, getOrInitializeFiles() scans the latest snapshot to initialize that entry.

Could we address this case so that SCAN does not remain pinned to a snapshot that predates the queried partition’s tiered data?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, this is uncovered (described into the following first case) in the current PR. I think we should distinguish two cases:

Data written before the regular partition expires.

The data is written through the regular bucket and committed in S2. The historical bucket may have no progress in that commit, so its lookup manager can remain on S1. When the regular partition expires, its existing rows are not copied into the historical bucket’s local KV. The first historical lookup therefore falls back to S1 and can miss the data. This is the gap you pointed out, and making snapshot capture and acquire atomic would not fix it.

For this case, I’ll make partition expiration trigger a refresh of the historical lookup manager’s cached snapshot to the latest version. This relies on the guarantee established by #3820 that the partition’s data has been fully tiered to the lake before expiration. I’ll include this fix in the current PR.

Updates or deletes written after the partition has expired.

Updates and deletes to expired partitions go through the historical bucket. Local values and deletion markers take priority over lake data. After tiering, the snapshot is updated before local state can be cleaned up. so for this case, there is no correctness risk for the cached expired snapshotId (that may be delayed updated with a potential async updating interval)

Comment on lines +166 to +168
Long lakeSnapshotId = context.lakeSnapshotId();
if (lakeSnapshotId != null) {
// Paimon propagates the table's snapshot and manifest caches to this copy.
private final @Nullable Long lakeSnapshotId;

/** Creates a lookup context when the lake snapshot is unknown. */
@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this test-only overload? The tests can call the six-argument constructor directly and pass null when the lake snapshot is unknown.

@luoyuxia luoyuxia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zuston Thanks for the pr. I left some comment. PTAL

@zuston

zuston commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

@zuston Thanks for the pr. I left some comment. PTAL

thanks for your quick review. and for the potential correctess risk, I have replied in the thread of #4480 (comment). please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants