forked from wal-g/wal-g
/
ao_storage.go
77 lines (63 loc) · 2.09 KB
/
ao_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package greenplum
import (
"fmt"
"strings"
"github.com/T0n0T/wal-g/internal"
"github.com/T0n0T/wal-g/internal/walparser"
"github.com/wal-g/tracelog"
"github.com/T0n0T/wal-g/pkg/storages/storage"
)
const (
AoStoragePath = "aosegments"
AoSegSuffix = "_aoseg"
AoSegDeltaDelimiter = "_D_"
)
func makeAoFileStorageKey(relNameMd5 string, modCount int64, location *walparser.BlockLocation) string {
return fmt.Sprintf("%d_%d_%s_%d_%d_%d%s",
location.RelationFileNode.SpcNode, location.RelationFileNode.DBNode,
relNameMd5,
location.RelationFileNode.RelNode, location.BlockNo,
modCount, AoSegSuffix)
}
func makeDeltaAoFileStorageKey(baseKey string, modCount int64) string {
trimmedKey := strings.TrimSuffix(baseKey, AoSegSuffix)
return fmt.Sprintf("%s%s%d%s", trimmedKey, AoSegDeltaDelimiter, modCount, AoSegSuffix)
}
// LoadStorageAoFiles loads the list of the AO/AOCS segment files that are referenced from previous backups
func LoadStorageAoFiles(baseBackupsFolder storage.Folder) (map[string]struct{}, error) {
aoSegments := make(map[string]struct{}, 0)
iterateFunc := func(_ string, desc BackupAOFileDesc) {
aoSegments[desc.StoragePath] = struct{}{}
}
err := iterateStorageAoFilesWithFunc(baseBackupsFolder, iterateFunc)
if err != nil {
return nil, err
}
return aoSegments, nil
}
func iterateStorageAoFilesWithFunc(baseBackupsFolder storage.Folder, iterateFunc func(string, BackupAOFileDesc)) error {
backupObjects, _, err := baseBackupsFolder.ListFolder()
if err != nil {
return err
}
backupTimes := internal.GetBackupTimeSlices(backupObjects)
if err != nil {
return err
}
for _, b := range backupTimes {
backup := NewSegBackup(baseBackupsFolder, b.BackupName)
aoMeta, err := backup.LoadAoFilesMetadata()
if err != nil {
if _, ok := err.(storage.ObjectNotFoundError); ok {
tracelog.WarningLogger.Printf("No AO files metadata found for backup %s in folder %s, skipping",
backup.Name, baseBackupsFolder.GetPath())
continue
}
return err
}
for localPath, fileDesc := range aoMeta.Files {
iterateFunc(localPath, fileDesc)
}
}
return nil
}