From 1b3a8ca903b549878112421bf412bf5898dce8d8 Mon Sep 17 00:00:00 2001 From: chrislusf Date: Sat, 5 Sep 2026 13:14:39 -0700 Subject: [PATCH] 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 --- seaweed-volume/src/storage/needle_map.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-volume/src/storage/needle_map.rs b/seaweed-volume/src/storage/needle_map.rs index 34828dcda..c541f665a 100644 --- a/seaweed-volume/src/storage/needle_map.rs +++ b/seaweed-volume/src/storage/needle_map.rs @@ -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);