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
2 changes: 2 additions & 0 deletions cmux-tui/crates/acpmux/src/hub/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ impl Hub {
pub fn stop_idle_reaper(&self) {
self.stopping.store(true, Ordering::SeqCst);
self.peer_notices_stop.send_replace(true);
// Reads of peer chats ahead of an open end too, before the last flush (`peer_snapshot/warm.rs`).
self.peer_snapshots.stop_warming();
self.idle_wake.notify_one();
}

Expand Down
10 changes: 10 additions & 0 deletions cmux-tui/crates/acpmux/src/hub/peer_grace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ impl Hub {
self.save_after_drop(&peer, generation, !ongoing);
}
notice => {
// Rows came (a list, a changed row) or the link is up: the peer's chats are
// read ahead soon (`peer_snapshot/warm.rs`).
let warms = match &notice {
PeerNotice::Connected | PeerNotice::Sessions(_) => true,
PeerNotice::SessionChanged { kind, .. } => kind != "purged",
_ => false,
};
// A link that brought rows (or a planned restart, which never
// enters the grace path) ends the outage: its next drop starts
// a new one, even after this one's rows went unreachable.
Expand All @@ -115,6 +122,9 @@ impl Hub {
current.outage_ended.store(false, Ordering::SeqCst);
}
self.apply_peer_notice(&peer, generation, notice);
if warms {
self.warm_peer_copies(&peer);
}
}
}
if settles {
Expand Down
41 changes: 33 additions & 8 deletions cmux-tui/crates/acpmux/src/hub/peer_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
//! client paints a paused or offline peer's chat at once, marked possibly stale, then catches up
//! from the peer with `afterSeq` (cmuxterm-hq#4381; Lawrence: "decouple persistence of acp
//! trajectories from the VM itself, in case the VM is resuming"). The peer's journal stays the
//! authority: this is what this daemon saw of it (its clients' pages, the peer's live records),
//! never a write lease, an execution checkpoint or a backup. The files are `disk.rs`'s.
//! authority: this is what this daemon saw of it (its clients' pages, the pages it read ahead of
//! an open, `warm.rs`, the peer's live records), never a write lease, an execution checkpoint or a
//! backup. The files are `disk.rs`'s.
//!
//! One thread owns every copy and every file (`Store`); the hub only sends it what it saw, in
//! the order it saw it, so no capture, listing, purge or write ever runs beside another. Sending
Expand Down Expand Up @@ -179,6 +180,11 @@ enum Op {
bounds: (usize, usize),
reply: mpsc::SyncSender<Value>,
},
/// What each copy of a peer covers (`warm.rs`).
Covers {
peer: String,
reply: mpsc::SyncSender<HashMap<String, (Option<u64>, u64)>>,
},
Flush {
peer: Option<String>,
done: Option<mpsc::SyncSender<()>>,
Expand Down Expand Up @@ -242,6 +248,8 @@ pub struct PeerSnapshots {
queued: Arc<AtomicU64>,
dropped: Arc<StdMutex<Dropped>>,
untaken: Untaken,
/// The reads ahead of an open (`warm.rs`).
warm: warm::Warm,
}

impl PeerSnapshots {
Expand All @@ -254,6 +262,7 @@ impl PeerSnapshots {
queued: Arc::default(),
dropped: Arc::default(),
untaken: Arc::default(),
warm: warm::Warm::default(),
}
}

Expand Down Expand Up @@ -680,6 +689,9 @@ impl Store {
Op::Read { key, generation, bounds, reply } => {
let _ = reply.send(self.read(&key, generation, bounds));
}
Op::Covers { peer, reply } => {
let _ = reply.send(self.covers(&peer));
}
Op::Flush { peer, done } => {
if done.is_none() {
self.dropped.lock().unwrap_or_else(|e| e.into_inner()).flushes.remove(&peer);
Expand All @@ -706,7 +718,7 @@ impl Store {
}
Op::Flush { .. } => return,
// Its reader is answered at once that there is nothing (its reply went with it).
Op::Read { .. } => return,
Op::Read { .. } | Op::Covers { .. } => return,
Op::LostPeer(_) => return self.take(op),
Op::ForgetPeer(peer) => (peer, true),
Op::Listed { peer, .. } | Op::Lagged { peer, .. } => (peer, false),
Expand Down Expand Up @@ -1428,9 +1440,11 @@ impl Hub {

/// Keeps a page of peer `peer`'s session `mux` this daemon forwarded (`_acpmux/attach`,
/// `_acpmux/events`; `server/peer_forward.rs`), asked on link `link` while the row named
/// generation `asked`; `events`: an `_acpmux/events` page, else an attach. Only a run of the chat as a client reads it is kept: not a page of older
/// history (`beforeSeq`), nor one of some kinds only that leaves the transcript out (the app's
/// attach asks for `transcript` and a few more, which its live records follow too).
/// generation `asked`; `events`: an `_acpmux/events` page, else an attach. Only a run of the
/// chat as a client reads it is kept: not a page of older history (a `beforeSeq` short of
/// [`warm::NEWEST`]), nor one of some kinds only that leaves the transcript out (the app's
/// attach asks for `transcript` and a few more, which its live records follow too). A read
/// ahead (`warm.rs`) is kept here too.
pub fn capture_peer_page(
&self,
(peer, generation, link, asked): (&str, u64, u64, Option<u64>),
Expand All @@ -1446,7 +1460,14 @@ impl Hub {
Some(Value::Array(kinds)) => !kinds.iter().any(transcript),
Some(kind) => !transcript(kind),
};
if params.get("beforeSeq").is_some_and(|v| !v.is_null()) || leaves_out {
// A page of the newest records (`beforeSeq` past every seq and no `afterSeq`: the pane's
// read-ahead, a read ahead here, `warm.rs`) is the chat's run as an attach's is. One with
// an `afterSeq` too is the newest `limit` records after it, which need not start there.
let before = params.get("beforeSeq").filter(|v| !v.is_null());
let after = params.get("afterSeq").filter(|v| !v.is_null());
let newest =
after.is_none() && before.and_then(Value::as_u64).is_some_and(|b| b >= warm::NEWEST);
if (before.is_some() && !newest) || leaves_out {
return;
}
let Some(records) = result.get("events").and_then(Value::as_array) else { return };
Expand All @@ -1459,7 +1480,10 @@ impl Hub {
// say which journal answered it.
generation: result.get("session").and_then(created_at).or_else(|| created_at(result)),
// `_acpmux/events` with no `afterSeq` pages forward from the first record.
after: params.get("afterSeq").and_then(Value::as_u64).or(events.then_some(0)),
after: params
.get("afterSeq")
.and_then(Value::as_u64)
.or((events && !newest).then_some(0)),
has_more: result.get("hasMore") != Some(&Value::Bool(false)),
host_last_seq: result.get("lastSeq").and_then(Value::as_u64),
// Only a peer that says how far its page holds is taken past the page's last record.
Expand All @@ -1472,6 +1496,7 @@ impl Hub {
}

mod read;
mod warm;

#[cfg(test)]
#[path = "peer_snapshot_tests.rs"]
Expand Down
Loading