Skip to content

Commit 82abd2b

Browse files
fcanovaiarmru
andauthored
refactor: clarify logging for parallel WAL archiving (#113)
Differentiate between the WAL archived and the ones pre-archived by the parallel workers. Signed-off-by: Francesco Canovai <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
1 parent 6a7d21e commit 82abd2b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

pkg/walarchive/cmd.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,43 @@ func (archiver *BarmanArchiver) ArchiveList(
109109
for idx := range walNames {
110110
waitGroup.Add(1)
111111
go func(walIndex int) {
112-
walStatus := &result[walIndex]
113-
walStatus.WalName = walNames[walIndex]
114-
walStatus.StartTime = time.Now()
115-
walStatus.Err = archiver.Archive(ctx, walNames[walIndex], options)
116-
walStatus.EndTime = time.Now()
117-
if walStatus.Err == nil && walIndex != 0 {
118-
walStatus.Err = archiver.Touch(walNames[walIndex])
112+
defer waitGroup.Done()
113+
114+
result[walIndex] = WALArchiverResult{
115+
WalName: walNames[walIndex],
116+
StartTime: time.Now(),
117+
Err: archiver.Archive(ctx, walNames[walIndex], options),
118+
EndTime: time.Now(),
119119
}
120+
walStatus := &result[walIndex]
121+
122+
walContextLog := contextLog.WithValues(
123+
"walName", walStatus.WalName,
124+
"startTime", walStatus.StartTime,
125+
"endTime", walStatus.EndTime,
126+
"elapsedWalTime", walStatus.EndTime.Sub(walStatus.StartTime),
127+
)
120128

121-
elapsedWalTime := walStatus.EndTime.Sub(walStatus.StartTime)
122129
if walStatus.Err != nil {
123-
contextLog.Warning(
130+
walContextLog.Warning(
124131
"Failed archiving WAL: PostgreSQL will retry",
125-
"walName", walStatus.WalName,
126-
"startTime", walStatus.StartTime,
127-
"endTime", walStatus.EndTime,
128-
"elapsedWalTime", elapsedWalTime,
129132
"error", walStatus.Err)
130-
} else {
131-
contextLog.Info(
132-
"Archived WAL file",
133-
"walName", walStatus.WalName,
134-
"startTime", walStatus.StartTime,
135-
"endTime", walStatus.EndTime,
136-
"elapsedWalTime", elapsedWalTime)
133+
return
134+
}
135+
136+
if walIndex == 0 {
137+
walContextLog.Info("Archived WAL file")
138+
return
139+
}
140+
141+
if err := archiver.Touch(walNames[walIndex]); err != nil {
142+
walContextLog.Warning(
143+
"WAL file pre-archived, but it could not be added to the spool. PostgreSQL will retry",
144+
"error", err)
145+
return
137146
}
138147

139-
waitGroup.Done()
148+
walContextLog.Info("Pre-archived WAL file (parallel)")
140149
}(idx)
141150
}
142151

0 commit comments

Comments
 (0)