Skip to content

fix: distinguish corrupt table from missing in open_table - #3731

Merged
wjones127 merged 1 commit into
lancedb:mainfrom
joaquinhuigomez:fix/distinguish-corrupt-table-from-missing
Jul 30, 2026
Merged

wjones127 merged 1 commit into
lancedb:mainfrom
joaquinhuigomez:fix/distinguish-corrupt-table-from-missing

Conversation

@joaquinhuigomez

Copy link
Copy Markdown
Contributor

table_names() lists any *.lance directory, but open_table() maps every DatasetNotFound to TableNotFound, so a corrupt or partially-written table looks identical to one that never existed (#3127). This takes the issue's Option 2: on DatasetNotFound, check the parent listing for the table's .lance entry — the same predicate table_names() uses — and return a new TableCorrupted error when the directory is present. The check runs only on the error path, and any failure in the recheck falls back to the previous TableNotFound behavior.

Tests cover the reporter's empty-dir repro, a deleted-manifest case, true absence (still TableNotFound), and an end-to-end list-then-open assertion; the three new corrupt-case tests fail without the src change. cargo test -p lancedb --lib 732 passed, clippy/fmt clean, cargo check --workspace --all-targets clean (both language bindings end in wildcard error arms).

Two notes for review: Error isn't #[non_exhaustive], so the new variant is technically semver-breaking for exhaustive matchers (pre-1.0, and the alternative — changing TableNotFound's shape — breaks more); and on the Python side corrupt tables now surface as RuntimeError rather than ValueError, which is the intended distinction but worth a maintainer's eye. open_from_namespace was left unchanged since namespace listings come from a server-side registry, not directory globbing.

Closes #3127

`table_names()` lists any `<name>.lance` directory without validating it,
while `open_table()` maps every `lance::Error::DatasetNotFound` to
`Error::TableNotFound`. A directory left behind by an interrupted drop and
re-create is therefore listed as a table but reported as missing when opened,
and callers cannot tell "never existed" from "exists but is unreadable".

On `DatasetNotFound`, check whether a `<name>.lance` entry is actually present
in the parent directory — the same predicate `table_names()` uses — and return
the new `Error::TableCorrupted` when it is. The check only runs on the error
path, and listing the parent (rather than probing the table path) is the one
form that works for both local filesystems and object stores, which have no
empty directories.

Closes lancedb#3127

@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 bug Something isn't working Rust Rust related issues labels Jul 27, 2026
@wjones127
wjones127 self-requested a review July 28, 2026 20:35

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

This makes sense, although perhaps you want to take it a step further and map it to a good error in Python? If not, we can file a follow up issue.

This also makes me think we should create a repair command on databases.

Comment thread rust/lancedb/src/error.rs
Comment on lines +21 to +24
#[snafu(display(
"Table '{name}' exists but could not be loaded (it may be corrupt or incomplete): {source}"
))]
TableCorrupted { name: String, source: BoxError },

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.

suggestion: it would be nice to map this error to a nice error in Python. Right now, they will just be converted to RuntimeError:

_ => self.runtime_error(),

@wjones127
wjones127 merged commit b505dc1 into lancedb:main Jul 30, 2026
25 checks passed
BubbleCal added a commit that referenced this pull request Aug 13, 2026
## What is the bug?

#3731 tries to distinguish a missing table from a corrupt table after
Lance returns `DatasetNotFound`. It does that by listing the database
parent and treating a physical `<name>.lance` entry as evidence that the
table exists.

That premise is not sound for a listing database. Table creation writes
data before atomically committing the first manifest, so the same
physical prefix can represent a live concurrent create, abandoned
uncommitted data, or an old empty directory. It is not evidence of a
committed table. The parent listing also makes every missing-table open,
including the create-on-miss path, perform work proportional to the
number of sibling tables. Cloud `list_with_delimiter` exhausts all pages
before returning.

## How does this PR fix the problem?

