Skip to content

feat(namespace): support page_token for descending table version listings - #11469

Merged
Xuanwo merged 3 commits into
lance-format:mainfrom
vaibhavdabas16:feat/11448-descending-version-page-token
Nov 30, 2026
Merged

Xuanwo merged 3 commits into
lance-format:mainfrom
vaibhavdabas16:feat/11448-descending-version-page-token

Conversation

@vaibhavdabas16

@vaibhavdabas16 vaibhavdabas16 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #11448 (item 2: page_token for descending listings).

DirectoryNamespace::list_table_versions ignored page_token when descending = true, and never returned a continuation when more versions existed. A newest-first history therefore couldn't be paged.

Changes:

  • New list_descending_version_page: the newest-first counterpart of list_ascending_version_page.
    • The token is the last (oldest) version on the page, and the next page holds the versions below it.
    • It requests limit + 1 rows to tell whether another page follows.
    • Token validation is shared with the ascending path: only the canonical decimal form of a non-negative version is accepted, and anything else is InvalidInput.
  • Early stop preserved:
    • list_versions_under now delegates to list_versions_below, which takes an optional exclusive upper bound.
    • The bound is applied after the naming scheme is read from the first manifest listed, so the ordered-V2 check is unchanged.
    • On lexically ordered V2 stores the listing still stops after limit + 1 kept manifests. descending = true, limit = 1 (get_latest_version) stays a short read.
    • Other layouts and unordered stores still collect, filter and sort.
  • Out of scope: item 1 of the issue (avoiding per-page _versions/ rescans for ascending pages) isn't addressed here.

Tests: both extend existing tests.

  • test_list_table_versions_pagination_mixed_manifests_and_cleanup (mixed V1/V2 manifests, plus staging, backup and detached files) pages a descending history with limit = 3. It checks the pages are [20, 12, 11], [10, 7, 5], [2], that limit = 1 returns a continuation, and that a non-canonical token is rejected.
  • test_list_versions_under_ordering_and_limit checks bounded descending listings on both a lexically ordered store (early stop) and an unordered local store (sort path).

Checks run locally:

  • cargo test -p lance-namespace-impls --lib -- version: 80 passed.
  • cargo fmt passes.
  • I didn't run clippy locally because of build resources on my machine.

Mixed manifest layouts: on a lexically ordered store, a V2 first entry is taken to mean the table uses V2 names, the same assumption Dataset::open makes. The descending listing then uses a single bounded LIST. If the scan meets a V1 manifest, it collects and sorts the rest numerically. On a table whose writers use a consistent naming scheme, walking every page returns exactly the unbounded descending history.

Note: if a handle opened before a migrate_manifest_paths_v2 run writes a V1 manifest after the migration completed, stop using the stale handles, re-run migrate_manifest_paths_v2, and reopen the writers before resuming writes.

…ings

DirectoryNamespace::list_table_versions ignored page_token when
descending was set and never returned a continuation, so a newest-first
history could not be paged.

A descending page now returns the last (oldest) version it holds as the
page token, and the next page lists the versions below it. The listing
still stops early on lexically ordered V2 stores, so fetching the latest
version reads at most limit + 1 manifests.

Part of lance-format#11448.

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-namespace Namespace impls enhancement New feature or request labels Nov 25, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 25, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Technical blocker: the first bounded page can miss the newest committed version. I tested DirectoryNamespace::list_table_versions on an ordered object store with manifest names modeling an interrupted migration. Versions 1 and 10–18 used V2 names and the remaining versions through 20 used V1. Unbounded descending listing returned 20 through 1. With limit=1, the first page returned 18 and token 18, making both 20 and 19 unreachable.

Please keep the logical-version cursor, establish numeric order before limiting mixed histories, and use the short V2 lookup when that ordering is guaranteed. A regression comparing a complete bounded walk with the unbounded result would cover both the first page and subsequent boundaries.

The descending early stop trusted stream order whenever the first
manifest listed had a V2 name. On a partly migrated table, V1 names
such as 19.manifest or 2.manifest sort after every V2 name and can hold
the newest versions, so a bounded page could skip them and its cursor
made them unreachable.

Before stopping early, list from just past the largest possible V2 name
and stop at the first key that cannot be a V1 manifest. Any V1 manifest
found there disables the early stop, so the listing is collected and
sorted numerically. A table using only V2 names pays one short extra
request.
@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Thanks @Xuanwo, you're right. A V2 first entry only proves no V1 name sorts before the V2 names. In your interrupted migration, 19.manifest and 20.manifest sort after them, so the early stop never saw them.

