This is an automated email from the ASF dual-hosted git repository.
yihua pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hudi-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 9d1d093c perf(core): reuse the plan's metadata snapshot for record
index lookups (#1096)
9d1d093c is described below
commit 9d1d093cf7616373fbc09deed763e725cc83d1b4
Author: Y Ethan Guo <[email protected]>
AuthorDate: Sat Dec 5 11:32:17 2026 -0800
perf(core): reuse the plan's metadata snapshot for record index lookups
(#1096)
* perf(core): walk base hfile blocks for record index lookups
A record index lookup against a compacted base HFile copied every entry of
each selected block into an owned record, then dropped the ones it did not
ask for. Compaction writes 1 MiB blocks, so a lookup of a few keys per block
allocated and copied thousands of entries for each key it kept.
Base lookups now walk the selected blocks' entries in place and copy out
only
the admitted ones, as the log-block path already does
(`HFileReader::read_admitted_records_batched`, sharing the walk with
`records_in_block`). Block selection, fetches, decompression and the Avro
decode of matched values are unchanged, so results are identical; a key that
is not UTF-8 is now skipped by the walk rather than rejected by the fold,
the
same as on the log path.
* perf(core): reuse the plan's metadata snapshot for record index lookups
A key lookup on the read path fenced record index log blocks with a
valid-instant set rebuilt from the timelines in storage, listing the data
timeline twice and the metadata timeline once, one after another, after the
plan had already built that set for the same snapshot. The plan now passes
its metadata snapshot's set to the lookup, which narrows it to the snapshot
as before; the write path's lookups still read the timelines in storage.
The lookup also opens each touched shard's base file at the size the
partition listing reported, so a base small enough to read whole needs no
size lookup first. A base read in ranges still asks storage for its length
when it opens.
* Cover a non-commit action pending at open in the lookup instant test
* test(core): pin that a duplicated key straddles blocks in the admitted
read test
* docs(core): note the snapshot branch keeps the admitted filter as a guard
---
crates/core/src/index/record.rs | 279 +++++++++++++++++++++++++++++++---
crates/core/src/metadata/table/mod.rs | 4 +-
crates/core/src/table/mod.rs | 101 +++++++++++-
crates/core/src/write/metadata.rs | 49 +++++-
4 files changed, 396 insertions(+), 37 deletions(-)
diff --git a/crates/core/src/index/record.rs b/crates/core/src/index/record.rs
index 90fa4364..d9dde674 100644
--- a/crates/core/src/index/record.rs
+++ b/crates/core/src/index/record.rs
@@ -39,8 +39,8 @@ use crate::timeline::selector::InstantRange;
use crate::util::concurrency::bounded_in_order;
use crate::write::metadata::{
DEFAULT_RLI_NUM_FILE_GROUPS, RECORD_INDEX_FILE_ID_PREFIX,
epoch_millis_to_instant_in,
- map_record_key_to_file_group_index, mdt_partition_latest_slices,
record_index_file_id,
- shard_count_from_slices, timeline_timezone,
+ map_record_key_to_file_group_index, mdt_partition_latest_slices_with_sizes,
+ record_index_file_id, shard_count_from_slices, timeline_timezone,
};
/// Metadata-table record-level index (global: key = record key).
@@ -97,27 +97,37 @@ async fn lookup_record_index(
storage: Arc<Storage>,
record_keys: &[&str],
) -> Result<HashMap<String, LoadedLocation>> {
- Ok(lookup_as_of(table, storage, record_keys, None)
+ Ok(lookup_as_of(table, storage, record_keys, None, None)
.await?
.unwrap_or_default())
}
/// The file groups holding `record_keys` in the snapshot whose latest commit
/// is `as_of`, or `None` when the index cannot answer for that snapshot.
+///
+/// `snapshot_valid_instants` is the valid-instant set a plan of the snapshot
+/// already built; see [`lookup_as_of`].
pub(crate) async fn locate_file_groups(
table: &Table,
record_keys: &[&str],
as_of: &str,
+ snapshot_valid_instants: Option<&HashSet<String>>,
) -> Result<Option<HashSet<(String, String)>>> {
let storage = table.file_system_view.storage.clone();
- Ok(lookup_as_of(table, storage, record_keys, Some(as_of))
- .await?
- .map(|found| {
- found
- .into_values()
- .map(|location| (location.partition_path, location.file_id))
- .collect()
- }))
+ Ok(lookup_as_of(
+ table,
+ storage,
+ record_keys,
+ Some(as_of),
+ snapshot_valid_instants,
+ )
+ .await?
+ .map(|found| {
+ found
+ .into_values()
+ .map(|location| (location.partition_path, location.file_id))
+ .collect()
+ }))
}
/// Locations of `record_keys`, read from only the index shards and HFile
@@ -128,17 +138,23 @@ pub(crate) async fn locate_file_groups(
/// placed them, so a lookup opens the touched shards rather than the whole
/// partition, and inside a shard the HFile block index narrows the read to the
/// blocks the keys fall in. Values are Avro-decoded only for the requested
keys.
+///
+/// `snapshot_valid_instants`, the set [`Table::valid_instant_timestamps`]
built
+/// for this handle's snapshot, saves reading the timelines again to fence log
+/// blocks; without it the set comes from the timelines in storage now.
async fn lookup_as_of(
table: &Table,
storage: Arc<Storage>,
record_keys: &[&str],
as_of: Option<&str>,
+ snapshot_valid_instants: Option<&HashSet<String>>,
) -> Result<Option<HashMap<String, LoadedLocation>>> {
let partition = MetadataPartitionType::RecordIndex.partition_name();
// Slice-resolved: only each file group's LIVE slice (multi-base aware
// after a Spark MDT compaction), logs in version order. One listing serves
// both the shard modulus and the routing, so the two cannot disagree.
- let slices = mdt_partition_latest_slices(storage.as_ref(),
partition).await?;
+ let (slices, file_sizes) =
+ mdt_partition_latest_slices_with_sizes(storage.as_ref(),
partition).await?;
if let Some(as_of) = as_of {
// An empty partition answers every key with "absent", and a base file
// compacted after the snapshot may hold later commits' changes, which
@@ -190,14 +206,7 @@ async fn lookup_as_of(
// Only trust log blocks whose instant completed on the data timeline
// (Java getValidInstantTimestamps): orphan MDT commits are skipped.
let range = if touched.iter().any(|(_, _, logs)| !logs.is_empty()) {
- let mut valid = table.valid_metadata_instants().await?;
- if let Some(as_of) = as_of {
- // The snapshot holds the commits that had completed by `as_of`
when
- // the table was opened; one pending then may have completed since.
- valid.retain(|instant| {
- instant.as_str() <= as_of &&
!table.timeline.pending_instants.contains(instant)
- });
- }
+ let valid = log_block_instants(table, as_of,
snapshot_valid_instants).await?;
Some(InstantRange::exact_match(valid, "UTC"))
} else {
None
@@ -214,17 +223,23 @@ async fn lookup_as_of(
.get_or_default(HudiReadConfig::FileSliceReadConcurrency)
.into();
let range = range.as_ref();
+ let file_sizes = &file_sizes;
let per_shard = bounded_in_order(&touched, concurrency, |(predicate, base,
logs)| {
let storage = storage.clone();
async move {
let matcher = predicate.matcher();
let mut merged: HashMap<String, LoadedLocation> = HashMap::new();
if let Some(base) = base {
- let reader = HFileReader::open_sized(storage.as_ref(), base,
whole_below, None)
- .await
- .map_err(|e| {
- CoreError::HFile(format!("failed to open record_index
base: {e:?}"))
- })?;
+ let reader = HFileReader::open_sized(
+ storage.as_ref(),
+ base,
+ whole_below,
+ file_sizes.get(base).copied(),
+ )
+ .await
+ .map_err(|e| {
+ CoreError::HFile(format!("failed to open record_index
base: {e:?}"))
+ })?;
let blocks = reader.blocks_for_predicate(predicate);
// A scattered batch can select most blocks of a large shard,
so
// they are fetched a window at a time. A resident file is
under
@@ -262,6 +277,32 @@ async fn lookup_as_of(
Ok(Some(per_shard.into_iter().flatten().collect()))
}
+/// The instants whose record index log blocks a lookup reads.
+async fn log_block_instants(
+ table: &Table,
+ as_of: Option<&str>,
+ snapshot_valid_instants: Option<&HashSet<String>>,
+) -> Result<HashSet<String>> {
+ // The snapshot holds the commits that had completed by `as_of` when the
+ // table was opened; one pending then may have completed since.
+ let admitted = |instant: &String| {
+ as_of.is_none_or(|as_of| {
+ instant.as_str() <= as_of &&
!table.timeline.pending_instants.contains(instant)
+ })
+ };
+ Ok(match snapshot_valid_instants {
+ // The snapshot already leaves out what was pending at open, and past
+ // `as_of` it holds only non-commit actions, which write no record
index
+ // entries, so `admitted` changes no result here; it stays as a guard.
+ Some(valid) => valid.iter().filter(|i| admitted(i)).cloned().collect(),
+ None => {
+ let mut valid = table.valid_metadata_instants().await?;
+ valid.retain(admitted);
+ valid
+ }
+ })
+}
+
/// Fold `records` into `merged`, later records overriding earlier ones and a
/// tombstone removing the key.
///
@@ -702,4 +743,192 @@ mod tests {
assert!(!found.contains_key("key-0350"));
}
}
+
+ /// A key lookup fences log blocks with the valid-instant set the plan
built
+ /// for the snapshot, and saves the three timeline listings the set read
+ /// from the timelines in storage takes. With a rolled-back write, a
pending
+ /// instant, and a commit pending at open that completes, with its metadata
+ /// commit, before the lookup, the two sets admit the same instants. They
+ /// differ on a clean pending at open that completes the same way: only the
+ /// set from storage admits it, since the lookup's own pending-at-open
+ /// filter covers commit actions only.
+ /// A small base is opened at its listed size, without a size lookup.
+ #[tokio::test]
+ async fn test_locate_file_groups_with_snapshot_valid_instants_lists_less()
{
+ use crate::storage::recording::{RequestKind, record_storage_requests};
+ use arrow_array::{Int64Array, RecordBatch, StringArray};
+ use arrow_schema::{DataType, Field, Schema};
+
+ let recording =
record_storage_requests(std::time::Duration::from_millis(1), false);
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().to_str().unwrap();
+ let mut writer = Table::create(path)
+ .with_table_name("t")
+ .with_record_key_fields(["id"])
+ .create()
+ .await
+ .unwrap();
+ let batch = |ids: &[&str]| {
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("id", DataType::Utf8, false),
+ Field::new("value", DataType::Int64, false),
+ ]));
+ RecordBatch::try_new(
+ schema,
+ vec![
+ Arc::new(StringArray::from(ids.to_vec())),
+ Arc::new(Int64Array::from(vec![1; ids.len()])),
+ ],
+ )
+ .unwrap()
+ };
+ let storage = writer.file_system_view.storage.clone();
+ let put_timeline_file = |name: String| {
+ let storage = storage.clone();
+ async move {
+ storage
+ .put_file(&format!(".hoodie/timeline/{name}"),
Vec::<u8>::new())
+ .await
+ .unwrap();
+ }
+ };
+ writer.append([batch(&["a", "b"])]).await.unwrap();
+ // A crashed write, which the next write rolls back.
+ let crashed = crate::write::append::generate_instant_time().await;
+ put_timeline_file(format!("{crashed}.commit.requested")).await;
+ put_timeline_file(format!("{crashed}.inflight")).await;
+ let completes_later =
crate::write::append::generate_instant_time().await;
+ let clean_completes_later =
crate::write::append::generate_instant_time().await;
+ writer.append([batch(&["c"])]).await.unwrap();
+ // Actions in flight when the reader opens, all but one below the
latest
+ // commit.
+ let pending = crate::write::append::generate_instant_time().await;
+ for instant in [&pending, &completes_later] {
+ put_timeline_file(format!("{instant}.commit.requested")).await;
+ put_timeline_file(format!("{instant}.inflight")).await;
+ }
+
put_timeline_file(format!("{clean_completes_later}.clean.requested")).await;
+
put_timeline_file(format!("{clean_completes_later}.clean.inflight")).await;
+
+ // The metadata commits of `completes_later` and
`clean_completes_later`
+ // land while they are pending; the instants themselves complete after
+ // the snapshot set is built and before the lookup reads the timelines.
+ let partition = writer
+ .get_file_slices(&crate::config::read_options::ReadOptions::new())
+ .await
+ .unwrap()[0]
+ .partition_path
+ .clone();
+ for instant in [&completes_later, &clean_completes_later] {
+ let stats = crate::write::metadata::update_files_partition_entries(
+ storage.as_ref(),
+ instant,
+ &[(
+ partition.clone(),
+ format!("unseen-{instant}_0-0-0_0.parquet"),
+ 1,
+ false,
+ )],
+
crate::write::metadata::metadata_hfile_codec_for(&writer).unwrap(),
+ )
+ .await
+ .unwrap();
+ crate::write::metadata::write_metadata_commit(
+ storage.as_ref(),
+ instant,
+ HashMap::from([("files".to_string(), stats)]),
+ )
+ .await
+ .unwrap();
+ }
+ let handle = Table::new(path).await.unwrap();
+ assert_eq!(handle.timeline.listed.rollbacks_and_restores.len(), 1);
+ assert!(handle.timeline.listed.pending.contains(&pending));
+ let as_of = handle
+ .timeline
+ .get_latest_commit_timestamp_as_option()
+ .unwrap()
+ .to_string();
+ assert!(completes_later < as_of && clean_completes_later < as_of);
+ let mdt = handle.metadata_table_now().await.unwrap();
+ let snapshot = handle.valid_instant_timestamps(&mdt).await.unwrap();
+ let completion = crate::write::append::generate_instant_time().await;
+
put_timeline_file(format!("{completes_later}_{completion}.commit")).await;
+
put_timeline_file(format!("{clean_completes_later}_{completion}.clean")).await;
+ let from_storage = log_block_instants(&handle, Some(&as_of), None)
+ .await
+ .unwrap();
+ let from_snapshot = log_block_instants(&handle, Some(&as_of),
Some(&snapshot))
+ .await
+ .unwrap();
+ // The metadata commits are there for the timelines in storage to
admit,
+ // so only the pending-at-open filters keep them out.
+ let latest = handle.valid_metadata_instants().await.unwrap();
+ assert!(latest.contains(&completes_later) &&
latest.contains(&clean_completes_later));
+ // The one difference: the snapshot set leaves out the clean pending at
+ // open, and the lookup's filter, over commit actions, does not.
+ assert!(from_storage.contains(&clean_completes_later));
+ assert!(!from_snapshot.contains(&clean_completes_later));
+ let mut from_storage_but_clean = from_storage.clone();
+ from_storage_but_clean.remove(&clean_completes_later);
+ assert_eq!(from_snapshot, from_storage_but_clean);
+ assert!(from_snapshot.contains(&crashed) &&
from_snapshot.contains(&as_of));
+ assert!(!from_snapshot.contains(&pending) &&
!from_snapshot.contains(&completes_later));
+
+ async fn with_requests<T>(
+ recording: &crate::storage::recording::RecordingGuard,
+ call: impl std::future::Future<Output = T>,
+ ) -> (T, Vec<crate::storage::recording::Request>) {
+ let start = std::time::Instant::now();
+ let out = call.await;
+ let requests = recording
+ .log
+ .requests()
+ .into_iter()
+ .filter(|r| r.start >= start)
+ .collect();
+ (out, requests)
+ }
+ let lookup = |valid| locate_file_groups(&handle, &["a", "c"], &as_of,
valid);
+ let (from_storage_located, from_storage_requests) =
+ with_requests(&recording, lookup(None)).await;
+ let (snapshot_located, snapshot_requests) =
+ with_requests(&recording, lookup(Some(&snapshot))).await;
+ let (from_storage_located, snapshot_located) =
+ (from_storage_located.unwrap(), snapshot_located.unwrap());
+ assert_eq!(snapshot_located, from_storage_located);
+ assert!(snapshot_located.is_some_and(|groups| !groups.is_empty()));
+ let lists = |requests: &[crate::storage::recording::Request]| {
+ requests
+ .iter()
+ .filter(|r| r.kind == RequestKind::List)
+ .count()
+ };
+ assert_eq!(
+ lists(&from_storage_requests),
+ lists(&snapshot_requests) + 3,
+ "{from_storage_requests:?}\n{snapshot_requests:?}"
+ );
+ // Each touched shard's base is a small bootstrap file, read whole in
+ // one request.
+ let base_gets = snapshot_requests
+ .iter()
+ .filter(|r| r.kind == RequestKind::Get &&
r.path.ends_with(".hfile"))
+ .count();
+ let shards = snapshot_requests
+ .iter()
+ .filter(|r| r.path.ends_with(".hfile"))
+ .map(|r| {
+ r.path
+ .rsplit('/')
+ .next()
+ .unwrap()
+ .split('_')
+ .next()
+ .unwrap()
+ })
+ .collect::<HashSet<_>>()
+ .len();
+ assert_eq!(base_gets, shards, "{snapshot_requests:?}");
+ }
}
diff --git a/crates/core/src/metadata/table/mod.rs
b/crates/core/src/metadata/table/mod.rs
index 4169ba5d..8aff6239 100644
--- a/crates/core/src/metadata/table/mod.rs
+++ b/crates/core/src/metadata/table/mod.rs
@@ -546,8 +546,8 @@ const ROLLBACK_READ_CONCURRENCY: usize = 8;
impl Table {
/// The valid-instant set as of the data timeline in storage now rather
than
- /// as of this handle's snapshot, for a write and for the record index,
which
- /// fences its own reads to a snapshot.
+ /// as of this handle's snapshot, for a write, and for a record index
lookup
+ /// without a plan snapshot, which narrows it to the snapshot itself.
pub(crate) async fn valid_metadata_instants(&self) ->
Result<HashSet<String>> {
let mdt = self.get_or_init_metadata_table().await?;
self.latest_valid_instant_timestamps(mdt).await
diff --git a/crates/core/src/table/mod.rs b/crates/core/src/table/mod.rs
index e767abca..c5db302a 100644
--- a/crates/core/src/table/mod.rs
+++ b/crates/core/src/table/mod.rs
@@ -1230,7 +1230,14 @@ impl Table {
if key_lookup == KeyLookup::UseIndex
&& !read_optimized
&& let Some(located) = self
- .file_groups_for_record_keys(filters, timestamp, &table_schema)
+ .file_groups_for_record_keys(
+ filters,
+ timestamp,
+ &table_schema,
+ metadata
+ .as_ref()
+ .map(|(snapshot, _)| &snapshot.valid_instants),
+ )
.await
{
let planned: HashSet<(&str, &str)> = file_slices
@@ -1267,12 +1274,14 @@ impl Table {
/// of the latest commit on table version 8 or later, whose metadata table
/// this reader can list. Anything the lookup cannot handle, including an
/// error, leaves the full scan in place; the row-level mask still applies
- /// the filter to whatever is read.
+ /// the filter to whatever is read. `valid_instants` is the plan's
+ /// metadata snapshot's, when it read the metadata table.
async fn file_groups_for_record_keys(
&self,
filters: &[Filter],
timestamp: &str,
table_schema: &Schema,
+ valid_instants: Option<&HashSet<String>>,
) -> Option<HashSet<(String, String)>> {
use crate::expr::ExprOperator;
use crate::index::is_record_index_enabled;
@@ -1354,7 +1363,7 @@ impl Table {
}
let keys = keys?;
let keys: Vec<&str> = keys.iter().map(String::as_str).collect();
- match crate::index::locate_file_groups(self, &keys, timestamp).await {
+ match crate::index::locate_file_groups(self, &keys, timestamp,
valid_instants).await {
Ok(located) => located,
Err(e) => {
log::warn!("record index lookup failed, reading every file
slice: {e}");
@@ -5976,4 +5985,90 @@ mod tests {
assert!(failed.is_err());
Ok(())
}
+
+ /// A read filtered on a record key fences its record index lookup with the
+ /// plan's snapshot valid-instant set: after the plan, the lookup lists the
+ /// `record_index` partition and the metadata timeline its bases are fenced
+ /// by, and no data timeline. The read returns the key's row.
+ #[tokio::test]
+ async fn
a_key_read_looks_up_the_record_index_without_listing_the_data_timeline() ->
Result<()>
+ {
+ use crate::storage::recording::{RequestKind, record_storage_requests};
+ use arrow_array::{Int64Array, RecordBatch, StringArray};
+ use arrow_schema::{DataType, Field, Schema};
+
+ let recording =
record_storage_requests(std::time::Duration::from_millis(1), false);
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().to_str().unwrap();
+ let mut table = Table::create(path)
+ .with_table_name("t")
+ .with_record_key_fields(["id"])
+ .with_option("hoodie.parquet.small.file.limit", "0")
+ .create()
+ .await?;
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("id", DataType::Utf8, false),
+ Field::new("value", DataType::Int64, false),
+ ]));
+ for group in 0..3 {
+ let batch = RecordBatch::try_new(
+ schema.clone(),
+ vec![
+ Arc::new(StringArray::from(
+ (0..10)
+ .map(|i| format!("k{:02}", group + 3 * i))
+ .collect::<Vec<_>>(),
+ )),
+ Arc::new(Int64Array::from_iter_values(0..10)),
+ ],
+ )
+ .unwrap();
+ table.append([batch]).await?;
+ }
+
+ let handle = Table::new(path).await?;
+ let start = std::time::Instant::now();
+ let batches = handle
+ .read(&ReadOptions::new().with_filters([("id", "=", "k04")])?)
+ .await?;
+ let ids: Vec<String> = batches
+ .iter()
+ .flat_map(|b| {
+ b.column_by_name("id")
+ .unwrap()
+ .as_any()
+ .downcast_ref::<StringArray>()
+ .unwrap()
+ .iter()
+ .map(|v| v.unwrap().to_string())
+ .collect::<Vec<_>>()
+ })
+ .collect();
+ assert_eq!(ids, ["k04"]);
+
+ let lists: Vec<_> = recording
+ .log
+ .requests()
+ .into_iter()
+ .filter(|r| r.kind == RequestKind::List && r.start >= start)
+ .collect();
+ let lookup_start = lists
+ .iter()
+ .filter(|r| r.path.ends_with(".hoodie/metadata/record_index"))
+ .map(|r| r.start)
+ .min()
+ .expect("the read looks up the record index");
+ let lookup_lists: Vec<&str> = lists
+ .iter()
+ .filter(|r| r.start >= lookup_start)
+ .map(|r| r.path.as_str())
+ .collect();
+ assert_eq!(lookup_lists.len(), 2, "{lookup_lists:?}");
+ assert!(
+ lookup_lists.iter().all(|p| !p.ends_with(".hoodie/timeline")
+ || p.ends_with(".hoodie/metadata/.hoodie/timeline")),
+ "{lookup_lists:?}"
+ );
+ Ok(())
+ }
}
diff --git a/crates/core/src/write/metadata.rs
b/crates/core/src/write/metadata.rs
index a6da6c7b..0fdbaad0 100644
--- a/crates/core/src/write/metadata.rs
+++ b/crates/core/src/write/metadata.rs
@@ -1332,6 +1332,43 @@ pub(crate) async fn mdt_partition_latest_slices(
mdt_partition_latest_slices_fenced(storage, partition, None, None).await
}
+/// [`mdt_partition_latest_slices`] with the listed size of every file in the
+/// partition, keyed by the relative path the slices name it by, so a caller
+/// opening a base file can skip asking storage for its size.
+pub(crate) async fn mdt_partition_latest_slices_with_sizes(
+ storage: &Storage,
+ partition: &str,
+) -> Result<(
+ Vec<(String, Option<String>, Vec<String>)>,
+ HashMap<String, u64>,
+)> {
+ let dir = format!("{METADATA_BASE}/{partition}");
+ let Some(listed) = list_mdt_partition(storage, &dir).await? else {
+ return Ok((Vec::new(), HashMap::new()));
+ };
+ let sizes = listed
+ .iter()
+ .map(|file| (format!("{dir}/{}", file.name), file.size))
+ .collect();
+ let slices = mdt_partition_latest_slices_fenced(storage, partition, None,
Some(listed)).await?;
+ Ok((slices, sizes))
+}
+
+/// The files of the metadata partition at `dir`, or `None` when it does not
+/// exist.
+async fn list_mdt_partition(
+ storage: &Storage,
+ dir: &str,
+) -> Result<Option<Vec<crate::storage::file_metadata::FileMetadata>>> {
+ match storage.list_files(Some(dir)).await {
+ Ok(files) => Ok(Some(files)),
+ Err(crate::storage::error::StorageError::ObjectStoreError(
+ object_store::Error::NotFound { .. },
+ )) => Ok(None),
+ Err(error) => Err(error.into()),
+ }
+}
+
/// MDT instants a base HFile may be admitted on: completed on the active MDT
/// timeline, or below its earliest instant, which archival only moves past
/// completed ones.
@@ -1413,19 +1450,17 @@ async fn mdt_partition_latest_slices_fenced(
let dir = format!("{METADATA_BASE}/{partition}");
let listed = match listed {
Some(files) => files,
- None => match storage.list_files(Some(&dir)).await {
- Ok(files) => files,
- Err(crate::storage::error::StorageError::ObjectStoreError(
- object_store::Error::NotFound { .. },
- )) => return Ok(Vec::new()),
- Err(error) => return Err(error.into()),
+ None => match list_mdt_partition(storage, &dir).await? {
+ Some(files) => files,
+ None => return Ok(Vec::new()),
},
};
// Admit only bases whose instant is committed on the MDT timeline: a crash
// between writing a compaction HFile and completing its .commit must not
// let the orphan base shadow the committed slice (and silently drop the
// still-live pre-compaction logs). Log blocks are fenced separately by the
- // callers via valid_metadata_instants.
+ // callers: on the read path with the plan's snapshot valid-instant set, on
+ // the write path via valid_metadata_instants.
let committed = match mdt_timeline {
Some(mdt_timeline) =>
CommittedMdtInstants::from_timeline(mdt_timeline),
None => CommittedMdtInstants::list(storage).await?,