Skip to content

Commit 6a7d21e

Browse files
chore: remove stale GatherWALFilesToArchive function (#111)
Signed-off-by: MichaluxPL <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
1 parent 99a3100 commit 6a7d21e

File tree

1 file changed

+0
-85
lines changed

1 file changed

+0
-85
lines changed

pkg/archiver/command.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,98 +18,13 @@ package archiver
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
23-
"math"
24-
"os"
25-
"path"
26-
"path/filepath"
27-
"strings"
28-
29-
"github.com/cloudnative-pg/machinery/pkg/log"
3022

3123
barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api"
3224
barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
3325
"github.com/cloudnative-pg/barman-cloud/pkg/utils"
3426
)
3527

36-
// GatherWALFilesToArchive reads from the archived status the list of WAL files
37-
// that can be archived in parallel way.
38-
// `requestedWALFile` is the name of the file whose archiving was requested by
39-
// PostgreSQL, and that file is always the first of the list and is always included.
40-
// `parallel` is the maximum number of WALs that we can archive in parallel
41-
func (archiver *WALArchiver) GatherWALFilesToArchive(
42-
ctx context.Context,
43-
requestedWALFile string,
44-
parallel int,
45-
) (walList []string) {
46-
contextLog := log.FromContext(ctx)
47-
pgWalDirectory := path.Join(os.Getenv("PGDATA"), "pg_wal")
48-
archiveStatusPath := path.Join(pgWalDirectory, "archive_status")
49-
noMoreWALFilesNeeded := errors.New("no more files needed")
50-
51-
// allocate parallel + 1 only if it does not overflow. Cap otherwise
52-
var walListLength int
53-
if parallel < math.MaxInt-1 {
54-
walListLength = parallel + 1
55-
} else {
56-
walListLength = math.MaxInt - 1
57-
}
58-
// slightly more optimized, but equivalent to:
59-
// walList = []string{requestedWALFile}
60-
walList = make([]string, 1, walListLength)
61-
walList[0] = requestedWALFile
62-
63-
err := filepath.WalkDir(archiveStatusPath, func(path string, d os.DirEntry, err error) error {
64-
// If err is set, it means the current path is a directory and the readdir raised an error
65-
// The only available option here is to skip the path and log the error.
66-
if err != nil {
67-
contextLog.Error(err, "failed reading path", "path", path)
68-
return filepath.SkipDir
69-
}
70-
71-
if len(walList) >= parallel {
72-
return noMoreWALFilesNeeded
73-
}
74-
75-
// We don't process directories beside the archive status path
76-
if d.IsDir() {
77-
// We want to proceed exploring the archive status folder
78-
if path == archiveStatusPath {
79-
return nil
80-
}
81-
82-
return filepath.SkipDir
83-
}
84-
85-
// We only process ready files
86-
if !strings.HasSuffix(path, ".ready") {
87-
return nil
88-
}
89-
90-
walFileName := strings.TrimSuffix(filepath.Base(path), ".ready")
91-
92-
// We are already archiving the requested WAL file,
93-
// and we need to avoid archiving it twice.
94-
// requestedWALFile is usually "pg_wal/wal_file_name" and
95-
// we compare it with the path we read
96-
if strings.HasSuffix(requestedWALFile, walFileName) {
97-
return nil
98-
}
99-
100-
walList = append(walList, filepath.Join("pg_wal", walFileName))
101-
return nil
102-
})
103-
104-
// In this point err must be nil or noMoreWALFilesNeeded, if it is something different
105-
// there is a programming error
106-
if err != nil && err != noMoreWALFilesNeeded {
107-
contextLog.Error(err, "unexpected error while reading the list of WAL files to archive")
108-
}
109-
110-
return walList
111-
}
112-
11328
// BarmanCloudWalArchiveOptions calculates the set of options to be
11429
// used with barman-cloud-wal-archive
11530
func (archiver *WALArchiver) BarmanCloudWalArchiveOptions(

0 commit comments

Comments
 (0)