Repository navigation
Description
Summary
RowIdSequenceKey's cache key encodes only the fragment id, with no dataset
version or generation component. Combined with the fact that the metadata cache
is namespaced by dataset URI only, this makes it possible for a long-lived
shared cache to serve a stale row-id sequence from a previously dropped
dataset to a new dataset created at the same URI, once fragment ids
overlap. The first mutation that consults the sequence then panics:
lance/src/dataset/utils.rs:129:
index.get(row_id).expect("row id missing from index")
Where the gap is (lance 8.0.0)
The cache key carries no version:
// src/session/caches.rs
pub struct RowIdSequenceKey {
pub fragment_id: u64,
}
impl CacheKey for RowIdSequenceKey {
type ValueType = RowIdSequence;
fn key(&self) -> Cow<'_, str> {
Cow::Owned(format!("row_id_sequence/{}", self.fragment_id))
}
...
}The only namespacing above the key is the dataset URI:
// src/session/caches.rs — GlobalMetadataCache
pub fn for_dataset(&self, uri: &str) -> DSMetadataCache {
// Create a sub-cache for the dataset by adding the URI as a key prefix.
// This prevents collisions between different datasets.
DSMetadataCache(self.0.with_key_prefix(uri))
}So the effective key is {uri}/row_id_sequence/{fragment_id}. The comment is
correct that this "prevents collisions between different datasets" — but it does
not prevent collisions between two generations of the same URI: drop the
dataset at uri, create a new one at the same uri, and the new dataset's
row_id_sequence/0 resolves to the dropped dataset's cached sequence. The
physical rows of the new fragment 0 don't match that stale sequence, so
RowIdIndex::get returns None and the expect above panics.
Reproduction (shape)
Single process, one shared Session/metadata cache across the dataset's
lifetime (typical of an embedding host that keeps a connection/session alive):
- Create dataset at
uriwith stable row ids, insert rows, compact, drop. - Create a new dataset at the same
uri, insert rows. - First
DELETE/UPDATEon the new dataset consults the row-id sequence →
panicrow id missing from index. With concurrent readers priming the cache
it reproduces within a few cycles; single-threaded it reproduces
deterministically when the stale entry is still resident.
Observed via lancedb 0.31 + lance 8.0.0.
Suggestion
Include a dataset generation/identity component in the row-id sequence cache key
(or in the sub-cache prefix) — e.g. the dataset UUID or the manifest version the
sequence was read from — so that a re-created dataset at the same URI cannot
alias a dropped dataset's sequence. Today any cache-retention path anywhere in a
host process re-manifests as index corruption rather than a clean miss.
A downstream consumer can mitigate by purging the session cache by URI prefix on
drop (we did this in our lancedb binding), but the version-less key is the
underlying hazard.
Happy to provide a minimal standalone repro or a PR if the direction sounds
right.
Activity
hellower commentedon Jul 6, 2026
Downstream lancedb issue with the drop → same-URI recreate reproduction and a working drop-time purge mitigation: lancedb/lancedb#3626
fix(core): key row id sequence cache on fragment contents (lance-form…
fix(core): key row id sequence cache on fragment contents (lance-form…