Make dataset in StorageBase interior-mutable - #236
Open
lucyge2022 wants to merge 10 commits into
Open
Conversation
…agebase so ops like merge, compact & schema evolution doenst need mutex of store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhancement on #198 - StorageBase should not own Dataset by value, and remove the necessity of using &mut self everywhere that needs a writer mutex for StorageBase bcos of that reason.
Root cause:
Datasetrebinding, not the work itselfStorageBaseowned itsDatasetby value. Lance mutating ops (append,compact_files,checkout_latest, schema evolution) take&mut selfnot because they mutate in place, but because they replace the whole handle at the end:That requirement propagated outward:
append_merged_batches→commit_merge→cleanup_own_shard→ callers holdingRwLock::write()on the store for the entire merge — including the expensive prepare phase (seal + read every flushed generation from object storage).But this is an LSM: a merge folds sealed generations into the base table while
addwrites the active memtable at the WAL tail. Disjoint data. They should not have serialized for the borrow checker's sake.Fix: interior-mutable dataset + narrow merge lock
StorageBase::datasetArcSwap<Dataset>— merge/compact/reload publish a new handle viaset_dataset()without&mut selfon the store&selfonStorageBase,RolloutStore,ContextStore,DatagenStore,GenericStoremerge_lock(try_lock→ second prepare no-ops) instead of accidental exclusivity from&mutPreparedMergeholdsmerge_lockuntil commit or dropSweeper, HTTP
merge-wal, and rollout/context compact routes updated toread()for maintenance; no write lock spanning seal + generation reads + base append.Ordering preserved
prepare_cleanup_mergestill seals before reading the shard manifest. With deferred flush intervals, reading the manifest first leavesflushed_generationsempty and rows durable but invisible until restart — load-bearing ordering kept intact.What deliberately did not change
ContextStorestill uses&mut selffor delete/upsert andstart_background_compaction— store-local lifecycle, unrelated toStorageBase's dataset handle. HTTP compact/merge paths do not need the outer write lock.Theoretically prepare + commit two phase split could be removed, but out of scope for this PR.
Tests
Extended
wal_merge_concurrency.rs(the existing generation-cleanup suite is explicitly serial — none of this had coverage):preparelosesmerge_lockwhile firstPreparedMergeis livePreparedMergeis heldEach merge test drives the sweeper's exact discipline:
read()prepare →read()commit viamerge_like_sweeper.Follow-ups (not folded in)
datagen_store.rsmay still carry the olderclaim_epoch-then-close pattern — separate pass.Verification
cargo test -p lance-context-core --test wal_merge_concurrencycargo test -p lance-context-core --test wal_merge_generation_cleanupcargo fmt --checkandclippy --workspace --all-targets -D warningsCloses #198.