Skip to content

Commit 690410a

Browse files
committed
Nest tombstone markers under a per-stream directory so they're discoverable
list_dirs_relative only surfaces child directories on every backend (S3/GCS/Azure via list-with-delimiter's common_prefixes, LocalFS via read_dir + is_dir), never leaf objects. A tombstone stored as a bare key named after the stream was therefore invisible to any future scan that needs to discover tombstoned streams rather than check one known name at a time. Move the marker one level deeper, under a directory named after the stream, and add list_tombstoned_streams for that scan.
1 parent 6443b18 commit 690410a

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

‎src/storage/mod.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ pub const MANIFEST_FILE: &str = "manifest.json";
314314
// stream's own prefix so a bulk prefix-delete can never sweep up a marker
315315
// that's supposed to survive it (see is_tombstoned/tombstone_path)
316316
pub const TOMBSTONE_ROOT_DIRECTORY: &str = ".tombstones";
317+
// the marker itself lives one level below `{tenant}/{stream_name}/`, not as
318+
// a leaf key directly named after the stream: list_dirs_relative on every
319+
// backend (S3/GCS/Azure via list-with-delimiter's common_prefixes, LocalFS
320+
// via read_dir + is_dir) only surfaces child *directories*, never leaf
321+
// objects, so a tombstone recorded as a bare `{stream_name}` key would be
322+
// invisible to the restart-recovery scan that discovers tombstoned streams
323+
pub const TOMBSTONE_MARKER_FILE_NAME: &str = ".tombstone";
317324

318325
// max concurrent request allowed for datafusion object store, overridable per
319326
// backend with P_MAX_OBJECT_STORE_REQUESTS.

‎src/storage/object_storage.rs‎

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ use ulid::Ulid;
6868
use super::{
6969
ALERTS_ROOT_DIRECTORY, MANIFEST_FILE, ObjectStorageError, ObjectStoreFormat,
7070
PARSEABLE_METADATA_FILE_NAME, PARSEABLE_ROOT_DIRECTORY, SCHEMA_FILE_NAME,
71-
STREAM_METADATA_FILE_NAME, STREAM_ROOT_DIRECTORY, TOMBSTONE_ROOT_DIRECTORY,
72-
retention::Retention,
71+
STREAM_METADATA_FILE_NAME, STREAM_ROOT_DIRECTORY, TOMBSTONE_MARKER_FILE_NAME,
72+
TOMBSTONE_ROOT_DIRECTORY, retention::Retention,
7373
};
7474

7575
/// Context for upload operations containing stream information
@@ -1447,10 +1447,21 @@ pub fn stream_json_path(stream_name: &str, tenant_id: &Option<String>) -> Relati
14471447
/// `TOMBSTONE_ROOT_DIRECTORY`, outside the `{tenant}/{stream_name}` prefix
14481448
/// that a bulk stream delete walks, so a mid-deletion crash can never lose
14491449
/// the marker before the deletion it records has actually finished.
1450+
///
1451+
/// The marker is nested one level under `{stream_name}/`, not stored as a
1452+
/// bare key named after the stream: `list_dirs_relative` (used to discover
1453+
/// tombstoned streams on restart) only surfaces child directories on every
1454+
/// backend, so `{stream_name}` must itself resolve to a directory for that
1455+
/// scan to find it.
14501456
#[inline(always)]
14511457
pub fn tombstone_path(stream_name: &str, tenant_id: &Option<String>) -> RelativePathBuf {
14521458
let tenant = tenant_id.as_deref().unwrap_or("");
1453-
RelativePathBuf::from_iter([TOMBSTONE_ROOT_DIRECTORY, tenant, stream_name])
1459+
RelativePathBuf::from_iter([
1460+
TOMBSTONE_ROOT_DIRECTORY,
1461+
tenant,
1462+
stream_name,
1463+
TOMBSTONE_MARKER_FILE_NAME,
1464+
])
14541465
}
14551466

14561467
/// Whether a stream has a deletion marker present, i.e. a deletion was
@@ -1478,6 +1489,21 @@ pub async fn is_tombstoned(
14781489
}
14791490
}
14801491

1492+
/// Stream names with a deletion marker for the given tenant, discovered by
1493+
/// listing `TOMBSTONE_ROOT_DIRECTORY` rather than checking one name at a
1494+
/// time. Used to resume deletions left unfinished by a crashed or restarted
1495+
/// node, since a tombstoned stream whose `.stream.json` is already gone
1496+
/// would otherwise never surface via `list_streams`. See `is_tombstoned` for
1497+
/// the equivalent single-name check.
1498+
pub async fn list_tombstoned_streams(
1499+
storage: &(impl ObjectStorage + ?Sized),
1500+
tenant_id: &Option<String>,
1501+
) -> Result<Vec<String>, ObjectStorageError> {
1502+
let tenant = tenant_id.as_deref().unwrap_or("");
1503+
let root = RelativePathBuf::from_iter([TOMBSTONE_ROOT_DIRECTORY, tenant]);
1504+
storage.list_dirs_relative(&root, tenant_id).await
1505+
}
1506+
14811507
/// if filter_id is an empty str it should not append it to the rel path
14821508
#[inline(always)]
14831509
pub fn filter_path(
@@ -1605,7 +1631,7 @@ pub fn manifest_segment_matches(manifest_path_str: &str, file_name: &str) -> boo
16051631

16061632
#[cfg(test)]
16071633
mod tombstone_tests {
1608-
use super::{ObjectStorage, is_tombstoned, to_bytes, tombstone_path};
1634+
use super::{ObjectStorage, is_tombstoned, list_tombstoned_streams, to_bytes, tombstone_path};
16091635
use crate::storage::LocalFS;
16101636
use temp_dir::TempDir;
16111637

@@ -1629,6 +1655,33 @@ mod tombstone_tests {
16291655

16301656
assert!(is_tombstoned(&storage, "test_stream", &None).await.unwrap());
16311657
}
1658+
1659+
#[tokio::test]
1660+
async fn no_markers_means_empty_discovery_list() {
1661+
let dir = TempDir::new().unwrap();
1662+
let storage = LocalFS::new(dir.path().to_path_buf());
1663+
1664+
assert!(
1665+
list_tombstoned_streams(&storage, &None)
1666+
.await
1667+
.unwrap()
1668+
.is_empty()
1669+
);
1670+
}
1671+
1672+
#[tokio::test]
1673+
async fn marker_present_means_discoverable_by_listing() {
1674+
let dir = TempDir::new().unwrap();
1675+
let storage = LocalFS::new(dir.path().to_path_buf());
1676+
1677+
storage
1678+
.put_object(&tombstone_path("test_stream", &None), to_bytes(&()), &None)
1679+
.await
1680+
.unwrap();
1681+
1682+
let discovered = list_tombstoned_streams(&storage, &None).await.unwrap();
1683+
assert_eq!(discovered, vec!["test_stream".to_string()]);
1684+
}
16321685
}
16331686

16341687
#[cfg(test)]

0 commit comments

Comments
 (0)