feat(log-store): list the regions that hold unreleased object store WAL entries (#10687)

* feat(log-store): list the regions that hold unreleased object store WAL entries

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs(log-store): say where the bound of the unreleased regions comes from

The bound is the largest entry id the store has ever indexed: the catalog
keeps it after the object that held it is removed. The test comment now
describes what its assertion shows.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
This commit is contained in:
jeremyhi
2026-11-27 09:11:15 +00:00
committed by GitHub
parent 01523bec3d
commit 34cddcabaa
4 changed files with 128 additions and 15 deletions
-1
View File
@@ -205,7 +205,6 @@ impl Datanode {
/// Returns the object store log store when the datanode runs on the object
/// store WAL.
#[cfg(any(test, feature = "testing"))]
pub fn object_store_log_store(&self) -> Option<Arc<ObjectStoreLogStore>> {
self.object_store_log_store.clone()
}
+4 -1
View File
@@ -76,6 +76,9 @@
//! before sealing may retain extra history. Recovery reads release segments
//! of the chain and seeds the obsolete watermarks from them, so a store
//! opened later collects the objects of a region that is never opened again.
//! [`ObjectStoreLogStore::unreleased_regions`] lists the regions that still
//! hold unreleased entries, so that a caller can release those of regions
//! that no longer need them.
//!
//! Recovery lists the objects, reads and verifies only the header, trailer and
//! footer of each, and indexes the footers of the chain in sequence order to
@@ -111,4 +114,4 @@ mod store;
pub use batch::entry_id;
pub use reader::{NodeWalPrefix, ObjectStoreWalReader, ObjectStoreWalReaders, WalReadUpperBound};
pub use store::{ObjectStoreLogStore, WalHole};
pub use store::{ObjectStoreLogStore, UnreleasedRegions, WalHole};
+13 -8
View File
@@ -260,6 +260,12 @@ impl ObjectCatalog {
self.max_entry_ids.get(&region_id).copied()
}
/// Returns the largest entry id ever indexed for any region, or zero
/// without one.
pub(crate) fn max_entry_id(&self) -> EntryId {
self.max_entry_ids.values().copied().max().unwrap_or(0)
}
/// Returns the sequence to assign to the next object written after recovery.
///
/// An empty catalog starts at zero, so the first object of a prefix always
@@ -277,14 +283,7 @@ impl ObjectCatalog {
.checked_add(1)
.context(WalObjectSequenceExhaustedSnafu { last_object_seq })?,
};
let floor = self
.max_entry_ids
.values()
.copied()
.map(sequence_floor)
.max()
.unwrap_or(0);
let next_object_seq = after_last.max(floor);
let next_object_seq = after_last.max(sequence_floor(self.max_entry_id()));
ensure!(
next_object_seq < OBJECT_SEQ_LIMIT,
WalObjectSequenceExhaustedSnafu {
@@ -312,6 +311,12 @@ impl ObjectCatalog {
.collect()
}
/// Returns the regions with a live segment in any indexed object, see
/// [`is_live`](Self::is_live).
pub(crate) fn live_regions(&self) -> Vec<RegionId> {
self.flush_candidates(0)
}
/// Iterates over the indexed objects ordered by object sequence.
pub(crate) fn objects_in_order(&self) -> impl Iterator<Item = (u64, &[FooterEntry])> + '_ {
self.objects
+111 -5
View File
@@ -199,6 +199,21 @@ pub struct WalHole {
pub max_entry_id: EntryId,
}
/// The regions that hold unreleased entries in a store, listed together with
/// a bound, see [`ObjectStoreLogStore::unreleased_regions`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnreleasedRegions {
/// Regions with an entry above their obsolete watermark in an indexed
/// object.
pub region_ids: Vec<RegionId>,
/// The largest entry id the store has ever indexed, or zero without one.
/// Every entry of a listed region at or below it is durable. Every entry
/// not yet indexed at the listing, and every entry appended later, is
/// above it, so a release through it keeps them, and their region is
/// listed again once they are indexed.
pub entry_id_bound: EntryId,
}
type TerminalError = Arc<Mutex<Option<Arc<Error>>>>;
/// The delete attempts in flight, one per object.
@@ -583,6 +598,28 @@ impl ObjectStoreLogStore {
.unwrap_or_default())
}
/// Lists the regions that hold unreleased entries in this store, from the
/// in-memory catalog without I/O. The listing includes open regions, so
/// the caller releases only the regions that no longer need their
/// entries, through [`UnreleasedRegions::entry_id_bound`] with
/// [`release_entries`](LogStore::release_entries). A release takes effect
/// in memory once admitted and survives a restart once the object carrying
/// its record is durable on the recovered chain. A region whose entries are
/// obsolete only in memory, see [`obsolete`](LogStore::obsolete), is listed
/// again by a store opened later.
pub fn unreleased_regions(&self) -> UnreleasedRegions {
let catalog = self.catalog.read().unwrap_or_else(PoisonError::into_inner);
UnreleasedRegions {
region_ids: catalog.live_regions(),
entry_id_bound: catalog.max_entry_id(),
}
}
/// Returns the provider that selects `region_id` in this store.
pub fn provider(&self, region_id: RegionId) -> Provider {
Provider::object_store_provider(region_id, self.prefix.clone())
}
/// Returns the region of `provider`, which must select this store's prefix.
fn region_of(&self, provider: &Provider) -> Result<RegionId> {
let provider =
@@ -936,10 +973,7 @@ impl LogStore for ObjectStoreLogStore {
actual: options.prefix.clone(),
}
);
Ok(Provider::object_store_provider(
options.region_id,
self.prefix.clone(),
))
Ok(self.provider(options.region_id))
}
fn flush_candidates(&self) -> Vec<RegionId> {
@@ -1123,7 +1157,7 @@ impl LogStore for ObjectStoreLogStore {
.collect::<BTreeSet<_>>();
Ok(regions
.into_iter()
.map(|region_id| Provider::object_store_provider(region_id, self.prefix.clone()))
.map(|region_id| self.provider(region_id))
.collect())
}
@@ -10216,6 +10250,77 @@ mod tests {
}
}
#[tokio::test]
async fn test_unreleased_regions_stay_listed_until_released_through_bound() {
let _serialized = SERIALIZED.lock().await;
for config in [manual(), enqueued(manual())] {
let object_store = memory_store();
let store = open(object_store.clone(), &config).await;
assert_eq!(
UnreleasedRegions {
region_ids: Vec::new(),
entry_id_bound: 0,
},
store.unreleased_regions()
);
let (one, two) = (region(1), region(2));
let first = spawn_append_batch(
&store,
vec![
entry(&store, one, "a"),
entry(&store, two, "b"),
entry(&store, two, "b2"),
],
);
store.wait_for_admitted_appends(1).await.unwrap();
store.seal_open_batch().await.unwrap();
first.await.unwrap().unwrap();
// Region one appends again; its entry stays in the open batch.
let later = spawn_append_batch(&store, vec![entry(&store, one, "c")]);
store.wait_for_admitted_appends(2).await.unwrap();
let listed = store.unreleased_regions();
assert_eq!(
HashSet::from([one, two]),
listed.region_ids.iter().copied().collect::<HashSet<_>>()
);
// The bound is the largest indexed id: the entry in the open batch,
// `id(2, 1)`, is not indexed yet and is above it.
assert_eq!(id(1, 2), listed.entry_id_bound);
// The bound is above the largest entry of region one.
for region_id in listed.region_ids {
store
.release_entries(&store.provider(region_id), region_id, listed.entry_id_bound)
.await
.unwrap();
}
assert_eq!(
UnreleasedRegions {
region_ids: Vec::new(),
entry_id_bound: id(1, 2),
},
store.unreleased_regions()
);
store.seal_open_batch().await.unwrap();
later.await.unwrap().unwrap();
let listed = store.unreleased_regions();
assert_eq!(vec![one], listed.region_ids);
assert_eq!(id(2, 1), listed.entry_id_bound);
assert_eq!(
expected_entries(one, &[(id(2, 1), "c")]),
read_entries(&store, one, 0).await
);
// A region hidden only by an obsolete mark is listed again after a reopen.
store.obsolete(&provider(one), one, id(2, 1)).await.unwrap();
assert!(store.unreleased_regions().region_ids.is_empty());
store.stop().await.unwrap();
let reopened = open(object_store, &config).await;
assert_eq!(vec![one], reopened.unreleased_regions().region_ids);
reopened.stop().await.unwrap();
}
}
#[tokio::test]
async fn test_bounded_release_preserves_entries_not_durable_at_admission() {
let _serialized = SERIALIZED.lock().await;
@@ -10611,6 +10716,7 @@ mod tests {
let store = open(object_store.clone(), &config).await;
assert_eq!(Some(id(3, 1)), watermark(&store, one));
assert!(read_entries(&store, one, 0).await.is_empty());
assert_eq!(vec![pin], store.unreleased_regions().region_ids);
store.obsolete_all(&provider(one), one).await.unwrap();
// A later stale bounded hint must not undo a permanent release.
store