@@ -43,6 +43,9 @@ type ExternalPath struct {
43
43
Encryption * EncryptionOptions
44
44
}
45
45
46
+ // IsSet returns whether the path was provided.
47
+ func (e ExternalPath ) IsSet () bool { return e .Path != "" }
48
+
46
49
// WALFailover is the configuration for write-ahead log (WAL) failover, used
47
50
// to temporarily write WALs to a separate location when disk
48
51
// stalls are encountered.
@@ -62,10 +65,13 @@ type WALFailover struct {
62
65
PrevPath ExternalPath
63
66
}
64
67
65
- // Type implements the pflag.Value interface.
66
- func (c * WALFailover ) Type () string { return "string" }
67
-
68
68
// String implements fmt.Stringer.
69
+ //
70
+ // Representation:
71
+ // - DefaultMode: ""
72
+ // - Disabled: "disabled[,prev_path=<prev_path>]"
73
+ // - AmongStores: "among-stores"
74
+ // - ToExplicitPath: "path=<path>[,prev_path=<prev_path>]"
69
75
func (c * WALFailover ) String () string {
70
76
return redact .StringWithoutMarkers (c )
71
77
}
@@ -95,15 +101,18 @@ func (c *WALFailover) SafeFormat(p redact.SafePrinter, _ rune) {
95
101
}
96
102
}
97
103
98
- // Set implements the pflag.Value interface.
99
- func (c * WALFailover ) Set (s string ) error {
104
+ // ParseWALFailover parses a string in the format produced by String().
105
+ //
106
+ // Used to parse the --wal-failover command-line flag.
107
+ func ParseWALFailover (s string ) (WALFailover , error ) {
108
+ var c WALFailover
100
109
switch {
101
110
case strings .HasPrefix (s , "disabled" ):
102
111
c .Mode = WALFailoverDisabled
103
112
var ok bool
104
113
c .Path .Path , c .PrevPath .Path , ok = parseWALFailoverPathFields (strings .TrimPrefix (s , "disabled" ))
105
114
if ! ok || c .Path .IsSet () {
106
- return errors .Newf ("invalid disabled --wal-failover setting: %s " +
115
+ return WALFailover {}, errors .Newf ("invalid disabled --wal-failover setting: %s " +
107
116
"expect disabled[,prev_path=<prev_path>]" , s )
108
117
}
109
118
case s == "among-stores" :
@@ -113,14 +122,14 @@ func (c *WALFailover) Set(s string) error {
113
122
var ok bool
114
123
c .Path .Path , c .PrevPath .Path , ok = parseWALFailoverPathFields (s )
115
124
if ! ok || ! c .Path .IsSet () {
116
- return errors .Newf ("invalid path --wal-failover setting: %s " +
125
+ return WALFailover {}, errors .Newf ("invalid path --wal-failover setting: %s " +
117
126
"expect path=<path>[,prev_path=<prev_path>]" , s )
118
127
}
119
128
default :
120
- return errors .Newf ("invalid --wal-failover setting: %s " +
129
+ return WALFailover {}, errors .Newf ("invalid --wal-failover setting: %s " +
121
130
"(possible values: disabled, among-stores, path=<path>)" , s )
122
131
}
123
- return nil
132
+ return c , nil
124
133
}
125
134
126
135
func parseWALFailoverPathFields (s string ) (path , prevPath string , ok bool ) {
@@ -144,6 +153,3 @@ func parseWALFailoverPathFields(s string) (path, prevPath string, ok bool) {
144
153
prevPath = strings .TrimPrefix (s , ",prev_path=" )
145
154
return path , prevPath , true
146
155
}
147
-
148
- // IsSet returns whether or not the path was provided.
149
- func (e ExternalPath ) IsSet () bool { return e .Path != "" }
0 commit comments