aboutsummaryrefslogtreecommitdiffstats
path: root/src/state
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 03:00:19 +0000
committertv <tv@krebsco.de>2026-11-29 03:00:19 +0000
commit2b4e99e1ed273da0f921eaec3e52300480acdf0a (patch)
tree53e2e5e1882eb6ff3853c2f2e8fa9d91a8c16655 /src/state
parent438b0ee5d1fe5d40f18e16d94904fc9bdd89783a (diff)
document: what a dropped change takes with it is the document's to say
document::dropping: a change a document holds and all that builds on it (Tainted), and the document left without them, with what this node's own writes among them touched and the others' changes (Dropped). The walk of the history, the fork and the fresh actor were the node's, in AppState::drop_taken, which keeps what is its own: whether a drop waits for a second member's word, the quarantine, the refused.
Diffstat (limited to 'src/state')
-rw-r--r--src/state/host.rs106
1 files changed, 30 insertions, 76 deletions
diff --git a/src/state/host.rs b/src/state/host.rs
index 34ed7ed..2fac94b 100644
--- a/src/state/host.rs
+++ b/src/state/host.rs
@@ -124,30 +124,21 @@ impl AppState {
if !replica.writable {
return None;
}
- let changes = replica.doc.get_changes(&[]);
- let dropped = changes.iter().find(|change| change.hash() == root)?;
- if dropped.deps().is_empty() {
- error!(change = %root, "Asked to drop the epoch's root; kept it");
- return None;
- }
- // In causal order: a change after those it builds on.
- let mut tainted: std::collections::HashSet<ChangeHash> = [root].into();
- for change in &changes {
- if change.deps().iter().any(|dep| tainted.contains(dep)) {
- tainted.insert(change.hash());
+ use crate::document::dropping::{Kept, Tainted};
+ let tainted = match Tainted::of(&replica.doc, root)? {
+ Ok(tainted) => tainted,
+ Err(Kept::Root) => {
+ error!(change = %root, "Asked to drop the epoch's root; kept it");
+ return None;
}
- }
- let kept: Vec<_> = changes
- .iter()
- .filter(|change| !tainted.contains(&change.hash()))
- .collect();
- if kept.is_empty() {
- error!(change = %root, "Dropping a change would leave nothing; kept it");
- return None;
- }
+ Err(Kept::Nothing) => {
+ error!(change = %root, "Dropping a change would leave nothing; kept it");
+ return None;
+ }
+ };
+ let count = tainted.len();
if another
- && (tainted.len() > BIG_DROP
- || (tainted.len() > SMALL_DROP && tainted.len() * 10 > changes.len()))
+ && (count > BIG_DROP || (count > SMALL_DROP && count * 10 > tainted.of_all()))
{
use crate::locks::MutexExt;
let mut screening = state.screening.lock_or_recover();
@@ -155,75 +146,38 @@ impl AppState {
.of(replica.epoch_seq)
.hold_drop(root, &peer);
if said < 2 {
- error!(change = %root, peer = %peer, changes = tainted.len(), why = %why, "A peer says we hold a change the swarm's rules refuse, and ours do too, but dropping it takes much: waiting for another member to say so");
+ error!(change = %root, peer = %peer, changes = count, why = %why, "A peer says we hold a change the swarm's rules refuse, and ours do too, but dropping it takes much: waiting for another member to say so");
return None;
}
}
- let built_on: std::collections::HashSet<ChangeHash> = kept
- .iter()
- .flat_map(|change| change.deps().iter().copied())
- .collect();
- let heads: Vec<ChangeHash> = kept
- .iter()
- .map(|change| change.hash())
- .filter(|hash| !built_on.contains(hash))
- .collect();
- // This node's own writes among those dropped: the paths they touched.
- let mut actors = own;
- actors.push(replica.doc.get_actor().clone());
- let ours: Vec<crate::document::ExpandedChange> = changes
- .iter()
- .filter(|change| tainted.contains(&change.hash()))
- .filter(|change| actors.contains(change.actor_id()))
- .map(|change| change.decode())
- .collect();
- let mut paths: Vec<Vec<String>> =
- crate::document::inspect::Inspector::new(&replica.doc)
- .ops(&ours)
- .into_iter()
- .flatten()
- .map(|op| op.path)
- .collect();
- paths.sort();
- paths.dedup();
- let actor = crate::document::ActorId::random();
- let fresh = match replica.doc.fork_at(&heads) {
- Ok(fresh) => fresh.with_actor(actor.clone()),
+ // This node's own writes among those dropped go to the quarantine; the
+ // others' changes, for operators, to the refused.
+ let dropped = match tainted.dropped(&replica.doc, own) {
+ Ok(dropped) => dropped,
Err(error) => {
error!(error = %error, "Couldn't drop a change taken unjudged");
return None;
}
};
- // The others' changes dropped, for operators (own: to the quarantine).
- let theirs: Vec<crate::access::screen::Refused> = changes
- .iter()
- .filter(|change| tainted.contains(&change.hash()))
- .filter(|change| !actors.contains(change.actor_id()))
- .map(|change| crate::access::screen::Refused {
- change: (*change).clone(),
- committer: replica
- .doc
- .get_author_for_actor(change.actor_id())
- .and_then(|author| {
- std::str::from_utf8(author.as_bytes())
- .ok()
- .map(str::to_owned)
- }),
- user: change
- .message()
- .and_then(crate::document::replica::user_of)
- .map(str::to_owned),
+ let paths = dropped.own_paths;
+ let theirs: Vec<crate::access::screen::Refused> = dropped
+ .theirs
+ .into_iter()
+ .map(|theirs| crate::access::screen::Refused {
+ change: theirs.change,
+ committer: theirs.committer,
+ user: theirs.user,
paths: Default::default(),
- why: if change.hash() == root {
+ why: if theirs.root {
format!("taken unjudged, dropped: {why}")
} else {
format!("taken unjudged, dropped: it builds on {root}")
},
})
.collect();
- state.own_writers.add(actor);
+ state.own_writers.add(dropped.actor);
let epoch = replica.epoch;
- let old = state.swap_document(&mut replica, epoch, fresh);
+ let old = state.swap_document(&mut replica, epoch, dropped.doc);
{
use crate::locks::MutexExt;
let mut screening = state.screening.lock_or_recover();
@@ -233,7 +187,7 @@ impl AppState {
// Before the document is let go: whoever reads it without the writes finds
// them quarantined.
crate::remake::quarantine_taken(&state, epoch, &old, paths);
- Some((own_paths, tainted.len()))
+ Some((own_paths, count))
})
.await
.ok()