Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/engine/src/backup/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,16 @@ impl ConfiguredStore {
/// Whether a call abandoned at its bound has not returned (module doc).
#[must_use]
pub fn check_call_in_flight(&self) -> bool {
self.check_call_in_flight.caller().is_some()
self.call_in_flight_caller().is_some()
}

/// The caller whose call abandoned at its bound has not returned
/// ([`BoundedCalls`]'s `what`, such as `check`, `deletion` or `startup
/// sync's store call`), if any: the caller the refusal of the next call
/// names.
#[must_use]
pub fn call_in_flight_caller(&self) -> Option<&'static str> {
self.check_call_in_flight.caller()
}

/// Whether a deletion fence's read abandoned at its bound has not
Expand Down
36 changes: 24 additions & 12 deletions crates/engine/src/backup/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ use extenddb_core::backup_format::{
use extenddb_core::metrics::MetricsCollector;
use extenddb_storage::BackupCatalog;
use extenddb_storage::backup_catalog::{
BackupKey, BackupRow, BackupStatus, ForgetRow, StoreIdentity, StoreKind, UNOWNED_GENERATION,
BackupKey, BackupRow, BackupStatus, ForgetRow, StoreIdentity, UNOWNED_GENERATION,
is_backup_not_found,
};
use extenddb_storage::error::StorageError;
Expand Down Expand Up @@ -1032,22 +1032,33 @@ pub async fn startup_sync<S: BackupCatalog + ?Sized>(
claim: None,
},
);
// A store call abandoned at its bound or dropped with the run (a
// filesystem call, whose thread still runs) is marked in flight under
// its caller's name: the run's own call, or another caller's (a
// deletion's, whose call held the slot the run waited for). Until it
// returns, each cycle's check is refused and the store is unreachable,
// so the sync runs again on the first cycle after it; the clause names
// the caller as the refusal does. A run cut in a catalog call, or after
// its last store call returned, marks nothing, and with no other
// caller's call in flight the next cycle's check runs as usual.
let in_flight = || {
store
.call_in_flight_caller()
.map_or_else(String::new, |caller| {
format!(
" (once the abandoned {caller} has returned; until then the store is \
unreachable)"
)
})
};
let Ok(outcome) = tokio::time::timeout(STARTUP_SYNC_TIMEOUT, run).await else {
// On a filesystem store the abandoned listing's walk still runs:
// until it returns, each cycle's check is refused and the store is
// unreachable, so the sync runs again on the first cycle after it.
tracing::warn!(
"backup store ({}) startup sync of the in-memory catalog did not finish within {} \
s; the backups it adopted keep their rows, and a later reconciler cycle runs it \
again from the first key of the root{}",
store.kind,
STARTUP_SYNC_TIMEOUT.as_secs(),
if store.kind == StoreKind::Filesystem {
" (once the abandoned listing of the root has returned; until then the store is \
unreachable)"
} else {
""
}
in_flight()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No cut reaches this arm while another caller's call is marked. SidecarReadStalled runs with the startup sync's own mark, and InsertStalled with none. DeletionInFlight ends in the error arm, because the listing's slot wait and the run's bound both end at 60 seconds. Reading the tests, a change that makes this arm name the startup sync's own call whenever the mark is set fails none of them. Please add a cut that ends here with a deletion marked, and assert that this line names the deletion. One way is a delay of 1 second on the manifest's read and a deletion started after 500 milliseconds. The deletion then takes the slot first, and the run's bound ends the run before the sidecar read's wait ends.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a sixth cut, Cut::DeletionAheadOfTheSidecarRead, to a_cut_startup_sync_names_the_store_unreachable_only_while_its_call_is_in_flight (crates/engine/src/backup/tests.rs:21973), along the lines you suggested. Each store call takes 1 s, deletions stall, and a calls("deletion") delete starts at 500 ms. The deletion takes the slot when the manifest read returns at 1 s, so the sidecar read's wait for the slot would end at 61 s, and the run's 60 s bound ends the run first. The cut asserts that the run timed out rather than returning Err, that call_in_flight_caller() is Some("deletion"), and that the timeout line ends with the deletion's clause and never names the startup sync's own call. Your mutant fails it: the timeout arm naming the startup sync's call whenever the mark is set. The cell passed 20 runs in a row, and backup:: passes 339.

);
return None;
};
Expand Down Expand Up @@ -1102,8 +1113,9 @@ pub async fn startup_sync<S: BackupCatalog + ?Sized>(
}
Err(e) => tracing::warn!(
"backup store ({}) startup sync of the in-memory catalog stopped: {e}; a later \
reconciler cycle runs it again",
store.kind
reconciler cycle runs it again{}",
store.kind,
in_flight()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test checks how this line ends when nothing is marked. The only assertion on the error arm, at tests.rs:22038, runs with the walk marked. The failed-listing run in startup_sync_logs_its_skips_at_info_until_a_run_has_reported(false) counts prefix lines only. Reading the tests, a change that always appends the clause here fails none of them. So does a change back to main's store-kind test in this arm. Please add a fourth cut with a listing that fails at once (fail_lists_of), asserting Err(Listing), no mark, and a line that ends in "runs it again".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added as the fourth cut, Cut::ListingFails: the root listing fails at once through fail_lists_of, and the cut asserts Err(Listing), no mark, and a line ending "a later reconciler cycle runs it again" with no clause. The two mutants you describe were run: the error arm always appending the clause, and the error arm choosing it by store.kind. This cut fails both.

),
}
Some(outcome)
Expand Down
267 changes: 267 additions & 0 deletions crates/engine/src/backup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ struct Fake {
/// When set, `insert_backup_row` fails with this error and writes
/// nothing.
insert_error: Mutex<Option<String>>,
/// When set, `insert_backup_row` never answers (a catalog write that
/// hangs) and writes nothing.
stall_inserts: std::sync::atomic::AtomicBool,
/// Every key `forget_available_backup_row` received.
forgets_seen: Mutex<Vec<BackupKey>>,
/// Preset answers of `forget_available_backup_row`, by ARN; the row is
Expand Down Expand Up @@ -884,6 +887,8 @@ struct MemStore {
/// When set, every `get` of a key ending in this text fails at the call
/// as a transport error (one object the store never serves).
fail_gets_of: Mutex<Option<String>>,
/// When set, `get` of this key never answers; every other call answers.
stall_gets_of: Mutex<Option<String>>,
/// When set, the body of the `get` with this ordinal (1-based, over
/// every `get` the store saw) panics after its first chunk: a reader on
/// the blocking pool that dies mid-file.
Expand Down Expand Up @@ -1178,6 +1183,11 @@ impl extenddb_backup_store::BackupStore for MemStore {
self.gets.lock().unwrap().push(key.to_owned());
self.stall().await;
self.check()?;
if self.stall_gets_of.lock().unwrap().as_deref() == Some(key) {
self.stalls
.fetch_add(1, std::sync::atomic::Ordering::AcqRel);
std::future::pending::<()>().await;
}
if key == STORE_IDENTITY_KEY {
let failure = {
let mut slot = self.identity_get_failure.lock().unwrap();
Expand Down Expand Up @@ -1712,6 +1722,12 @@ impl BackupCatalog for Fake {
row: &'a BackupRow,
) -> BoxedFuture<'a, Result<bool, StorageError>> {
self.insert_attempts.lock().unwrap().push(row.clone());
if self
.stall_inserts
.load(std::sync::atomic::Ordering::Acquire)
{
return Box::pin(std::future::pending());
}
if let Some(e) = self.insert_error.lock().unwrap().clone() {
return Box::pin(async move { Err(StorageError::Internal(e)) });
}
Expand Down Expand Up @@ -21933,6 +21949,257 @@ async fn a_startup_sync_whose_first_run_is_cut_at_its_bound_logs_its_skips_at_in
startup_sync_logs_its_skips_at_info_until_a_run_has_reported(true).await;
}

/// The line a startup sync cut short ends with says that the store is
/// unreachable until the abandoned call returns exactly when a store call
/// is still in flight, on a filesystem root, on either arm, and names the
/// caller the in-flight mark names: the root's listing held past the bound
/// (the listing's own bound, as long as the run's, ends the run with a
/// listing error, the walk marked in flight), the sidecar's read stalled
/// once the run's first second has passed (the run's bound ends it before
/// the read's own, the read marked in flight), the row's insert stalled
/// after every store call of the run returned (the run's bound ends it with
/// nothing marked, and the line says nothing of the store), the root's
/// listing failing at once (a listing error with nothing marked, and the
/// line says nothing of the store), a deletion's call holding the slot
/// the listing waits for (the deletion abandoned at its own bound and
/// marked, the listing's wait ending at the run's bound, and the line names
/// the deletion), and a deletion's call that takes the slot while the
/// manifest's read holds it (each call takes a second and the deletion
/// starts at 500 ms, so it holds the slot from the first second on, is
/// abandoned and marked at its own bound, and the run's bound ends the run
/// while the sidecar's read still waits for the slot; the line names the
/// deletion).
#[tokio::test(start_paused = true)]
async fn a_cut_startup_sync_names_the_store_unreachable_only_while_its_call_is_in_flight() {
#[derive(Debug, Clone, Copy)]
enum Cut {
ListingHeld,
SidecarReadStalled,
InsertStalled,
ListingFails,
DeletionInFlight,
DeletionAheadOfTheSidecarRead,
}
const DELETION_CLAUSE: &str = "(once the abandoned deletion has returned; until then the \
store is unreachable)";
const OWN_CALL: &str = "startup sync's store call";
const CLAUSE: &str = "(once the abandoned startup sync's store call has returned; until \
then the store is unreachable)";
let (lines, _guard) = LogLines::capture();
for cut in [
Cut::ListingHeld,
Cut::SidecarReadStalled,
Cut::InsertStalled,
Cut::ListingFails,
Cut::DeletionInFlight,
Cut::DeletionAheadOfTheSidecarRead,
] {
let mem = Arc::new(MemStore::default());
mem.insert(STORE_IDENTITY_KEY, &identity_file("store-1", "catalog-1"));
let fake = Arc::new(Fake::default());
let backup = sync_arn(1);
put_backup(&mem, &backup);
let runtime = runtime().with_store(
ConfiguredStore::new(
store().store_kind,
store().store_root,
Arc::clone(&mem) as Arc<dyn extenddb_backup_store::BackupStore>,
None,
Ok(store()),
)
.with_ephemeral_catalog(true),
);
let configured = runtime.configured_store().unwrap();
match cut {
Cut::ListingHeld => mem
.hold_root_list
.store(true, std::sync::atomic::Ordering::Release),
Cut::SidecarReadStalled => {
// Each call takes a second, so the sidecar's read, the
// run's second call after its listing, starts once a
// second has passed and its own bound ends after the run's.
mem.set_delay(Some(Duration::from_secs(1)));
*mem.stall_gets_of.lock().unwrap() =
Some(format!("{}{MANIFEST_CHECKSUM_FILE}", prefix_of(&backup)));
}
Cut::InsertStalled => fake
.stall_inserts
.store(true, std::sync::atomic::Ordering::Release),
Cut::ListingFails => *mem.fail_lists_of.lock().unwrap() = Some(String::new()),
Cut::DeletionInFlight => mem
.stall_deletes
.store(true, std::sync::atomic::Ordering::Release),
Cut::DeletionAheadOfTheSidecarRead => {
mem.set_delay(Some(Duration::from_secs(1)));
mem.stall_deletes
.store(true, std::sync::atomic::Ordering::Release);
}
}
let before = lines
.containing("startup sync of the in-memory catalog")
.len();
let run = tokio::time::timeout(
super::sync::STARTUP_SYNC_TIMEOUT * 5,
super::sync::startup_sync(&*fake, &runtime),
);
let deletion_after = match cut {
// The deletion's call takes the slot first; the run's listing
// waits for it.
Cut::DeletionInFlight => Some(Duration::ZERO),
// The deletion waits for the slot behind the manifest's read
// and takes it before the sidecar's read.
Cut::DeletionAheadOfTheSidecarRead => Some(Duration::from_millis(500)),
_ => None,
};
let ran = if let Some(after) = deletion_after {
let deletion = configured.calls("deletion");
let prefix = prefix_of(&backup);
let delete = async {
if !after.is_zero() {
tokio::time::sleep(after).await;
}
extenddb_backup_store::BackupStore::delete_prefix(&deletion, &prefix).await
};
let (deleted, ran) = futures::future::join(delete, run).await;
assert!(deleted.is_err(), "the deletion is abandoned: {deleted:?}");
ran
} else {
run.await
}
.expect("the startup sync is bounded");
let logged = lines.containing("startup sync of the in-memory catalog")[before..].to_vec();
let [line] = logged.as_slice() else {
panic!("{cut:?}: one line: {logged:?}");
};
assert_eq!(
lines
.at_level(tracing::Level::WARN)
.last()
.map(String::as_str),
Some(line.as_str()),
"{cut:?}"
);
assert!(configured.startup_sync_pending(), "{cut:?}: left pending");
match cut {
Cut::ListingHeld => {
assert!(
matches!(ran, Some(Err(super::sync::SyncError::Listing { .. }))),
"{ran:?}"
);
assert!(line.contains("stopped: "), "{line}");
assert_eq!(
configured.call_in_flight_caller(),
Some(OWN_CALL),
"the walk is marked"
);
assert!(line.ends_with(CLAUSE), "{line}");
mem.hold_root_list
.store(false, std::sync::atomic::Ordering::Release);
for _ in 0..200 {
if !configured.check_call_in_flight() {
break;
}
tokio::time::sleep(Duration::from_millis(10)).await;
}
assert!(!configured.check_call_in_flight(), "the walk returned");
}
Cut::SidecarReadStalled => {
assert!(ran.is_none(), "{ran:?}");
assert!(line.contains("did not finish within 60 s"), "{line}");
assert_eq!(mem.stalls.load(std::sync::atomic::Ordering::Acquire), 1);
assert_eq!(
configured.call_in_flight_caller(),
Some(OWN_CALL),
"the read is marked"
);
assert!(line.ends_with(CLAUSE), "{line}");
}
Cut::InsertStalled => {
assert!(ran.is_none(), "{ran:?}");
assert!(line.contains("did not finish within 60 s"), "{line}");
assert_eq!(
fake.insert_attempts.lock().unwrap().len(),
1,
"cut in the insert"
);
assert!(!configured.check_call_in_flight(), "nothing is marked");
assert!(line.ends_with("from the first key of the root"), "{line}");
}
Cut::ListingFails => {
assert!(
matches!(ran, Some(Err(super::sync::SyncError::Listing { .. }))),
"{ran:?}"
);
assert!(line.contains("stopped: "), "{line}");
assert!(!configured.check_call_in_flight(), "nothing is marked");
assert!(
line.ends_with("a later reconciler cycle runs it again"),
"{line}"
);
}
Cut::DeletionInFlight => {
assert!(
matches!(ran, Some(Err(super::sync::SyncError::Listing { .. }))),
"{ran:?}"
);
assert!(line.contains("stopped: "), "{line}");
assert_eq!(mem.stalls.load(std::sync::atomic::Ordering::Acquire), 1);
assert_eq!(
configured.call_in_flight_caller(),
Some("deletion"),
"the deletion is marked"
);
assert!(line.ends_with(DELETION_CLAUSE), "{line}");
// The listing's error names the run's call; the clause
// names the deletion's.
assert!(!line.contains(&format!("abandoned {OWN_CALL}")), "{line}");
mem.stall_deletes
.store(false, std::sync::atomic::Ordering::Release);
for _ in 0..200 {
if !configured.check_call_in_flight() {
break;
}
tokio::time::sleep(Duration::from_millis(10)).await;
}
assert!(!configured.check_call_in_flight(), "the deletion returned");
}
Cut::DeletionAheadOfTheSidecarRead => {
assert!(ran.is_none(), "{ran:?}");
assert!(line.contains("did not finish within 60 s"), "{line}");
assert_eq!(mem.stalls.load(std::sync::atomic::Ordering::Acquire), 1);
// The manifest's read reached the store; the sidecar's
// never held the slot.
let prefix = prefix_of(&backup);
let gets = mem.gets.lock().unwrap().clone();
assert!(
gets.contains(&format!("{prefix}{EXTENDDB_MANIFEST_FILE}")),
"{gets:?}"
);
assert!(
!gets.contains(&format!("{prefix}{MANIFEST_CHECKSUM_FILE}")),
"{gets:?}"
);
assert_eq!(
configured.call_in_flight_caller(),
Some("deletion"),
"the deletion is marked"
);
assert!(line.ends_with(DELETION_CLAUSE), "{line}");
assert!(!line.contains(&format!("abandoned {OWN_CALL}")), "{line}");
mem.stall_deletes
.store(false, std::sync::atomic::Ordering::Release);
for _ in 0..200 {
if !configured.check_call_in_flight() {
break;
}
tokio::time::sleep(Duration::from_millis(10)).await;
}
assert!(!configured.check_call_in_flight(), "the deletion returned");
}
}
}
}

/// A startup sync another caller has taken is not run again: with the
/// pending sync taken, `startup_sync` answers `None` with no listing of the
/// root and no row read, and the sync is not handed back.
Expand Down
Loading