Repository navigation
fix: make table existence manifest-authoritative - #3919
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
❌ 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.
| Ok(entries.iter().any(|entry| entry.as_str() == dir_name)) | ||
|
|
||
| let is_native_local = | ||
| !requires_store_probe && matches!(object_store.scheme(), "file" | "file+uring"); |
There was a problem hiding this comment.
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 reportsfile; this branch then bypasses the provider and returnsTableNotFoundfor storage present incustom_inner; - the default
file-object-storeprovider exposes an empty.lancedirectory totable_names()throughlist_with_delimiter, but the HEAD/recursive-list branch sees no object, soopen_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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Consume the follow-up capability fix so post-open wrappers cannot retain stale native-path authority.
Consume the registry-prefix fix so capability-aware wrappers retain provider-scoped identity.
Carry explicit native-path authority through direct store bindings so empty local table directories remain corrupt instead of missing.
Keep the parent probe only for untyped deprecated direct bindings while provider-resolved and capable stores remain target-bounded.
There was a problem hiding this comment.
❌ 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.
| return Ok(entries.iter().any(|entry| entry.as_str() == dir_name)); | ||
| } | ||
|
|
||
| if let Some(native_path) = object_store.native_directory_path(&path) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Pin the builder ordering fix and cover non-preserving direct wrappers so recovery cannot bypass their probe semantics.
Consume the approved identity binding so replacing an effective store automatically invalidates stale native-path authority.
There was a problem hiding this comment.
❌ 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.
| 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" } |
There was a problem hiding this comment.
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.
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>.lanceentry 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_delimiterexhausts 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:
DatasetNotFoundmaps directly toTableNotFound; no parent or target storage probe runs.Create.Createrequests are arbitrated by the conditional version-1 manifest commit: one succeeds and the loser receivesTableAlreadyExists.table_namesis 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.6dependency frommain; 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
.lancedirectories with marker objects on the local filesystem; fixture creation and teardown are outside the timed region. Baseline isorigin/mainat6fb976cf, candidate ise1240751. Both were built from the same lockfile on the same macOS arm64 machine with the repository'sreleaseprofile (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.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, orlist_with_delimitercalls.Run with:
Correctness and compatibility boundaries
.lancedirectory or orphan data without a committed manifest now opens asTableNotFoundand may be replaced by a successfulCreate.TableAlreadyExists.DatasetNotFoundcorruption, external-manifest, authorization, and object-store errors are not folded intoTableNotFound.TableCorruptedremains in the public error enum for compatibility, but this listing-database fallback no longer synthesizes it from an ambiguous physical footprint.Missing,Creating, andCorruptwould 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 -- --checkcargo check --quiet --locked -p lancedb --features remote --tests --examplescargo clippy --quiet --locked -p lancedb --features remote --tests --examples -- -D warningscargo test --quiet --locked -p lancedb --features remote --tests