v0.3.7-pre.008

This commit is contained in:
2026-09-02 16:56:11 +02:00
parent 6e406a6b84
commit 48d26b43f9
19 changed files with 693 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-app-backfill-desk/src/store_runtime.rs
// version: 1
// version: 2
//! Composite-selected Store readiness and shutdown lifecycle owned by Backfill Desk.
@@ -21,6 +21,36 @@ impl StoreStartup {
options.composition_ready = options.transport_ready && options.network_coherent && options.store_ready;
}
/// Temporarily lends the ready Store facade to one admitted Backfill execution.
pub(crate) fn take_for_run(&self) -> ksp_core_lib::Result<ksp_store_lib::Store> {
let runtime = self.runtime.as_ref();
let runtime = match runtime {
std::option::Option::Some(value) if value.health_ready() => value,
_ => {
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_BACKFILL_COMPOSITION_NOT_READY,
"Backfill Desk cannot start a Backfill run without a ready Store",
));
},
};
return runtime.take_for_run();
}
/// Restores the Store facade after one Backfill execution reaches its terminal result.
pub(crate) fn restore_after_run(&self, store: ksp_store_lib::Store) -> ksp_core_lib::Result<()> {
let runtime = self.runtime.as_ref();
let runtime = match runtime {
std::option::Option::Some(value) => value,
std::option::Option::None => {
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_APP_STATE_INVALID,
"Backfill Desk cannot restore Store after runtime ownership disappeared",
));
},
};
return runtime.restore_after_run(store);
}
/// Closes the retained Store runtime if startup reached the physical Store-open phase.
pub(crate) async fn close(&self) -> ksp_core_lib::Result<()> {
let runtime = self.runtime.as_ref();
@@ -46,6 +76,44 @@ impl StoreRuntime {
return self.health_ready;
}
/// Temporarily removes the Store from the application slot for one single-active Backfill execution.
pub(crate) fn take_for_run(&self) -> ksp_core_lib::Result<ksp_store_lib::Store> {
let store = take_store(&self.store);
let store = match store {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
return match store {
std::option::Option::Some(value) => std::result::Result::Ok(value),
std::option::Option::None => std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_BACKFILL_RUN_ACTIVE,
"Backfill Desk Store is already owned by an active Backfill run",
)),
};
}
/// Restores the Store after one terminal Backfill execution so a later campaign can be admitted.
pub(crate) fn restore_after_run(&self, store: ksp_store_lib::Store) -> ksp_core_lib::Result<()> {
let locked = self.store.lock();
let mut locked = match locked {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => {
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_APP_STATE_LOCK_FAILED,
"Backfill Desk Store runtime state lock is poisoned",
));
},
};
if locked.is_some() {
return std::result::Result::Err(ksp_core_lib::Error::new(
crate::ERROR_CODE_APP_STATE_INVALID,
"Backfill Desk cannot restore Store into an occupied runtime slot",
));
}
*locked = std::option::Option::Some(store);
return std::result::Result::Ok(());
}
/// Explicitly closes the Store exactly once through its backend-neutral facade.
pub(crate) async fn close(&self) -> ksp_core_lib::Result<()> {
let store = take_store(&self.store);