Fixed in ff967a1. The cursor is still the logical version. Before the early stop is trusted, has_v1_manifests_after_v2_names lists from just past the largest possible V2 name (18446744073709551615.manifest). It stops at the first key whose segment under _versions/ doesn't start with a digit; detached manifests start with d. If any V1 manifest is there, the listing is collected and sorted numerically before the page is cut. V1 names that sort before the V2 names already took the sorting branch through the first-entry check.

Cost: a table using only V2 names makes one extra short list_with_offset request that returns nothing committed. test_list_versions_under_early_stop_bounded_consumption now forwards list_with_offset in its counting store and still asserts that the latest-version lookup consumes 2 entries.

Regression test: test_descending_pages_across_manifest_layouts compares a complete bounded walk, for every limit from 1 to the version count, with the unbounded descending listing. Cases:

  • your layout: V2 for versions 1 and 10–18, V1 for 2–9, 19 and 20
  • a V2 prefix with a V1 tail
  • V1 names sorting before V2 names
  • V2 only

This also addresses the Gatekeeper finding. cargo test -p lance-namespace-impls --lib -- version: 84 passed.

One note: resolve_version_from_listing in lance-table makes the same V2-first assumption when opening a table, so a dataset in this state still resolves its latest version as 18 there. I left that out of scope here. Happy to open a separate issue if you'd like.

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 25, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 25, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I verified the original interrupted migration on ff967a193: all 20 versions are reachable. The 84 repository tests and five additional probes passed.

One pagination blocker remains when a canonical V1 filename sorts between two V2 filenames. Let a = 1844674407370955161. With V1(a), V2(6), and V2(1), the unbounded descending listing returns [a, 6, 1]. Following every cursor with limit=1 returns [6, 1]. With limit=2 it returns [6, a, 6, 1]. All three filenames sort below the suffix seek, so an empty suffix cannot guarantee V2 ordering.

These versions are legal but far beyond ordinary sequential histories. I installed a predecessor with the manifest writer, published a through the namespace API, and deleted the predecessor. Namespace CAS then treated 6 as latest. The direct-open resolver's first-V2 behavior predates this change.

Please cover this interleaved layout by comparing the complete bounded walk with the unbounded numeric order. Can the early stop be limited to layouts guaranteed to be V2-only, with numeric sorting when a mixed layout is still possible?

The V1 probe added in the previous commit used list_with_offset, which
backends without start-after pushdown (Hugging Face through OpenDAL)
emulate by listing the whole directory. Every latest-version lookup on
such a store read the full history again.

Drop the probe. Like resolve_version_from_listing, take a V2 first
entry to mean the table uses V2 names. Any V1 manifest the early stop
meets while scanning, including one sorting between V2 names, still
drops the early stop and the listing is sorted numerically.
@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Thanks @Xuanwo, and thanks for the interleaved case. Your two findings pull in opposite directions, so I want to lay out the trade-off and ask which direction you'd like.

  • Gatekeeper: list_with_offset is emulated by a full listing on backends without start-after (Hugging Face through OpenDAL). So the ff967a193 probe made every latest-version lookup there read the whole history.
  • Your case: a V1 name can also sort between V2 names. So no probe of a suffix, or of any bounded prefix, can prove a table is V2-only. Only a full listing can.

Proving V2-only and keeping the latest-version lookup bounded can't both hold. The options I see:

  • A. Always sort bounded descending pages numerically. Always correct, but the latest-version lookup becomes history-proportional, undoing what perf: stop listing the entire _versions directory for limited version queries #8679 kept.
  • B. Keep the same assumption as resolve_version_from_listing (a V2 first entry means V2 names). Drop the early stop whenever the scan meets a V1 manifest. A partly migrated table that hides V1 names beyond the scan is expected to finish migrate_manifest_paths_v2, as it already must for Dataset::open.
  • C. B for the first page, and numeric sorting whenever a page_token is set.

I've pushed B in 72adfe1, since it keeps namespace listing consistent with how a dataset resolves its own latest version:

  • The probe is gone, so every backend makes one bounded listing again.
  • Any V1 manifest the early stop reads turns the early stop off, and the listing is collected and sorted.
  • Your layout, V1(1844674407370955161), V2(6), V2(1), now walks as [a, 6, 1] for every limit. 1844674407370955161.manifest sorts between the V2 names of 6 and 1, so the scan meets it.

