Repository navigation
[core] Use tag files for loaded tables - #1585
Conversation
leaves12138
left a comment
There was a problem hiding this comment.
Reviewed base main at head 035fe31 (+1216/-1691, 17 files).
File list: datafusion procedures.rs, tests/rest_management_procedures.rs; rest-server README.md, tests/e2e.rs; core catalog/caching_catalog.rs, catalog/mod.rs, table/mod.rs, table/referenced_files.rs, table/rest_env.rs, table/tag_manager.rs, table/tag_manager/cache.rs (new), table/time_travel.rs; tests mock_server.rs, rest_catalog/caching_tags.rs, rest_catalog/read_path_completion.rs; docs python-binding.md, sql.md.
Core change notice: this PR changes general paimon-core tag semantics for every binding, not just SQL procedures:
TagManageris now file-only: the REST-owned mode (RestTags,ensure_storage_owned, dot-segment filtering, ISO retention conversion) is removed. Loaded tables read and writetag/tag-<name>on their own branch (branch/branch-<b>/tag/for non-main), including create, replace, rename, and delete. Identifier-basedCatalogtag methods keep using the server endpoints.- The scan tag cache moves from
caching_catalog.rsintotable/tag_manager/cache.rswith the same options, defaults (30 min write / 10 min access, legacycache.expiration-intervalalias), LRU capacity, and single-flight semantics. The cached value is nowOption<Snapshot>read from files instead ofGetTagResponse; missing results are shared by current waiters then discarded. Keys stay (identifier-with-branch, UUID, tag). - Cache misses check table identity before and after reading the tag file, so a recreated table sharing the storage path cannot poison the cache;
get_for_scanonly caches when the manager's branch matches the loaded REST identity, otherwise it falls back to a fresh file read. - Table-level tag writes acquire
InvalidateOnDrop(invalidate before and after the mutation), andCachingCatalogmutations reuse the same helper.without_tag_cacheis removed: listings,get_with_metadata, referenced-file collection, and rollback target resolution now read current files directly, which is authoritative without a cache-bypass flag. time_traveldrops the REST 501 fallback for numeric/watermark versions:scan.versionresolves tag files first, then snapshot id/watermark, uniformly for filesystem and REST tables.
Analysis:
- Behavior alignment: this matches Java, where
TagManageralways operates on table files and the REST catalog tag endpoints are a separate identifier-based surface. The previous Rust REST-owned mode blocked replace/rename on REST tables and hid storage-only tags; the new tests verify those procedures now work through files whileCatalog::create_tag/delete_tagstill hit the server, and the mock server now writes real tag files so both surfaces stay consistent. - The 501-endpoint scenario is covered end to end (rest-server e2e): create/list/time-travel/delete all work from storage while
catalog.get_tagstill reports unsupported. The numeric-version resolution test verifies tag-file precedence and clean fallback after the tag file is removed. - Cache-invalidation races are preserved from the previous implementation: an invalidated in-flight load cannot repopulate the cache, a missing load cannot evict its replacement (
Arc::ptr_eqguard), and a cancelled load leaves no poisonedOnceCell. The moved unit tests still cover coalescing, expiration (write vs access deadlines), key isolation per database/branch/table/tag, config validation, and case-insensitive booleans. - Branch handling:
with_branchkeeps the table root path and switches only the tag directory, sotag_manager()on a branch copy resolvesbranch/branch-<b>/tag/;copy_with_branchstill loads the branch identity through the catalog, giving each branch its own UUID-scoped cache entries (verified bycopied_branches_share_tag_cache, including cache reuse after the branch tag file is deleted externally). - Legacy dot-segment tags (
./..) now work through files instead of being rejected, since the URL-path limitation only applied to the REST API; name validation still rejects separators and control characters. Referenced-file accounting reads tags from storage per branch and keeps failing on metadata errors rather than undercounting; the external-retagging test confirms fresh file reads while the scan cache entry stays intact. - Rollback keeps its stricter contract: target resolution reads the current tag file (not the scan cache), the rebound-target rejection tests are reworked to repoint the tag on the rollback request, and both success and failure paths invalidate shared handles.
resolve_snapshot_by_idin procedures now only falls back to tags onSnapshotNotExistand propagates other errors, instead of swallowing all snapshot read failures; managers come from the loaded table so branch paths and REST env are honored.
No findings. Test coverage is comprehensive: 29 TagManager/cache unit tests plus the reworked REST integration suites covering cache sharing/invalidation across handles, UUID replacement isolation, branch caching, missing-tag single-flight without negative caching, storage-only tags, corrupt tag files (readable error, deletable), retention metadata round-trips, and referenced-file counts with expired snapshots retained by tags.
CI note: all reported checks green (builds and units on Linux/macOS/Windows, all integration suites, MSRV, check); macOS unit still pending. The author reports 340 Rust/DataFusion/REST-server integration tests and 29 TagManager/cache unit tests passing. Approving without waiting for CI.
LGTM.
Purpose
A loaded Rust table has a branch path and FileIO. Use them to read and write tag files for time travel, tag listings, and SQL tag procedures. The identifier-based REST Catalog methods use the server's tag endpoints.
This builds on the shared native tag cache introduced for #1564.
Brief change log
TagManager. Tables loaded by one caching catalog share the cache with entries scoped by table identity, branch, and tag.Tests
TagManagerand tag cache unit tests.API and Format
Table operations use the existing tag JSON. Catalog tag methods accept table identifiers and retain access through the REST catalog protocol.
Documentation
Updated the SQL, Python binding, and REST server guides for tag file operations and cache behavior.