@@ -68,8 +68,8 @@ use ulid::Ulid;
6868use 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) ]
14511457pub 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) ]
14831509pub fn filter_path (
@@ -1605,7 +1631,7 @@ pub fn manifest_segment_matches(manifest_path_str: &str, file_name: &str) -> boo
16051631
16061632#[ cfg( test) ]
16071633mod 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