@@ -1612,13 +1612,27 @@ pub async fn is_tombstoned(
16121612/// node, since a tombstoned stream whose `.stream.json` is already gone
16131613/// would otherwise never surface via `list_streams`. See `is_tombstoned` for
16141614/// the equivalent single-name check.
1615+ ///
1616+ /// `list_dirs_relative` only proves a directory exists under the tombstone
1617+ /// root, not that it actually holds a `.tombstone` marker (e.g. a partial or
1618+ /// interrupted write could leave an empty one behind) -- each candidate is
1619+ /// re-checked with `is_tombstoned` before being returned, so a directory
1620+ /// without a real marker is silently skipped rather than misreported.
16151621pub async fn list_tombstoned_streams(
16161622 storage: &(impl ObjectStorage + ?Sized),
16171623 tenant_id: &Option<String>,
16181624) -> Result<Vec<String>, ObjectStorageError> {
16191625 let tenant = tenant_id.as_deref().unwrap_or("");
16201626 let root = RelativePathBuf::from_iter([TOMBSTONE_ROOT_DIRECTORY, tenant]);
1621- storage.list_dirs_relative(&root, tenant_id).await
1627+ let candidates = storage.list_dirs_relative(&root, tenant_id).await?;
1628+
1629+ let mut confirmed = Vec::with_capacity(candidates.len());
1630+ for stream_name in candidates {
1631+ if is_tombstoned(storage, &stream_name, tenant_id).await? {
1632+ confirmed.push(stream_name);
1633+ }
1634+ }
1635+ Ok(confirmed)
16221636}
16231637
16241638/// if filter_id is an empty str it should not append it to the rel path
@@ -1799,6 +1813,33 @@ mod tombstone_tests {
17991813 let discovered = list_tombstoned_streams(&storage, &None).await.unwrap();
18001814 assert_eq!(discovered, vec!["test_stream".to_string()]);
18011815 }
1816+
1817+ #[tokio::test]
1818+ async fn directory_without_the_actual_marker_is_not_reported_as_tombstoned() {
1819+ let dir = TempDir::new().unwrap();
1820+ let storage = LocalFS::new(dir.path().to_path_buf());
1821+
1822+ // A directory can exist under the tombstone root without ever
1823+ // containing the marker itself (e.g. an interrupted write) --
1824+ // list_dirs_relative alone can't tell the difference, so
1825+ // list_tombstoned_streams must re-verify via is_tombstoned.
1826+ let sibling_path = tombstone_path("test_stream", &None)
1827+ .parent()
1828+ .unwrap()
1829+ .join("not-the-marker");
1830+ storage
1831+ .put_object(&sibling_path, to_bytes(&()), &None)
1832+ .await
1833+ .unwrap();
1834+
1835+ assert!(!is_tombstoned(&storage, "test_stream", &None).await.unwrap());
1836+ assert!(
1837+ list_tombstoned_streams(&storage, &None)
1838+ .await
1839+ .unwrap()
1840+ .is_empty()
1841+ );
1842+ }
18021843}
18031844
18041845#[cfg(test)]
0 commit comments