From 07c8a8bcbc37174945d2640134e33f5e34336bc9 Mon Sep 17 00:00:00 2001 From: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> Date: Mon, 14 Apr 2025 11:27:56 +0200 Subject: [PATCH 1/3] chore: remove stale GatherWALFilesToArchive function Signed-off-by: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> --- pkg/archiver/command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/archiver/command.go b/pkg/archiver/command.go index a757f97a..5c1f0f08 100644 --- a/pkg/archiver/command.go +++ b/pkg/archiver/command.go @@ -97,7 +97,7 @@ func (archiver *WALArchiver) GatherWALFilesToArchive( return nil } - walList = append(walList, filepath.Join("pg_wal", walFileName)) + walList = append(walList, filepath.Join(pgWalDirectory, walFileName)) return nil }) From 8c690fcc818b97920cb9588222d03ea1de3b886e Mon Sep 17 00:00:00 2001 From: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> Date: Mon, 14 Apr 2025 11:39:16 +0200 Subject: [PATCH 2/3] chore: remove stale GatherWALFilesToArchive function Signed-off-by: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 111f05d2..5d11634a 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/cloudnative-pg/barman-cloud +module github.com/MichaluxPL/barman-cloud go 1.23.0 From ff75849ce58b0f5daec01ad5a4e2132848404458 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Wed, 16 Apr 2025 15:15:49 +0200 Subject: [PATCH 3/3] chore: review Signed-off-by: Leonardo Cecchi --- go.mod | 2 +- pkg/archiver/command.go | 85 ----------------------------------------- 2 files changed, 1 insertion(+), 86 deletions(-) diff --git a/go.mod b/go.mod index 5d11634a..111f05d2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/MichaluxPL/barman-cloud +module github.com/cloudnative-pg/barman-cloud go 1.23.0 diff --git a/pkg/archiver/command.go b/pkg/archiver/command.go index 5c1f0f08..d77aa7f1 100644 --- a/pkg/archiver/command.go +++ b/pkg/archiver/command.go @@ -18,98 +18,13 @@ package archiver import ( "context" - "errors" "fmt" - "math" - "os" - "path" - "path/filepath" - "strings" - - "github.com/cloudnative-pg/machinery/pkg/log" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command" "github.com/cloudnative-pg/barman-cloud/pkg/utils" ) -// GatherWALFilesToArchive reads from the archived status the list of WAL files -// that can be archived in parallel way. -// `requestedWALFile` is the name of the file whose archiving was requested by -// PostgreSQL, and that file is always the first of the list and is always included. -// `parallel` is the maximum number of WALs that we can archive in parallel -func (archiver *WALArchiver) GatherWALFilesToArchive( - ctx context.Context, - requestedWALFile string, - parallel int, -) (walList []string) { - contextLog := log.FromContext(ctx) - pgWalDirectory := path.Join(os.Getenv("PGDATA"), "pg_wal") - archiveStatusPath := path.Join(pgWalDirectory, "archive_status") - noMoreWALFilesNeeded := errors.New("no more files needed") - - // allocate parallel + 1 only if it does not overflow. Cap otherwise - var walListLength int - if parallel < math.MaxInt-1 { - walListLength = parallel + 1 - } else { - walListLength = math.MaxInt - 1 - } - // slightly more optimized, but equivalent to: - // walList = []string{requestedWALFile} - walList = make([]string, 1, walListLength) - walList[0] = requestedWALFile - - err := filepath.WalkDir(archiveStatusPath, func(path string, d os.DirEntry, err error) error { - // If err is set, it means the current path is a directory and the readdir raised an error - // The only available option here is to skip the path and log the error. - if err != nil { - contextLog.Error(err, "failed reading path", "path", path) - return filepath.SkipDir - } - - if len(walList) >= parallel { - return noMoreWALFilesNeeded - } - - // We don't process directories beside the archive status path - if d.IsDir() { - // We want to proceed exploring the archive status folder - if path == archiveStatusPath { - return nil - } - - return filepath.SkipDir - } - - // We only process ready files - if !strings.HasSuffix(path, ".ready") { - return nil - } - - walFileName := strings.TrimSuffix(filepath.Base(path), ".ready") - - // We are already archiving the requested WAL file, - // and we need to avoid archiving it twice. - // requestedWALFile is usually "pg_wal/wal_file_name" and - // we compare it with the path we read - if strings.HasSuffix(requestedWALFile, walFileName) { - return nil - } - - walList = append(walList, filepath.Join(pgWalDirectory, walFileName)) - return nil - }) - - // In this point err must be nil or noMoreWALFilesNeeded, if it is something different - // there is a programming error - if err != nil && err != noMoreWALFilesNeeded { - contextLog.Error(err, "unexpected error while reading the list of WAL files to archive") - } - - return walList -} - // BarmanCloudWalArchiveOptions calculates the set of options to be // used with barman-cloud-wal-archive func (archiver *WALArchiver) BarmanCloudWalArchiveOptions(