Make a timed batch write on every tick (closes #192)
check / check (push) Canceled after 0s

The prefix, AS and peer handlers skipped a timed write unless one
interval had passed since the last write ended. The next tick came a
little less than one interval after that, so every other tick was
skipped. Each tick now writes. A full batch's write restarts the timer,
so the next timed write comes one interval after that write began.
Comparing clock readings would not do: two ticks one interval apart can
read a hair under it. flushBatch no longer reports whether it wrote a
batch, since nothing reads that. A new test runs the loop on a fake
clock and fails on the old code.

Model: opus-5-5
This commit was merged in pull request #193.
This commit is contained in:
2026-10-27 15:23:52 +01:00
parent 05b39eee7a
commit 2c304a0022
6 changed files with 78 additions and 30 deletions
+3 -5
View File
@@ -200,11 +200,11 @@ func (h *PeerHandler) takeBatch() []peerUpdate {
}
// flushBatch takes the pending batch and writes it to the database, without
// holding the mutex during the write. It reports whether there was a batch.
func (h *PeerHandler) flushBatch() bool {
// holding the mutex during the write.
func (h *PeerHandler) flushBatch() {
batch := h.takeBatch()
if len(batch) == 0 {
return false
return
}
// The earliest and the latest time the batch saw each peer, with the peer
@@ -234,6 +234,4 @@ func (h *PeerHandler) flushBatch() bool {
h.mu.Lock()
h.writing = 0
h.mu.Unlock()
return true
}