Skip to content

fix: make table existence manifest-authoritative - #3919

Merged
BubbleCal merged 18 commits into
mainfrom
yang/fix-open-table-parent-listing
Aug 13, 2026
Merged

BubbleCal merged 18 commits into
mainfrom
yang/fix-open-table-parent-listing

Conversation

@BubbleCal

@BubbleCal BubbleCal commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

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:

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

@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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 11, 2026
@github-actions github-actions Bot added bug Something isn't working Rust Rust related issues labels Aug 11, 2026
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 11, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Aug 11, 2026

@lancedb-gatekeeper lancedb-gatekeeper 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.

❌ Gate recommendation: request changes.

The configured-store revision improves wrapper handling and covers providers that return a non-file scheme, but probe selection still cannot distinguish a genuinely native, directory-aware backend from a provider-owned object store. That leaves both configured-store authority and the listed-empty-directory contract broken.

Carry an explicit, platform-aware probe capability from the resolved provider/store. Use native metadata only when that capability guarantees native directory semantics; otherwise use the bounded object-store probe without losing empty-directory detection for built-in local backends.

Comment thread rust/lancedb/src/table.rs Outdated
Ok(entries.iter().any(|entry| entry.as_str() == dir_name))

let is_native_local =
!requires_store_probe && matches!(object_store.scheme(), "file" | "file+uring");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The scheme() check is not sufficient to select the recovery probe. It produces two failures at this boundary:

  • a session provider can return ObjectStore::new(custom_inner, file_url, ...), which still reports file; this branch then bypasses the provider and returns TableNotFound for storage present in custom_inner;
  • the default file-object-store provider exposes an empty .lance directory to table_names() through list_with_delimiter, but the HEAD/recursive-list branch sees no object, so open_table() reports that listed table as missing instead of corrupt.

Please carry an explicit resolved-store probe capability or provider provenance, including platform behavior, and use symlink_metadata only when the resolved backend guarantees native directory semantics. This preserves empty local directories without bypassing custom providers or wrappers.

This is a successor to the earlier configured-store finding.

Reproducer

I added these regressions beside the existing provider helper:

#[tokio::test]
async fn test_open_recovery_uses_custom_file_provider_preserving_file_scheme() {
    use object_store::ObjectStoreExt as _;

    let tmp_dir = tempdir().unwrap();
    let dataset_path = tmp_dir.path().join("custom-file-scheme.lance");
    let uri = url::Url::from_file_path(&dataset_path).unwrap().to_string();
    assert!(!dataset_path.exists());

    let inner = Arc::new(object_store::memory::InMemory::new());
    let table_path = object_store::path::Path::from_url_path(
        url::Url::parse(&uri).unwrap().path(),
    )
    .unwrap();
    inner
        .put(&table_path.clone().join("_marker"), bytes::Bytes::new().into())
        .await
        .unwrap();
    let store = lance_io::object_store::ObjectStore::new(
        inner, url::Url::parse(&uri).unwrap(), None, None, false, false, 1, 0, None,
    );
    assert_eq!(store.scheme(), "file");

    let registry = Arc::new(lance_io::object_store::ObjectStoreRegistry::default());
    registry.insert("file", Arc::new(FileSchemeMemoryProvider { store }));
    let read_params = ReadParams {
        session: Some(Arc::new(lance::session::Session::new(0, 0, registry))),
        ..Default::default()
    };

    let err = NativeTable::open_with_params(
        &uri, "custom-file-scheme", Vec::new(), None, Some(read_params),
        None, None, HashSet::new(), None,
    )
    .await
    .unwrap_err();
    assert!(matches!(err, Error::TableCorrupted { .. }), "got {err:?}");
}

