review: a memory write wakes the Honcho worker
A write, an undo or an accepted write decided into the ledger waited out the worker's 30 s idle sleep. Mirror::journalled now says whether it added a line, and memoryd wakes the worker when it did. The Wake lock is a leaf, taken under the index lock as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -225,9 +225,16 @@ impl Mirror {
|
||||
/// Decide the journalled edit `id` (the latest when `None`), called under the index lock
|
||||
/// right after it was journalled, so the ledger has the journal's order; the ledger's lock is
|
||||
/// taken inside the index lock, and before an undo is decided against it. Its parts are
|
||||
/// `Edit { id, part }` from 0, numbering what is decided. An edit already decided, or asking nothing, adds no line. A
|
||||
/// failure is logged; the edit itself stands.
|
||||
pub fn journalled(&self, store: &Store, id: Option<&str>, now: Timestamp, log: &dyn Fn(&str)) {
|
||||
/// `Edit { id, part }` from 0, numbering what is decided. An edit already decided, or asking
|
||||
/// nothing, adds no line. A failure is logged; the edit itself stands. Whether any line was
|
||||
/// added, so that the worker is woken only when there is something new.
|
||||
pub fn journalled(
|
||||
&self,
|
||||
store: &Store,
|
||||
id: Option<&str>,
|
||||
now: Timestamp,
|
||||
log: &dyn Fn(&str),
|
||||
) -> bool {
|
||||
let records = match journal::records(store) {
|
||||
Ok(records) => records,
|
||||
Err(e) => {
|
||||
@@ -235,7 +242,7 @@ impl Mirror {
|
||||
"memoryd: {e}; the edit is not mirrored in Honcho; {}",
|
||||
ledger::RUNBOOK
|
||||
));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
let found = match id {
|
||||
@@ -243,7 +250,7 @@ impl Mirror {
|
||||
None => records.last(),
|
||||
};
|
||||
let Some(record) = found else {
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
let session = session_of(record, &records);
|
||||
let mut book = self.ledger.lock().unwrap_or_else(|p| p.into_inner());
|
||||
@@ -251,9 +258,10 @@ impl Mirror {
|
||||
if record.undoes.is_some() {
|
||||
actions.retain(|a| brought_back(&book, a));
|
||||
}
|
||||
let mut added = false;
|
||||
for (part, action) in actions.into_iter().enumerate() {
|
||||
let Ok(part) = u32::try_from(part) else {
|
||||
return;
|
||||
return added;
|
||||
};
|
||||
let item = Item::Edit {
|
||||
id: record.id.clone(),
|
||||
@@ -268,8 +276,10 @@ impl Mirror {
|
||||
action,
|
||||
}) {
|
||||
log(&format!("memoryd: {e}; {}", ledger::RUNBOOK));
|
||||
return;
|
||||
return added;
|
||||
}
|
||||
added = true;
|
||||
}
|
||||
added
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,9 +228,12 @@ impl Memoryd {
|
||||
|
||||
/// With `[honcho]`: decide journalled edit `id` (the latest when `None`) into the ledger. Called
|
||||
/// under the index lock, so edits are decided in the journal's order (M5c spec, section 4).
|
||||
/// What it decided is sent at once: the worker is woken.
|
||||
fn mirror(&self, id: Option<&str>) {
|
||||
if let Some(mirror) = &self.mirror {
|
||||
mirror.journalled(&self.store, id, Timestamp::now(), &*self.log);
|
||||
if let Some(mirror) = &self.mirror
|
||||
&& mirror.journalled(&self.store, id, Timestamp::now(), &*self.log)
|
||||
{
|
||||
self.wake.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user