sweepbatcher: remove all completed batches

Previously, if a completed batch was visited after a batch to which the
sweep was added, it was not deleted because the function returned early.

This has been separated into two loops: the first one removes completed batches,
and the second one adds the sweep to a batch.
This commit is contained in:
Boris Nagaev 2025-02-25 23:14:36 -03:00
parent a64f4610ab
commit a0f87241da
No known key found for this signature in database

View file

@ -590,16 +590,17 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
sweep.notifier = notifier
// This is a check to see if a batch is completed. In that case we just
// lazily delete it.
for _, batch := range b.batches {
if batch.isComplete() {
delete(b.batches, batch.id)
}
}
// Check if the sweep is already in a batch. If that is the case, we
// provide the sweep to that batch and return.
for _, batch := range b.batches {
// This is a check to see if a batch is completed. In that case
// we just lazily delete it and continue our scan.
if batch.isComplete() {
delete(b.batches, batch.id)
continue
}
if batch.sweepExists(sweep.swapHash) {
accepted, err := batch.addSweep(ctx, sweep)
if err != nil && !errors.Is(err, ErrBatchShuttingDown) {