Skip to content

[core] Load snapshots by ID from the catalog - #11563

Draft
sundapeng wants to merge 2 commits into
apache:masterfrom
sundapeng:snapshot-by-id-catalog-loader
Draft

sundapeng wants to merge 2 commits into
apache:masterfrom
sundapeng:snapshot-by-id-catalog-loader

Conversation

@sundapeng

@sundapeng sundapeng commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Purpose

A catalog can publish a snapshot before its file becomes visible. A reader can obtain the latest ID from the catalog and then fail to read that same snapshot by ID. This follows up on the file retry added in #11276.

On a cache miss, snapshot(id) and tryGetSnapshot(id) now ask a version-managing catalog for that ID. Both fall back to the file when the catalog cannot supply a matching snapshot and check the catalog once more if the file is missing. Each keeps its existing file retry and exception behavior. REST permission errors propagate to the caller.

Writer recovery, expiration, and snapshot listings read snapshot contents from disk. This matters when the shared cache holds a catalog snapshot under the same ID as a different file.

Tests

  • 422 tests passed on JDK 8 across 10 core test classes, including snapshot lookup, writer recovery, expiration, time travel, and the REST catalog.
  • Regression tests cover a missing file, publication between lookups, and a cached catalog snapshot whose file differs or has been deleted. A mock HTTP server verifies the branch path and the handling of HTTP 501 and 403.
  • Checkstyle, Spotless, and the documentation build passed.

SnapshotManager reads a snapshot by id only from the snapshot-N file, even
when the table comes from a catalog that manages snapshot versions and the
same SnapshotManager already loads the latest snapshot through the catalog.
The file is a best-effort mirror: a rollback deletes snapshot files under
ids that later commits can reuse, and a commit's mirror write can still be
in flight, so a by-id read can fail with FileNotFoundException while the
catalog still holds the snapshot. Readers that resolve the latest id from
the catalog and then re-read that id from the file system degrade an
authoritative answer into a mirror read.

Add SnapshotLoader.load(version), implemented through the existing REST
loadSnapshot(identifier, version) contract, and consult it in
snapshot(long) and tryGetSnapshot(long): catalog first, file system as
fallback, and the catalog again after a file system miss before failing.
A catalog answer with a mismatched snapshot id is rejected. Writes keep
file system truth: latestSnapshotFromFileSystem, earliestSnapshot and
snapshotsWithId still read only the file system.
Use the numeric snapshot ID in the loader and share lookup, validation,
and cache handling between the two by-ID read methods. Recheck the
catalog when the file is missing and preserve each method's retry and
exception behavior. A REST server can decline the version endpoint with
HTTP 501, while permission errors must reach the caller.

Writer recovery, expiration, and snapshot listings need the file on disk.
Bypass the shared cache for those reads on catalog-managed tables, since
it can contain a different snapshot at the same path. Keep the loader's
serialization UID compatible with the existing implementation.
@sundapeng sundapeng changed the title [core] Resolve snapshots by id through the catalog loader when available [core] Load snapshots by ID from the catalog Nov 30, 2026
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.

1 participant