test_descending_pages_across_manifest_layouts compares the full bounded walk, for every limit, with the unbounded listing. It covers that layout plus a V2 prefix with a V1 tail, V1 names sorting before V2 names, and V2 only. cargo test -p lance-namespace-impls --lib -- version: 84 passed.

What B gives up: your earlier interrupted migration, with V2 for 1 and 10–18 and V1 for 19 and 20. 19.manifest and 20.manifest sort after every manifest the early stop reads, so a bounded first page returns 18 again. That's the same version Dataset::open resolves for that directory. I removed that case from the test rather than assert the limitation.

If you'd rather have A or C, both are small changes on top of this.

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 25, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 25, 2026

@Xuanwo Xuanwo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Option B can also miss a commit after migration succeeds. I reproduced this on 14.0.3 with a memory-backed DirectoryNamespace. I left a writer idle at version 2, ran migrate_manifest_paths_v2() on a second handle, and verified that versions 1 and 2 both had V2 filenames. Only then did I call update_config() on the original handle. It committed 3.manifest. The full descending listing returned [3, 2, 1], while limit=1 and a freshly opened dataset both reported version 2. All operations were serial, as the released migration docs require.

Tracing 72adfe1e, the two V2 names fill the first page and its lookahead. The returned token is 2, so every subsequent page excludes version 3. Sorting only after a token is supplied (option C) cannot recover it either. Could you keep this three-version regression and assert that walking the public pages returns [3, 2, 1]? That checks the new pagination contract independently of the existing latest-version lookup.

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for laying out the trade-off. I agree with option B in 72adfe1e. Keep the same early-stop assumption as Dataset::open: on an ordered V2 history, use a single bounded LIST; if the scan encounters a V1 name, collect and sort the rest. On a table whose writers use a consistent naming scheme, walking every page should return exactly the unbounded descending history.

I'll follow up separately on the stale writer. Please add one note to the PR docs: if a handle opened before migration has written a V1 manifest after migration completed, stop using the stale handles, re-run migrate_manifest_paths_v2, and reopen the writers before resuming writes.

@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Thanks @Xuanwo. I added the stale-writer note to the PR description, along with a short summary of the option B behavior: one bounded LIST on an ordered V2 history, and collect-and-sort once a V1 name is seen.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 26, 2026

@lance-gatekeeper lance-gatekeeper Bot 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.

⚠️ Gate recommendation: approve with a non-blocking risk.

The added operating note clarifies that mixed layouts can recur after a successful migration through stale V1 writer handles. The accepted risk remains incomplete bounded histories, including omitted newest commits. Stop stale handles, finish or repeat migrate_manifest_paths_v2, and reopen writers before resuming writes.

The logical cursor and short ordered-V2 lookup remain acceptable for histories with a consistent naming scheme. The stale-writer defect is tracked separately in #11513, with a commit-path fix proposed in #11521; no writer changes are requested here.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 26, 2026
Xuanwo pushed a commit that referenced this pull request Nov 26, 2026
Addresses the ascending LIST cost in #11448. Descending continuation is
under review in #11469.

For a bounded ascending continuation on ordered S3, check whether a V1
key could contribute to the requested interval, then seek to the
corresponding V2 keys. Return the page directly only after finding every
expected version and one lookahead row. A gap, a possible V1 overlap, or
a change in decimal width falls back to the existing numeric scan. The
logical page token survives deletion of its manifest.

The regression compares a complete ascending walk with unbounded history
when a V1 key sorts between V2 keys. It also checks bounded reads,
duplicate manifests, and cleanup between pages.

With 10,001 V2 manifests on Moto 5.2.6, the public Rust API returned
every expected version, manifest path, size, eTag and timestamp. No
query issued a manifest GET or HEAD.

| Query | Upstream version-directory LISTs | This PR |
| --- | ---: | ---: |
| Latest version | 1 | 1 |
| Full ascending history, unbounded | 11 | 11 |
| Full ascending history, pages of 1,000 | 121 | 68 |
| Full ascending history, pages of 100 | 1,111 | 260 |

The three-version continuation consumed 102 entries on upstream and at
most five with this patch. All 512 namespace unit tests passed. Rust
formatting and Clippy passed in CI. The Java 25 job needs a maintainer
rerun after Maven Central returned HTTP 429 while resolving the Maven
JAR plugin. [Java job
log](https://github.com/lance-format/lance/actions/runs/45667556579/job/139396945155)
@Xuanwo
Xuanwo merged commit 3797d0c into lance-format:main Nov 30, 2026
47 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-namespace Namespace impls enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants