Skip to content

fix(compaction): keep rewritten files when fragment-id reservation fails - #9995

Merged
Xuanwo merged 3 commits into
lance-format:mainfrom
dsingh-exa:compaction-reservation-failure-keep-files
Oct 24, 2026
Merged

Xuanwo merged 3 commits into
lance-format:mainfrom
dsingh-exa:compaction-reservation-failure-keep-files

Conversation

@dsingh-exa

Copy link
Copy Markdown
Contributor

RewriteResult is serializable, so a compaction result can be committed again after an earlier commit already published it. If reserving fragment ids for that replay fails, commit_compaction deleted the rewritten files. Reassigning fragment ids doesn't change data file paths, so those files can still be referenced by the published version. Deleting them makes the dataset unreadable: on the base, replaying a published compaction with an injected reservation failure leaves the current version failing to scan with Not found.

This keeps the files when reservation fails, which matches how a failed rewrite commit is already handled. Cleanup after a failed rewrite is unchanged.

Tradeoff: output that really is orphaned now waits for cleanup_old_versions. With delete_unverified it is reclaimed immediately; otherwise it waits for the 7-day unverified threshold.

This partly reverts the reservation-failure cleanup from #7722. That PR reasoned that reservation commits don't reference the rewritten files, which doesn't hold for replays.

Tests cover both the address-style path (defer_index_remap) and the stable-row-id path:

  • A replay test checks that the files survive and that the reopened data and version are unchanged.
  • A fresh-run test checks that the files are retained and that GC then reclaims them.

@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 the bug Something isn't working label Oct 15, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 15, 2026
@wjones127 wjones127 added the critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. label Oct 19, 2026

@geruh geruh 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.

Thanks for raising @dsingh-exa! I think keeping the files here makes sense since a failed reservation doesn't necessarily mean they're unreferenced, especially with retries. Just left a couple minor nits.

let ds = Dataset::open(test_uri).await.unwrap();
assert_eq!(ds.count_rows(None).await.unwrap(), num_rows);
assert_eq!(ds.version().version, published_version);
assert_eq!(ds.scan().try_into_batch().await.unwrap(), expected);

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.

nit: could we also run cleanup_old_versions after the failed replay and check that the data is still readable? I think it'd be good to make sure GC doesn't delete the files from the earlier commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 52322c3.

Comment thread rust/lance/src/dataset/optimize.rs Outdated
// path below can clean them up (or deliberately keep them). Fragment ids
// may still be reassigned by reserve_fragment_ids; cleanup only needs the
// file paths, which never change.
let all_new_fragments: Vec<Fragment> = completed_tasks

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.

nit: looks like all_new_fragments is only used for .len() now that the cleanup is gone. could we just count the fragments instead of cloning them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch fixed in 52322c3.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 21, 2026
dsingh-exa and others added 2 commits October 20, 2026 16:17
`RewriteResult` is serializable, so a compaction result can be committed again
after an earlier commit already published it. If reserving fragment ids for
that replay fails, `commit_compaction` deleted the rewritten files. Reassigning
fragment ids does not change data file paths, so those files can still be
referenced by the published version, and deleting them leaves the dataset
unreadable.

Leave the files in place when reservation fails, matching the existing
handling of a failed rewrite commit. Unreferenced output is reclaimed by
`cleanup_old_versions`. Cleanup after a failed rewrite is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dsingh-exa
dsingh-exa force-pushed the compaction-reservation-failure-keep-files branch from 52322c3 to 8bcfe25 Compare October 21, 2026 02:17
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 21, 2026

@geruh geruh 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.

LGTM, thanks for addressing comments @dsingh-exa!

pending maintainer review

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 24, 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.

A failed reservation cannot establish that replayed files are unreferenced, so retaining them for dataset GC remains appropriate. The regression cases verify that GC preserves published data after a failed replay in both reservation paths, while fresh orphaned output remains reclaimable.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 24, 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.

Reviewed: on fragment-id reservation failure, rewritten files are no longer deleted immediately - a replayed RewriteResult can already be published, and reassigning ids does not change file paths, so deleting them would break the published version. Both reservation paths now leave files to cleanup_old_versions/GC, consistent with the existing failed-commit handling. Tests cover first-commit failure (files reclaimed by GC, readability preserved) and replay failure (published version/files survive GC). CI green; approving.

@Xuanwo
Xuanwo merged commit 6f65cf6 into lance-format:main Oct 24, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants