retryBatch retries writing a batch up to maxRetries times with a fixed delay between attempts. If the batcher context is canceled during a wait, one final attempt is made before returning.
(params database.BatchUpsertConnectionLogsParams)
| 466 | // fixed delay between attempts. If the batcher context is canceled |
| 467 | // during a wait, one final attempt is made before returning. |
| 468 | func (b *DBBatcher) retryBatch(params database.BatchUpsertConnectionLogsParams) { |
| 469 | count := len(params.ID) |
| 470 | for attempt := range maxRetries { |
| 471 | t := b.clock.NewTimer(retryInterval, "connectionLogBatcher", "retryBackoff") |
| 472 | select { |
| 473 | case <-b.ctx.Done(): |
| 474 | t.Stop() |
| 475 | b.shutdownBatch(params) |
| 476 | return |
| 477 | case <-t.C: |
| 478 | } |
| 479 | |
| 480 | //nolint:gocritic // System-level batch operation for connection logs. |
| 481 | err := b.store.BatchUpsertConnectionLogs(dbauthz.AsConnectionLogger(b.ctx), params) |
| 482 | if err == nil { |
| 483 | return |
| 484 | } |
| 485 | |
| 486 | b.log.Warn(b.ctx, "batch retry failed", |
| 487 | slog.Error(err), |
| 488 | slog.F("count", count), |
| 489 | slog.F("attempt", attempt+1), |
| 490 | slog.F("max_attempts", maxRetries), |
| 491 | ) |
| 492 | } |
| 493 | |
| 494 | b.log.Error(b.ctx, "batch retries exhausted, dropping batch", |
| 495 | slog.F("dropped", count)) |
| 496 | } |
| 497 | |
| 498 | // shutdownBatch makes a single write attempt during shutdown with a |
| 499 | // bounded timeout so it can't hang indefinitely. |
no test coverage detected