#[tokio::test]
async fn test_open_recovery_detects_empty_file_object_store_directory() {
    let tmp_dir = tempdir().unwrap();
    let dataset_path = tmp_dir.path().join("empty-object-store.lance");
    std::fs::create_dir(&dataset_path).unwrap();
    let path = tmp_dir.path().to_str().unwrap().replace('\', "/");
    let path_prefix = if path.starts_with('/') { "" } else { "/" };
    let db = connect(format!("file-object-store://{path_prefix}{path}"))
        .execute()
        .await
        .unwrap();

    assert_eq!(
        db.table_names().execute().await.unwrap(),
        vec!["empty-object-store".to_string()]
    );
    let err = db.open_table("empty-object-store").execute().await.unwrap_err();
    assert!(matches!(err, Error::TableCorrupted { .. }), "got {err:?}");
}

Run with:

cargo test --quiet -p lancedb --lib table::tests::test_open_recovery_ -- --nocapture

Expected both regressions to produce TableCorrupted; observed TableNotFound for both (3 passed, 2 failed).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in 8c83ff5: provider provenance is carried separately from the reported file scheme, and the built-in file-object-store path receives native directory probing. Both original reproducers now yield TableCorrupted; the focused current-head recovery suite passes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed on current head e9aed2c: the original custom-file-scheme and built-in file-object-store regressions now pass, and probe selection uses typed resolved-store capability instead of the reported scheme.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
Consume the follow-up capability fix so post-open wrappers cannot retain stale native-path authority.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
Consume the registry-prefix fix so capability-aware wrappers retain provider-scoped identity.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
Carry explicit native-path authority through direct store bindings so empty local table directories remain corrupt instead of missing.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
Keep the parent probe only for untyped deprecated direct bindings while provider-resolved and capable stores remain target-bounded.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026

@lancedb-gatekeeper lancedb-gatekeeper 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.

❌ Gate recommendation: request changes.

1 fixed / 1 new: the legacy direct-store regression is fixed, but explicit direct native-path authority can still be restored after a non-preserving wrapper invalidates it. Recovery can therefore bypass the effective store and misclassify or hide its errors.

Apply the resolver before wrapper invalidation, or retain it only when the wrapper preservation contract allows it, so both direct-store construction paths enforce the same authority ordering.

Comment thread rust/lancedb/src/table.rs Outdated
return Ok(entries.iter().any(|entry| entry.as_str() == dir_name));
}

if let Some(native_path) = object_store.native_directory_path(&path) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A non-preserving wrapper can still be bypassed here when a direct store also supplies an explicit native resolver. Lance DatasetBuilder passes the wrapper to ObjectStore::new, which invalidates native-path authority, and then calls with_native_directory_path_resolver afterward, restoring the authority that the effective wrapper declined. Recovery consequently reads host metadata and returns TableCorrupted instead of honoring the wrapped-store failure.

Apply the resolver before wrapper application, or condition its retention on preserves_native_directory_path(), and cover this direct-resolver/non-preserving-wrapper composition. This is a successor to the earlier wrapper-authority discussion.

Reproducer
#[tokio::test]
async fn test_direct_native_resolver_does_not_bypass_non_preserving_wrapper() {
    let tmp_dir = tempdir().unwrap();
    let native_table_path = tmp_dir.path().join("wrapped.lance");
    std::fs::create_dir(&native_table_path).unwrap();

    let uri = "memory:///database/wrapped.lance";
    let target = object_store::path::Path::from("database/wrapped.lance");
    let read_params = ReadParams {
        store_options: Some(ObjectStoreParams {
            object_store: Some((
                Arc::new(object_store::memory::InMemory::new()),
                url::Url::parse(uri).unwrap(),
            )),
            native_directory_path_resolver: Some(NativeDirectoryPathResolver::new(
                move |_path| native_table_path.clone(),
            )),
            object_store_wrapper: Some(Arc::new(OpenRecoveryTestStoreWrapper {
                fail_exact_head: Some(target),
                ..Default::default()
            })),
            ..Default::default()
        }),
        ..Default::default()
    };

    let err = NativeTable::open_with_params(
        uri,
        "wrapped",
        Vec::new(),
        None,
        Some(read_params),
        None,
        None,
        HashSet::new(),
        None,
    )
    .await
    .unwrap_err();

    assert!(
        !matches!(err, Error::TableCorrupted { .. }),
        "a non-preserving wrapper must remain authoritative, got {err:?}"
    );
}

Run:

CARGO_HOME=/home/agent/tmp/pr3919-legacy-cargo-01c CARGO_TARGET_DIR=/home/agent/tmp/pr3919-legacy-target-01c cargo test --quiet --features remote -p lancedb --lib test_direct_native_resolver_does_not_bypass_non_preserving_wrapper -- --nocapture

Expected the wrapped-store probe failure rather than TableCorrupted; observed TableCorrupted and the assertion failed (0 passed, 1 failed).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in 9f35d62: Lance DatasetBuilder now restores an explicit direct resolver only when no wrapper is configured or the wrapper declares that it preserves native paths. The new regression propagates the injected wrapper probe failure, the exact prior memory:/// reproducer passes, and the focused current-head open suite passes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed on current head e9aed2c: the original direct-store and non-preserving-wrapper reproducer now propagates the wrapper probe failure. A distinct provider-registry capability resurrection is reported separately on the current Lance pin.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
Pin the builder ordering fix and cover non-preserving direct wrappers so recovery cannot bypass their probe semantics.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
lancedb-gatekeeper[bot]

This comment was marked as outdated.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 12, 2026
Consume the approved identity binding so replacing an effective store automatically invalidates stale native-path authority.
@lancedb-gatekeeper lancedb-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 12, 2026

@lancedb-gatekeeper lancedb-gatekeeper 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.

❌ Gate recommendation: request changes.

