fix(server): a refused batch counts toward a log's size, not toward a snapshot rewrite

This commit is contained in:
Dylan M. Taylor
2026-11-04 04:07:45 +00:00
parent 4bb35d5266
commit e9ec7564c2
2 changed files with 21 additions and 1 deletions
+3 -1
View File
@@ -68,7 +68,9 @@ impl Backend for Store {
Err(err) => log::error!("file {file}: a change couldn't be logged: {err}"),
}
}
log.entries += journal.len();
// A refusal changes nothing in the document: it counts toward the log's size (bytes), but
// not toward the entries that make a snapshot rewrite worthwhile.
log.entries += journal.iter().filter(|j| !matches!(j, figcraft_collab::Journal::Refused { .. })).count();
log.dirty = true;
e.meta.updated = now();
if log.entries >= after || log.bytes + log.pending.len() as u64 >= max_bytes {
+18
View File
@@ -155,6 +155,24 @@ fn read_only_sessions_keep_client_ids_without_rewriting_the_snapshot() {
}
}
#[test]
fn a_viewers_refused_batches_do_not_rewrite_the_snapshot() {
let dir = TempDir::new("refusals");
let c = StoreConfig { compact_after: 3, ..cfg(dir.path()) };
let mut store = Store::open(dir.path(), c).unwrap();
let (id, _, _) = publish(&mut store, "Busy");
let mut server = store.open(&id).unwrap();
let mut v = join(&mut server, Access::View);
store.changed(&id, &mut server);
let generation = || disk::check_snapshot(&fs::read(dir.path().join(FILES).join(&id).join(SNAPSHOT)).unwrap()).unwrap();
assert_eq!(generation(), 1);
for i in 0..10 {
rename(&mut server, &mut v, &format!("P{i}"));
store.changed(&id, &mut server);
}
assert_eq!(generation(), 1, "refusals are logged, not compacted");
}
#[test]
fn a_long_log_is_compacted_while_open() {
let dir = TempDir::new("compact");