Skip to content

drop_table leaves stale session cache entries — same-URI recreate can panic with "row id missing from index" #3626

Open
lance-format/lance
#8916

Description

@hellower

Summary

Connection::drop_table removes the table's data but does not purge the shared
Session caches (dataset metadata cache / index cache) for the dropped table's
URI. When a table is dropped and a new table is re-created under the same
URI
, a subsequent mutation (DELETE/UPDATE with stable row ids) can resolve
stale cached metadata belonging to the dropped dataset and panic inside lance:

lance/src/dataset/utils.rs:129: row id missing from index

Why the stale entry survives

The most damaging stale entry is the row-id sequence. Its cache key is
version-less (row_id_sequence/{fragment_id} — RowIdSequenceKey in lance), and
the only namespacing above it is the dataset URI prefix
(GlobalMetadataCache::for_dataset(uri)), which the comment there notes
"prevents collisions between different datasets". It does not prevent collisions
between two generations of the same URI. So after drop + same-URI re-create,
a lookup for row_id_sequence/0 of the new dataset can hit the sequence of the
old (dropped) dataset still resident in the shared session, and the mismatch
against the new fragment's physical rows trips the row id missing from index
invariant. (Filed the version-less-key angle separately against lance.)

Reproduction (embedding host, single process, shared session)

  1. CREATE table t (stable row ids), insert rows, COMPACT, DROP TABLE t.
  2. CREATE table t again at the same URI, insert rows.
  3. First DELETE on the new t → panic. Deterministic when the stale entry is
    still resident; with concurrent readers priming the cache it reproduces
    within a few cycles.

Observed with lancedb 0.31 / lance 8.0.0.

Fix that worked for us

  • Have the connection own its Session explicitly (ConnectBuilder::session()),
    so drop_table can reach both cache layers deterministically.
  • After the drop, purge both caches by URI prefix — using two
    terminator-precise prefixes
    ({uri}/ and {uri}?) so sibling tables that
    share a name prefix (t vs t2, or a query-string variant) are not evicted.
  • Run the purge unconditionally after the drop attempt (also on the timeout
    path), so a timed-out-but-still-progressing drop cannot leave repopulated
    stale entries behind.

After the fix: 30/30 drop → re-create → mutate cycles clean (previously panicked
by cycle 3).

Happy to upstream a PR if the approach sounds right — the ideal fix probably
combines this drop-time purge with a version/generation component in lance's
row-id sequence cache key.

Activity

  1. hellower commented on Jul 6, 2026

    @hellower
    Author

    Companion lance issue for the version-less cache key: lance-format/lance#7645

  2. wjones127 commented on Jul 13, 2026

    @wjones127
    Contributor

    I think what we need to do is start adding the version + manifest e_tag as part of the prefix, and that will avoid this kind of cache issues on drop.

  3. hellower commented on Aug 31, 2026

    @hellower
    Author

    Update: as of lance-format/lance#8904 (merged 2026-08-31), IndexMetadataKey now carries the manifest e-tag, closing one of the four gaps #8078's own follow-up note named. RowIdSequenceKey was already fixed by #8078 itself.

    The remaining three — TransactionKey, RowIdIndexKey, RowAddrMaskKey — are addressed by lance-format/lance#8916, extending #8904's exact pattern to each. Includes a drop/recreate regression test for TransactionKey (verified it fails without the fix, passes with it) and key-isolation unit tests for all three.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions