aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/records.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 18:39:31 +0100
committertv <tv@krebsco.de>2026-10-31 18:39:31 +0100
commit4a6403d0242cf730a3f864c8d26e0ba15a98fcf0 (patch)
treefddd3aee30d2874c8bb07dad29731892a1ff610a /src/remake/records.rs
parent88b3d05543561d5a34a4ff96b9a8ca9351e1a98d (diff)
remake coordination use document, not automerge
Diffstat (limited to 'src/remake/records.rs')
-rw-r--r--src/remake/records.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/remake/records.rs b/src/remake/records.rs
index 463d085..f22b1e5 100644
--- a/src/remake/records.rs
+++ b/src/remake/records.rs
@@ -28,7 +28,6 @@
use std::collections::BTreeMap;
-use automerge::{AutoCommit, ChangeHash};
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use tracing::warn;
@@ -39,6 +38,7 @@ use crate::clock::UnixMillis;
use crate::document::meta::{self, REMAKES, VOTES};
use crate::document::replica::Epoch;
use crate::document::store::{self, StoreError};
+use crate::document::{ChangeHash, Document};
/// One day, for retention defaults.
const DAY_MS: u64 = 24 * 60 * 60 * 1000;
@@ -337,13 +337,13 @@ pub(crate) fn record_path(id: &str, part: &str) -> Vec<String> {
}
/// The record with this ID, if it exists and is readable, with its votes.
-pub(crate) fn load(doc: &AutoCommit, id: &str) -> Option<Record> {
+pub(crate) fn load(doc: &Document, id: &str) -> Option<Record> {
let record = load_record(doc, id)?;
Some(with_votes(id, record, &load_register(doc)))
}
/// All readable records, with their votes.
-pub(crate) fn load_all(doc: &AutoCommit) -> Vec<(String, Record)> {
+pub(crate) fn load_all(doc: &Document) -> Vec<(String, Record)> {
let register = load_register(doc);
store::keys_at(doc, &records_dir())
.unwrap_or_default()
@@ -366,7 +366,7 @@ fn with_votes(id: &str, mut record: Record, register: &Register) -> Record {
record
}
-fn load_record(doc: &AutoCommit, id: &str) -> Option<Record> {
+fn load_record(doc: &Document, id: &str) -> Option<Record> {
let value = match store::read_path(doc, &record_path(id, "")) {
Ok(Some(value)) => value,
Ok(None) => return None,
@@ -390,7 +390,7 @@ fn load_record(doc: &AutoCommit, id: &str) -> Option<Record> {
}
/// A commit among concurrent decisions of remake `id` that disagree, if they do.
-fn contested_decision(doc: &AutoCommit, id: &str) -> Option<Decision> {
+fn contested_decision(doc: &Document, id: &str) -> Option<Decision> {
let decisions: Vec<Decision> = store::read_candidates(doc, &record_path(id, "decision"))
.ok()?
.into_iter()
@@ -418,7 +418,7 @@ fn register_path(voter: &str) -> Vec<String> {
}
/// The votes register; unreadable entries are skipped with a warning.
-pub(crate) fn load_register(doc: &AutoCommit) -> Register {
+pub(crate) fn load_register(doc: &Document) -> Register {
store::keys_at(doc, &meta::path(&[VOTES]))
.unwrap_or_default()
.into_iter()
@@ -446,7 +446,7 @@ pub(crate) fn load_register(doc: &AutoCommit) -> Register {
}
fn write_part<T: Serialize>(
- doc: &mut AutoCommit,
+ doc: &mut Document,
id: &str,
part: &str,
value: &T,
@@ -456,7 +456,7 @@ fn write_part<T: Serialize>(
}
pub(crate) fn write_proposal(
- doc: &mut AutoCommit,
+ doc: &mut Document,
id: &str,
proposal: &Proposal,
) -> Result<(), StoreError> {
@@ -464,7 +464,7 @@ pub(crate) fn write_proposal(
}
pub(crate) fn write_decision(
- doc: &mut AutoCommit,
+ doc: &mut Document,
id: &str,
decision: &Decision,
) -> Result<(), StoreError> {
@@ -472,7 +472,7 @@ pub(crate) fn write_decision(
}
pub(crate) fn write_abort_request(
- doc: &mut AutoCommit,
+ doc: &mut Document,
id: &str,
request: &AbortRequest,
) -> Result<(), StoreError> {
@@ -480,7 +480,7 @@ pub(crate) fn write_abort_request(
}
/// Writes `voter`'s entry in the votes register (replacing its earlier one).
-pub(crate) fn write_vote(doc: &mut AutoCommit, voter: &str, vote: &Vote) -> Result<(), StoreError> {
+pub(crate) fn write_vote(doc: &mut Document, voter: &str, vote: &Vote) -> Result<(), StoreError> {
let json = serde_json::to_value(vote).map_err(anyhow::Error::from)?;
store::write_path(doc, &register_path(voter), &json)
}
@@ -568,7 +568,7 @@ mod tests {
#[test]
fn round_trip_through_the_document() {
- let mut doc = AutoCommit::new();
+ let mut doc = Document::new();
let p = proposal(10_000);
write_proposal(&mut doc, "c-1", &p).unwrap();
write_abort_request(
@@ -612,7 +612,7 @@ mod tests {
#[test]
fn concurrent_votes_are_kept_apart() {
- let mut a = AutoCommit::new();
+ let mut a = Document::new();
let vote = |remake: &str, at: u64| Vote {
remake: remake.into(),
at: UnixMillis(at),
@@ -685,7 +685,7 @@ mod tests {
#[test]
fn disagreeing_decisions_are_contested() {
- let mut base = AutoCommit::new();
+ let mut base = Document::new();
write_proposal(&mut base, "c-1", &proposal(10_000)).unwrap();
base.commit();
let (mut a, mut b, mut c) = (base.fork(), base.fork(), base.fork());
@@ -725,7 +725,7 @@ mod tests {
#[test]
fn unreadable_records_are_skipped() {
- let mut doc = AutoCommit::new();
+ let mut doc = Document::new();
store::write_path(
&mut doc,
&record_path("broken", ""),