-
Notifications
You must be signed in to change notification settings - Fork 766
fix: make FTS metadata loading retry-safe #7838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1314,24 +1314,21 @@ impl DatasetIndexExt for Dataset { | |
| async fn load_indices(&self) -> Result<Arc<Vec<IndexMetadata>>> { | ||
| let metadata_key = IndexMetadataKey { | ||
| version: self.version().version, | ||
| store_identity: &self.object_store.store_prefix, | ||
| }; | ||
| let mut indices = match self.index_cache.get_with_key(&metadata_key).await { | ||
| Some(indices) => indices, | ||
| None => { | ||
| let mut indices = self | ||
| .index_cache | ||
| .get_or_insert_with_key(metadata_key, || async { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| let mut loaded_indices = read_manifest_indexes( | ||
| &self.object_store, | ||
| &self.manifest_location, | ||
| &self.manifest, | ||
| ) | ||
| .await?; | ||
| retain_supported_indices(&mut loaded_indices); | ||
| let loaded_indices = Arc::new(loaded_indices); | ||
| self.index_cache | ||
| .insert_with_key(&metadata_key, loaded_indices.clone()) | ||
| .await; | ||
| loaded_indices | ||
| } | ||
| }; | ||
| Ok(loaded_indices) | ||
| }) | ||
| .await?; | ||
|
|
||
| // Infer details for legacy vector indices (once per index name, concurrently). | ||
| // This may run on indices that were opportunistically cached during Dataset::open | ||
|
|
@@ -4350,6 +4347,48 @@ mod tests { | |
| assert_eq!(indices2.len(), 1); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_load_indices_singleflights_concurrent_cache_misses() { | ||
| let session = Arc::new(Session::default()); | ||
| let write_params = WriteParams { | ||
| session: Some(session.clone()), | ||
| ..Default::default() | ||
| }; | ||
| let test_dir = TempStrDir::default(); | ||
| let schema = Arc::new(Schema::new(vec![Field::new("tag", DataType::Utf8, false)])); | ||
| let batch = RecordBatch::try_new( | ||
| schema.clone(), | ||
| vec![Arc::new(StringArray::from(vec!["a", "b", "c"]))], | ||
| ) | ||
| .unwrap(); | ||
| let mut dataset = Dataset::write( | ||
| RecordBatchIterator::new(vec![Ok(batch)], schema), | ||
| &test_dir, | ||
| Some(write_params), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| dataset | ||
| .create_index( | ||
| &["tag"], | ||
| IndexType::Bitmap, | ||
| None, | ||
| &ScalarIndexParams::default(), | ||
| false, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| session.index_cache.clear().await; | ||
| let before = session.index_cache_stats().await; | ||
| let results = futures::future::join_all((0..32).map(|_| dataset.load_indices())).await; | ||
| assert!(results.iter().all(|result| result.is_ok())); | ||
| let after = session.index_cache_stats().await; | ||
|
|
||
| assert_eq!(after.misses - before.misses, 1); | ||
| assert_eq!(after.hits - before.hits, 31); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_remap_empty() { | ||
| let data = gen_batch() | ||
|
|
@@ -4736,6 +4775,7 @@ mod tests { | |
| // We commit by doing a delete("false") after replacing the cached indices. | ||
| let metadata_key = crate::session::index_caches::IndexMetadataKey { | ||
| version: dataset.version().version, | ||
| store_identity: &dataset.object_store.store_prefix, | ||
| }; | ||
| dataset | ||
| .index_cache | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy FTS indexes can still fail to open on S3 readers that have
s3:GetObjectbut nots3:ListBucket. These indexes do not containmetadata.lance, and S3 returns 403 rather than 404 for a missing object whenListBucketis unavailable, sois_not_found()is false even thoughtokens.lanceis readable. Could we probe the legacy tokens file when opening metadata fails, use the fallback only if that succeeds, and otherwise preserve the original metadata error? https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadObject.html