diff --git a/pkg/walarchive/cmd.go b/pkg/walarchive/cmd.go index f3be5f3e..da539323 100644 --- a/pkg/walarchive/cmd.go +++ b/pkg/walarchive/cmd.go @@ -109,34 +109,43 @@ func (archiver *BarmanArchiver) ArchiveList( for idx := range walNames { waitGroup.Add(1) go func(walIndex int) { - walStatus := &result[walIndex] - walStatus.WalName = walNames[walIndex] - walStatus.StartTime = time.Now() - walStatus.Err = archiver.Archive(ctx, walNames[walIndex], options) - walStatus.EndTime = time.Now() - if walStatus.Err == nil && walIndex != 0 { - walStatus.Err = archiver.Touch(walNames[walIndex]) + defer waitGroup.Done() + + result[walIndex] = WALArchiverResult{ + WalName: walNames[walIndex], + StartTime: time.Now(), + Err: archiver.Archive(ctx, walNames[walIndex], options), + EndTime: time.Now(), } + walStatus := &result[walIndex] + + walContextLog := contextLog.WithValues( + "walName", walStatus.WalName, + "startTime", walStatus.StartTime, + "endTime", walStatus.EndTime, + "elapsedWalTime", walStatus.EndTime.Sub(walStatus.StartTime), + ) - elapsedWalTime := walStatus.EndTime.Sub(walStatus.StartTime) if walStatus.Err != nil { - contextLog.Warning( + walContextLog.Warning( "Failed archiving WAL: PostgreSQL will retry", - "walName", walStatus.WalName, - "startTime", walStatus.StartTime, - "endTime", walStatus.EndTime, - "elapsedWalTime", elapsedWalTime, "error", walStatus.Err) - } else { - contextLog.Info( - "Archived WAL file", - "walName", walStatus.WalName, - "startTime", walStatus.StartTime, - "endTime", walStatus.EndTime, - "elapsedWalTime", elapsedWalTime) + return + } + + if walIndex == 0 { + walContextLog.Info("Archived WAL file") + return + } + + if err := archiver.Touch(walNames[walIndex]); err != nil { + walContextLog.Warning( + "WAL file pre-archived, but it could not be added to the spool. PostgreSQL will retry", + "error", err) + return } - waitGroup.Done() + walContextLog.Info("Pre-archived WAL file (parallel)") }(idx) }