The target-scoped recovery design is sound, but the final Lance pin regresses configured-provider authority: registry tracing and metrics can rebind native-path capability that was already invalid for the provider-returned store. Preserve that capability across registry wrappers only when it was valid for the exact inner store returned by the provider; otherwise keep it invalid so recovery probes the configured store.

Please mark this PR with the breaking-change label.

Comment thread Cargo.toml Outdated
lance-core = { "version" = "=11.0.0-beta.6", "rev" = "f8d628fe6af452cc168e0406c1199a91fb059cda", "git" = "https://github.com/lance-format/lance.git" }
lance-datagen = { "version" = "=11.0.0-beta.6", "rev" = "f8d628fe6af452cc168e0406c1199a91fb059cda", "git" = "https://github.com/lance-format/lance.git" }
lance-file = { "version" = "=11.0.0-beta.6", "rev" = "f8d628fe6af452cc168e0406c1199a91fb059cda", "git" = "https://github.com/lance-format/lance.git" }
lance-io = { "version" = "=11.0.0-beta.6", default-features = false, "rev" = "f8d628fe6af452cc168e0406c1199a91fb059cda", "git" = "https://github.com/lance-format/lance.git" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The pinned f8d628f revision can resurrect stale native-directory authority during registry resolution. A custom file provider can return ObjectStore::local() after replacing its public inner with the actual store; the capability is invalid then, but ObjectStoreRegistry::get_store replaces inner with tracing and metrics and calls rebind_native_directory_path() unconditionally. Recovery consequently trusts the absent host path, bypasses provider-backed target storage, and returns TableNotFound. This regresses the configured-provider authority from the earlier discussion.

Capture capability validity before registry wrappers replace inner; rebind only when it was valid for the provider-returned store, and otherwise clear it.

Reproducer

I added this test after FileSchemeMemoryProvider on the current head:

#[derive(Debug)]
struct ReplacedNativeStoreProvider {
    inner: Arc<dyn object_store::ObjectStore>,
}

#[async_trait::async_trait]
impl lance_io::object_store::ObjectStoreProvider for ReplacedNativeStoreProvider {
    async fn new_store(
        &self,
        _base_path: url::Url,
        _params: &ObjectStoreParams,
    ) -> lance_core::Result<lance_io::object_store::ObjectStore> {
        let mut store = lance_io::object_store::ObjectStore::local();
        store.inner = self.inner.clone();
        Ok(store)
    }
}

#[tokio::test]
async fn test_open_recovery_does_not_resurrect_replaced_native_capability() {
    use object_store::ObjectStoreExt as _;

    let tmp_dir = tempdir().unwrap();
    let dataset_path = tmp_dir.path().join("replaced-native.lance");
    let uri = url::Url::from_file_path(&dataset_path).unwrap().to_string();
    assert!(!dataset_path.exists());

    let inner = Arc::new(object_store::memory::InMemory::new());
    let table_path =
        object_store::path::Path::from_url_path(url::Url::parse(&uri).unwrap().path()).unwrap();
    inner
        .put(
            &table_path.clone().join("_marker"),
            bytes::Bytes::new().into(),
        )
        .await
        .unwrap();

    let registry = Arc::new(lance_io::object_store::ObjectStoreRegistry::default());
    registry.insert(
        "file",
        Arc::new(ReplacedNativeStoreProvider {
            inner: inner.clone(),
        }),
    );
    let read_params = ReadParams {
        session: Some(Arc::new(lance::session::Session::new(0, 0, registry))),
        ..Default::default()
    };

    let err = NativeTable::open_with_params(
        &uri,
        "replaced-native",
        Vec::new(),
        None,
        Some(read_params),
        None,
        None,
        HashSet::new(),
        None,
    )
    .await
    .unwrap_err();

    assert!(
        matches!(&err, Error::TableCorrupted { name, .. } if name == "replaced-native"),
        "the provider effective store contains the table marker, got {err:?}"
    );
}
CARGO_TARGET_DIR=/home/agent/tmp/pr3919-verify-target cargo test --locked --quiet -p lancedb table::tests::test_open_recovery_does_not_resurrect_replaced_native_capability -- --exact --nocapture

Expected TableCorrupted; observed TableNotFound and exit 101 even though the provider contains the exact target marker.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 12, 2026
@BubbleCal BubbleCal changed the title fix: avoid listing siblings when opening missing tables fix: make table existence manifest-authoritative Aug 13, 2026
@BubbleCal BubbleCal added the breaking-change A breaking change in our public APIs label Aug 13, 2026
@BubbleCal
BubbleCal merged commit 1d75638 into main Aug 13, 2026
31 of 32 checks passed
@BubbleCal
BubbleCal deleted the yang/fix-open-table-parent-listing branch August 13, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change A breaking change in our public APIs bug Something isn't working K-changes Latest Gatekeeper recommendation requests changes. Rust Rust related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants