Skip to content

Commit eeb367f

Browse files
committed
Merge branch 'fix/1763-stream-deletion-safety-net' into fix/1763-async-stream-deletion
2 parents 4eafc27 + 094389a commit eeb367f

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
@@ -573,6 +573,7 @@ impl ObjectStorage for LocalFS {
573573
PARSEABLE_ROOT_DIRECTORY,
574574
ALERTS_ROOT_DIRECTORY,
575575
SETTINGS_ROOT_DIRECTORY,
576+
TOMBSTONE_ROOT_DIRECTORY,
576577
];
577578

578579
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
@@ -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.
16151621
pub 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

Comments
 (0)