Skip to content

Commit 094389a

Browse files
committed
Address CodeRabbit review: preserve deleting flag, tighten tombstone discovery
set_metadata replaced the whole LogStreamMetadata wholesale, so a reload racing a delete (e.g. a schema update landing after mark_deleting()) could silently clear the deleting flag back to false despite it being documented as monotonic. Now ORs it in instead of overwriting. list_tombstoned_streams trusted list_dirs_relative's raw directory listing as proof of a marker's existence, but a directory can exist under the tombstone root without the marker itself (e.g. an interrupted write). Each candidate is now re-verified with is_tombstoned before being reported. list_old_streams (unused elsewhere in this codebase, but kept consistent with list_streams) didn't exclude TOMBSTONE_ROOT_DIRECTORY, so dir_with_old_stream would treat it as a corrupt stream directory the same way list_streams did before the earlier fix.
1 parent 690410a commit 094389a

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎src/parseable/streams.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,12 @@ impl Stream {
12171217
}
12181218

12191219
/// Stores the provided stream metadata in memory mapping
1220-
pub async fn set_metadata(&self, updated_metadata: LogStreamMetadata) {
1221-
*self.metadata.write().expect(LOCK_EXPECT) = updated_metadata;
1220+
pub async fn set_metadata(&self, mut updated_metadata: LogStreamMetadata) {
1221+
let mut metadata = self.metadata.write().expect(LOCK_EXPECT);
1222+
// mark_deleting() is documented as monotonic -- a reload racing a
1223+
// delete must not silently clear it back to false.
1224+
updated_metadata.deleting |= metadata.deleting;
1225+
*metadata = updated_metadata;
12221226
}
12231227

12241228
pub fn get_first_event(&self) -> Option<String> {

‎src/storage/localfs.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ impl ObjectStorage for LocalFS {
572572
PARSEABLE_ROOT_DIRECTORY,
573573
ALERTS_ROOT_DIRECTORY,
574574
SETTINGS_ROOT_DIRECTORY,
575+
TOMBSTONE_ROOT_DIRECTORY,
575576
];
576577

577578
let result = fs::read_dir(&self.root).await;

‎src/storage/object_storage.rs‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,13 +1495,27 @@ pub async fn is_tombstoned(
14951495
/// node, since a tombstoned stream whose `.stream.json` is already gone
14961496
/// would otherwise never surface via `list_streams`. See `is_tombstoned` for
14971497
/// the equivalent single-name check.
1498+
///
1499+
/// `list_dirs_relative` only proves a directory exists under the tombstone
1500+
/// root, not that it actually holds a `.tombstone` marker (e.g. a partial or
1501+
/// interrupted write could leave an empty one behind) -- each candidate is
1502+
/// re-checked with `is_tombstoned` before being returned, so a directory
1503+
/// without a real marker is silently skipped rather than misreported.
14981504
pub async fn list_tombstoned_streams(
14991505
storage: &(impl ObjectStorage + ?Sized),
15001506
tenant_id: &Option<String>,
15011507
) -> Result<Vec<String>, ObjectStorageError> {
15021508
let tenant = tenant_id.as_deref().unwrap_or("");
15031509
let root = RelativePathBuf::from_iter([TOMBSTONE_ROOT_DIRECTORY, tenant]);
1504-
storage.list_dirs_relative(&root, tenant_id).await
1510+
let candidates = storage.list_dirs_relative(&root, tenant_id).await?;
1511+
1512+
let mut confirmed = Vec::with_capacity(candidates.len());
1513+
for stream_name in candidates {
1514+
if is_tombstoned(storage, &stream_name, tenant_id).await? {
1515+
confirmed.push(stream_name);
1516+
}
1517+
}
1518+
Ok(confirmed)
15051519
}
15061520

15071521
/// if filter_id is an empty str it should not append it to the rel path
@@ -1682,6 +1696,33 @@ mod tombstone_tests {
16821696
let discovered = list_tombstoned_streams(&storage, &None).await.unwrap();
16831697
assert_eq!(discovered, vec!["test_stream".to_string()]);
16841698
}
1699+
1700+
#[tokio::test]
1701+
async fn directory_without_the_actual_marker_is_not_reported_as_tombstoned() {
1702+
let dir = TempDir::new().unwrap();
1703+
let storage = LocalFS::new(dir.path().to_path_buf());
1704+
1705+
// A directory can exist under the tombstone root without ever
1706+
// containing the marker itself (e.g. an interrupted write) --
1707+
// list_dirs_relative alone can't tell the difference, so
1708+
// list_tombstoned_streams must re-verify via is_tombstoned.
1709+
let sibling_path = tombstone_path("test_stream", &None)
1710+
.parent()
1711+
.unwrap()
1712+
.join("not-the-marker");
1713+
storage
1714+
.put_object(&sibling_path, to_bytes(&()), &None)
1715+
.await
1716+
.unwrap();
1717+
1718+
assert!(!is_tombstoned(&storage, "test_stream", &None).await.unwrap());
1719+
assert!(
1720+
list_tombstoned_streams(&storage, &None)
1721+
.await
1722+
.unwrap()
1723+
.is_empty()
1724+
);
1725+
}
16851726
}
16861727

16871728
#[cfg(test)]

0 commit comments

Comments
 (0)