Skip to content

Commit fa5315a

Browse files
authored
[Badger] Don't busy wait when we're caught up (#725)
1 parent 6265f2e commit fa5315a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

storage/posix/antispam/badger.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (f *follower) Follow(ctx context.Context, lr tessera.LogReader) {
233233
var logSize uint64
234234

235235
// Busy loop while there's work to be done
236-
for workDone := true; workDone; {
236+
for moreWork := true; moreWork; {
237237
err := f.as.db.Update(func(txn *badger.Txn) error {
238238
ctx, span := tracer.Start(ctx, "tessera.antispam.badger.FollowTxn")
239239
defer span.End()
@@ -265,18 +265,19 @@ func (f *follower) Follow(ctx context.Context, lr tessera.LogReader) {
265265
if errors.Is(err, os.ErrNotExist) {
266266
// The log probably just hasn't completed its first integration yet, so break out of here
267267
// and go back to sleep for a bit to avoid spamming errors into the log and scaring operators.
268-
workDone = false
268+
moreWork = false
269269
return nil
270270
}
271271
return fmt.Errorf("populate: IntegratedSize(): %v", err)
272272
}
273273
switch {
274274
case followFrom > logSize:
275-
workDone = true
275+
// Since we've got a stale view, there could be more work to do - loop and check without sleeping.
276+
moreWork = true
276277
return fmt.Errorf("followFrom %d > size %d", followFrom, logSize)
277278
case followFrom == logSize:
278279
// We're caught up, so unblock pushback and go back to sleep
279-
workDone = true
280+
moreWork = false
280281
f.as.pushBack.Store(false)
281282
return nil
282283
default:

0 commit comments

Comments
 (0)