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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user