This PR makes the committed Lance manifest the sole table-existence
authority for listing-database opens:

- `DatasetNotFound` maps directly to `TableNotFound`; no parent or
target storage probe runs.
- Other Lance load errors continue to propagate unchanged.
- A physical directory, object prefix, or uncommitted data file alone
does not block `Create`.
- Concurrent `Create` requests are arbitrated by the conditional
version-1 manifest commit: one succeeds and the loser receives
`TableAlreadyExists`.
- `table_names` is documented as physical discovery, not an atomic
table-existence check. Its snapshot can contain an entry that is still
being created, has only uncommitted storage, or is concurrently dropped.

This removes the need for a new Lance object-store capability. LanceDB
remains on the official Lance `v11.0.0-beta.6` dependency from `main`;
the merge commit for lance-format/lance#7722 is an ancestor of that tag,
so the ambiguous-GCS-500 corruption-prevention fix is retained.

## Performance evidence

Lower is better. The benchmark uses real `.lance` directories with
marker objects on the local filesystem; fixture creation and teardown
are outside the timed region. Baseline is `origin/main` at `6fb976cf`,
candidate is `e1240751`. Both were built from the same lockfile on the
same macOS arm64 machine with the repository's `release` profile (fat
LTO), then executed in alternating baseline/candidate order for three
pairs. Each run used 10 warmups and 100 distinct missing-table opens per
scale. The table reports the median of the three run-level percentiles.

| Scenario / metric | Baseline | This PR | Benefit |
| --- | ---: | ---: | ---: |
| 1,000 real sibling directories, p50 | 11.905 ms | 21.042 us | 566x
speedup |
| 10,000 real sibling directories, p50 | 143.630 ms | 18.375 us | 7,817x
speedup |
| 100,000 real sibling directories, p50 | 1.991 s | 19.917 us | 99,984x
speedup |
| 100,000 real sibling directories, p95 | 2.346 s | 25.792 us | 90,965x
speedup |

These results validate removal of the sibling-cardinality dependency in
this local-filesystem workload; they are not an extrapolation to
production GCS latency. A structural object-store regression test
separately asserts that opening one missing table performs zero
parent-scoped `list`, `list_with_offset`, or `list_with_delimiter`
calls.

Run with:

```bash
BENCH_SIBLINGS=1000,10000,100000 BENCH_WARMUPS=10 BENCH_TRIALS=100 \
  cargo run --locked --release --quiet -p lancedb --example bench_open_missing_table
```

## Correctness and compatibility boundaries

- An empty `.lance` directory or orphan data without a committed
manifest now opens as `TableNotFound` and may be replaced by a
successful `Create`.
- Two synchronized creators sharing one object store deterministically
produce one success and one conditional-manifest conflict mapped to
`TableAlreadyExists`.
- A readable manifest remains authoritative; non-`DatasetNotFound`
corruption, external-manifest, authorization, and object-store errors
are not folded into `TableNotFound`.
- `TableCorrupted` remains in the public error enum for compatibility,
but this listing-database fallback no longer synthesizes it from an
ambiguous physical footprint.
- Reliably distinguishing `Missing`, `Creating`, and `Corrupt` would
require explicit authoritative lifecycle/catalog metadata (for example a
leased creation record). It cannot be inferred from a directory or
prefix, and is outside this incident fix.

## Validation

- `cargo fmt --all -- --check`
- `cargo check --quiet --locked -p lancedb --features remote --tests
--examples`
- `cargo clippy --quiet --locked -p lancedb --features remote --tests
--examples -- -D warnings`
- `cargo test --quiet --locked -p lancedb --features remote --tests`
  - library: 843 passed, 1 ignored
  - integration groups: 39 passed, 6 passed, 5 passed
- focused coverage for empty directories, orphan data, physical listing
snapshots, zero parent listings, and concurrent manifest arbitration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Rust Rust related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: table_names() lists table with corrupt/incomplete .lance directory that open_table() cannot open

2 participants