Skip to content

[core] Use tag files for loaded tables - #1585

Merged
JingsongLi merged 5 commits into
apache:mainfrom
JingsongLi:codex/read-tags-from-files
Dec 4, 2026
Merged

JingsongLi merged 5 commits into
apache:mainfrom
JingsongLi:codex/read-tags-from-files

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Resolve tag files on the loaded table's branch, including SQL create, replace, rename, and delete.
  • Put scan-cache loading, expiration, and invalidation under TagManager. Tables loaded by one caching catalog share the cache with entries scoped by table identity, branch, and tag.
  • Read current files for tag listings, referenced-file accounting, and client-side rollback target resolution.

Tests

  • Passed 340 Rust, DataFusion, and REST server integration tests, including table tag operations when the REST tag endpoint returns HTTP 501.
  • Passed 29 TagManager and 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.

@JingsongLi JingsongLi changed the title [core] Read tag metadata from table files [core] Resolve table tags from storage Dec 4, 2026
@JingsongLi
JingsongLi marked this pull request as draft December 4, 2026 03:50
@JingsongLi JingsongLi changed the title [core] Resolve table tags from storage [core] Use tag files for loaded tables Dec 4, 2026
@JingsongLi
JingsongLi marked this pull request as ready for review December 4, 2026 04:11

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:

  • TagManager is now file-only: the REST-owned mode (RestTags, ensure_storage_owned, dot-segment filtering, ISO retention conversion) is removed. Loaded tables read and write tag/tag-<name> on their own branch (branch/branch-<b>/tag/ for non-main), including create, replace, rename, and delete. Identifier-based Catalog tag methods keep using the server endpoints.
  • The scan tag cache moves from caching_catalog.rs into table/tag_manager/cache.rs with the same options, defaults (30 min write / 10 min access, legacy cache.expiration-interval alias), LRU capacity, and single-flight semantics. The cached value is now Option<Snapshot> read from files instead of GetTagResponse; 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_scan only 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), and CachingCatalog mutations reuse the same helper. without_tag_cache is 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_travel drops the REST 501 fallback for numeric/watermark versions: scan.version resolves tag files first, then snapshot id/watermark, uniformly for filesystem and REST tables.

Analysis:

  • Behavior alignment: this matches Java, where TagManager always 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 while Catalog::create_tag/delete_tag still 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_tag still 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_eq guard), and a cancelled load leaves no poisoned OnceCell. 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_branch keeps the table root path and switches only the tag directory, so tag_manager() on a branch copy resolves branch/branch-<b>/tag/; copy_with_branch still loads the branch identity through the catalog, giving each branch its own UUID-scoped cache entries (verified by copied_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_id in procedures now only falls back to tags on SnapshotNotExist and 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.

@JingsongLi
JingsongLi merged commit 2456fee into apache:main Dec 4, 2026
15 checks passed
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.

2 participants