summaryrefslogtreecommitdiffstats
path: root/src/compaction/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/compaction/mod.rs')
-rw-r--r--src/compaction/mod.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/compaction/mod.rs b/src/compaction/mod.rs
index 5608eae..6cb1a98 100644
--- a/src/compaction/mod.rs
+++ b/src/compaction/mod.rs
@@ -3,18 +3,24 @@
//! * `snapshot`: deterministic snapshot build (step 3).
//! * `records`: the replicated compaction records under `_continuum/compactions/<id>`.
//! * `coordinator`: proposal, settle period and decision on the node that was asked.
+//! * `switch`: switching this node to a committed epoch (worker).
+//! * `delta`: replaying this node's changes since the base into the new epoch.
+//! * `local`: per-node in-memory state (prebuilt snapshots, switch status, archive).
//! * `api`: `/admin/compaction(s)` handlers.
//!
-//! Step 4 decides compactions but does not switch epochs yet; a committed record only
-//! names the new epoch.
-//!
//! The rest of the node is reached exclusively through [`Host`], so this module never
//! depends on `AppState`, peers or sync internals.
mod api;
mod coordinator;
+mod delta;
+mod local;
mod records;
pub(crate) mod snapshot;
+mod switch;
+
+pub(crate) use local::Compaction;
+pub(crate) use switch::run_worker;
use std::future::Future;
use std::sync::Arc;
@@ -34,6 +40,9 @@ use crate::sync::ChangeSet;
///
/// Used generically (`H: Host`), never as `dyn Host`, so the generic methods are fine.
pub(crate) trait Host: Clone + Send + Sync + 'static {
+ /// This node's in-memory compaction state.
+ fn compaction(&self) -> &Compaction;
+
/// This node's peer ID.
fn node_id(&self) -> String;
@@ -69,6 +78,18 @@ pub(crate) trait Host: Clone + Send + Sync + 'static {
F: FnOnce(&mut AutoCommit) -> Result<T, E> + Send + 'static,
T: Send + 'static,
E: Send + 'static;
+
+ /// Replaces the document and its epoch atomically. Under the write lock, `f` gets
+ /// the live document and returns the new one. Afterwards the node resets every
+ /// peer's sync state and publishes the change. Returns the old document.
+ fn switch_epoch<E, F>(
+ &self,
+ epoch: Epoch,
+ f: F,
+ ) -> impl Future<Output = Result<AutoCommit, E>> + Send
+ where
+ F: FnOnce(&mut AutoCommit) -> Result<AutoCommit, E> + Send + 'static,
+ E: Send + 'static;
}
#[derive(Clone, Debug)]
@@ -87,4 +108,5 @@ pub(crate) fn router<H: Host>() -> Router<H> {
"/admin/compactions/{id}",
get(api::get::<H>).delete(api::abort::<H>),
)
+ .route("/admin/epochs", get(api::epochs::<H>))
}