Skip to content

Commit b874cd1

Browse files
fcanovaiarmru
andcommitted
fix: off by 1 error in parallel wal archive (cloudnative-pg#7389)
Fix an error in which the amount of workers archived in parallel was the wal the archive command was called on + the maxParallel, actually using one worker more than requested. Closes cloudnative-pg#7390 Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com> (cherry picked from commit 1db692d)
1 parent 8b2584c commit b874cd1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/management/postgres/archiver/archiver.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ func internalRun(
180180
return fmt.Errorf("failed to get envs: %w", err)
181181
}
182182

183-
maxParallel := 1
184-
if cluster.Spec.Backup.BarmanObjectStore.Wal != nil {
185-
maxParallel = cluster.Spec.Backup.BarmanObjectStore.Wal.MaxParallel
186-
}
187-
188183
// Create the archiver
189184
var walArchiver *barmanArchiver.WALArchiver
190185
if walArchiver, err = barmanArchiver.New(
@@ -210,7 +205,7 @@ func internalRun(
210205
return fmt.Errorf("while testing the existence of the WAL file in the spool directory: %w", err)
211206
}
212207
if isDeletedFromSpool {
213-
contextLog.Info("Archived WAL file (parallel)",
208+
contextLog.Info("WAL file already archived, skipping",
214209
"walName", walName,
215210
"currentPrimary", cluster.Status.CurrentPrimary,
216211
"targetPrimary", cluster.Status.TargetPrimary)
@@ -221,7 +216,7 @@ func internalRun(
221216
walFilesList := walUtils.GatherReadyWALFiles(
222217
ctx,
223218
walUtils.GatherReadyWALFilesConfig{
224-
MaxResults: maxParallel,
219+
MaxResults: getMaxResult(cluster),
225220
SkipWALs: []string{walName},
226221
PgDataPath: pgData,
227222
},
@@ -230,6 +225,7 @@ func internalRun(
230225
// Ensure the requested WAL file is always the first one being
231226
// archived
232227
walFilesList.Ready = append([]string{walName}, walFilesList.Ready...)
228+
contextLog.Debug("WAL files to archive", "walFilesListReady", walFilesList.Ready)
233229

234230
options, err := walArchiver.BarmanCloudWalArchiveOptions(
235231
ctx, cluster.Spec.Backup.BarmanObjectStore, cluster.Name)
@@ -256,6 +252,13 @@ func internalRun(
256252
return walStatus[0].Err
257253
}
258254

255+
func getMaxResult(cluster *apiv1.Cluster) int {
256+
if cluster.Spec.Backup.BarmanObjectStore.Wal != nil && cluster.Spec.Backup.BarmanObjectStore.Wal.MaxParallel > 0 {
257+
return cluster.Spec.Backup.BarmanObjectStore.Wal.MaxParallel - 1
258+
}
259+
return 0
260+
}
261+
259262
// archiveWALViaPlugins requests every capable plugin to archive the passed
260263
// WAL file, and returns an error if a configured plugin fails to do so.
261264
// It will not return an error if there's no plugin capable of WAL archiving

0 commit comments

Comments
 (0)