fix: wal archive - early return if WAL was in spool #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the
WALServiceImplementation.Archivemethod by introducing a local spool-based check to prevent redundant WAL uploads. This is particularly relevant when maxParallel is set to a value greater than 1.Similar to how its implemented in
plugin-barman-cloud: https://github.com/cloudnative-pg/plugin-barman-cloud/blob/b7b2b5b78755d4fcd7242100cd79df3095b58174/internal/cnpgi/common/wal.go#L177The Problem
When
maxParallel> 1, pgBackRest attempts to archive the requested WAL segment plus the next N−1 segments speculatively. However, PostgreSQL issues WALArchiveRequest calls sequentially (WAL 1, then WAL 2, then WAL 3).Under the previous implementation, this created a "sliding window" of redundant work:
This resulted in unnecessary network overhead and frequent warnings in the logs regarding files already existing in the repository with the same checksum.
Changes
Added a check against the spool in
WALServiceImplementation.Archive. If a WAL segment is already marked as completed in the local spool, the plugin returns a success response immediately without invoking the pgBackRest binary.