/
configure.go
41 lines (33 loc) · 1.14 KB
/
configure.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
package greenplum
import (
"fmt"
"strconv"
"github.com/greenplum-db/gp-common-go-libs/gplog"
"github.com/apecloud/dataprotection-wal-g/internal"
"github.com/spf13/viper"
)
func SetSegmentStoragePrefix(contentID int) {
viper.Set(internal.StoragePrefixSetting, FormatSegmentStoragePrefix(contentID))
}
func ConfigureSegContentID(contentIDFlag string) (int, error) {
var rawContentID string
if contentIDFlag != "" {
rawContentID = contentIDFlag
} else if contentIDSetting, ok := internal.GetSetting(internal.GPSegContentID); ok {
rawContentID = contentIDSetting
} else {
return 0, fmt.Errorf("segment content ID is not specified, add the --content-id flag or use the %s setting", internal.GPSegContentID)
}
contentID, err := strconv.Atoi(rawContentID)
if err != nil {
return 0, fmt.Errorf("failed to parse the segment content ID: %v", err)
}
return contentID, nil
}
// initGpLog is required for gp-common-go library to function properly
func initGpLog(logsDir string) {
gplog.SetLogFileNameFunc(func(program, logdir string) string {
return fmt.Sprintf("%s/%s-gplog.log", logdir, program)
})
gplog.InitializeLogging("wal-g", logsDir)
}