rust volume: saturate writes_since_checkpoint to prevent u32 overflow

If checkpoints keep failing (e.g. a persistent .dat flush failure whose
error is not EIO and so does not mark the volume read-only), the counter
increments on every write with no upper bound and wraps at ~4.3 billion.
Use saturating_add so it pins at u32::MAX instead, which keeps
checkpoint_due() true and retries on every subsequent write.

Co-Authored-By: Chris Lu <chris.lu@gmail.com>
This commit is contained in:
chrislusf
2026-09-05 13:14:39 -07:00
co-authored by Chris Lu
parent 242890124a
commit 1b3a8ca903
+2 -2
View File
@@ -792,7 +792,7 @@ impl RedbNeedleMap {
}
txn.commit()
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("redb commit: {}", e)))?;
self.writes_since_checkpoint += 1;
self.writes_since_checkpoint = self.writes_since_checkpoint.saturating_add(1);
self.metric.on_put(key, old.as_ref(), size);
Ok(())
@@ -866,7 +866,7 @@ impl RedbNeedleMap {
txn.commit().map_err(|e| {
io::Error::new(io::ErrorKind::Other, format!("redb commit: {}", e))
})?;
self.writes_since_checkpoint += 1;
self.writes_since_checkpoint = self.writes_since_checkpoint.saturating_add(1);
// Only now is the tombstone in the table the metrics describe.
self.metric.on_delete(&old);