@@ -15,7 +15,6 @@ import (
15
15
"unicode"
16
16
17
17
"github.com/cockroachdb/cockroach/pkg/cli/cliflags"
18
- "github.com/cockroachdb/cockroach/pkg/roachpb"
19
18
"github.com/cockroachdb/cockroach/pkg/storage/storageconfig"
20
19
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
21
20
"github.com/cockroachdb/errors"
@@ -50,72 +49,45 @@ func GetAbsoluteFSPath(fieldName string, p string) (string, error) {
50
49
return ret , nil
51
50
}
52
51
53
- // ProvisionedRateSpec is an optional part of the StoreSpec.
54
- type ProvisionedRateSpec struct {
55
- // ProvisionedBandwidth is the bandwidth provisioned for this store in bytes/s.
56
- ProvisionedBandwidth int64
57
- }
58
-
59
- func newStoreProvisionedRateSpec (
52
+ func parseStoreProvisionedRate (
60
53
field redact.SafeString , value string ,
61
- ) (ProvisionedRateSpec , error ) {
54
+ ) (storageconfig. ProvisionedRate , error ) {
62
55
split := strings .Split (value , "=" )
63
56
if len (split ) != 2 {
64
- return ProvisionedRateSpec {}, errors .Errorf ("%s field has invalid value %s" , field , value )
57
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field has invalid value %s" , field , value )
65
58
}
66
59
subField := split [0 ]
67
60
subValue := split [1 ]
68
61
if subField != "bandwidth" {
69
- return ProvisionedRateSpec {}, errors .Errorf ("%s field does not have bandwidth sub-field" , field )
62
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field does not have bandwidth sub-field" , field )
70
63
}
71
64
if len (subValue ) == 0 {
72
- return ProvisionedRateSpec {}, errors .Errorf ("%s field has no value specified for bandwidth" , field )
65
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field has no value specified for bandwidth" , field )
73
66
}
74
67
if len (subValue ) <= 2 || subValue [len (subValue )- 2 :] != "/s" {
75
- return ProvisionedRateSpec {},
68
+ return storageconfig. ProvisionedRate {},
76
69
errors .Errorf ("%s field does not have bandwidth sub-field %s ending in /s" ,
77
70
field , subValue )
78
71
}
79
72
bandwidthString := subValue [:len (subValue )- 2 ]
80
73
bandwidth , err := humanizeutil .ParseBytes (bandwidthString )
81
74
if err != nil {
82
- return ProvisionedRateSpec {},
75
+ return storageconfig. ProvisionedRate {},
83
76
errors .Wrapf (err , "could not parse bandwidth in field %s" , field )
84
77
}
85
78
if bandwidth == 0 {
86
- return ProvisionedRateSpec {},
79
+ return storageconfig. ProvisionedRate {},
87
80
errors .Errorf ("%s field is trying to set bandwidth to 0" , field )
88
81
}
89
- return ProvisionedRateSpec {ProvisionedBandwidth : bandwidth }, nil
82
+ return storageconfig. ProvisionedRate {ProvisionedBandwidth : bandwidth }, nil
90
83
}
91
84
92
85
// StoreSpec contains the details that can be specified in the cli pertaining
93
86
// to the --store flag.
94
- type StoreSpec struct {
95
- Path string
96
- Size storageconfig.SizeSpec
97
- BallastSize * storageconfig.SizeSpec
98
- InMemory bool
99
- Attributes roachpb.Attributes
100
- // StickyVFSID is a unique identifier associated with a given store which
101
- // will preserve the in-memory virtual file system (VFS) even after the
102
- // storage engine has been closed. This only applies to in-memory storage
103
- // engine.
104
- StickyVFSID string
105
- // PebbleOptions contains Pebble-specific options in the same format as a
106
- // Pebble OPTIONS file. For example:
107
- // [Options]
108
- // delete_range_flush_delay=2s
109
- // flush_split_bytes=4096
110
- PebbleOptions string
111
- // EncryptionOptions is set if encryption is enabled.
112
- EncryptionOptions * storageconfig.EncryptionOptions
113
- // ProvisionedRateSpec is optional.
114
- ProvisionedRateSpec ProvisionedRateSpec
115
- }
87
+ type StoreSpec = storageconfig.Store
116
88
117
- // String returns a fully parsable version of the store spec.
118
- func (ss StoreSpec ) String ( ) string {
89
+ // StoreSpecCmdLineString returns a fully parsable version of the store spec.
90
+ func StoreSpecCmdLineString (ss storageconfig. Store ) string {
119
91
// TODO(jackson): Implement redact.SafeFormatter
120
92
var buffer bytes.Buffer
121
93
if len (ss .Path ) != 0 {
@@ -124,23 +96,23 @@ func (ss StoreSpec) String() string {
124
96
if ss .InMemory {
125
97
fmt .Fprint (& buffer , "type=mem," )
126
98
}
127
- if ss .Size .Capacity > 0 {
128
- fmt .Fprintf (& buffer , "size=%s," , humanizeutil .IBytes (ss .Size .Capacity ))
99
+ if ss .Size .Bytes > 0 {
100
+ fmt .Fprintf (& buffer , "size=%s," , humanizeutil .IBytes (ss .Size .Bytes ))
129
101
}
130
102
if ss .Size .Percent > 0 {
131
103
fmt .Fprintf (& buffer , "size=%s%%," , humanize .Ftoa (ss .Size .Percent ))
132
104
}
133
105
if ss .BallastSize != nil {
134
- if ss .BallastSize .Capacity > 0 {
135
- fmt .Fprintf (& buffer , "ballast-size=%s," , humanizeutil .IBytes (ss .BallastSize .Capacity ))
106
+ if ss .BallastSize .Bytes > 0 {
107
+ fmt .Fprintf (& buffer , "ballast-size=%s," , humanizeutil .IBytes (ss .BallastSize .Bytes ))
136
108
}
137
109
if ss .BallastSize .Percent > 0 {
138
110
fmt .Fprintf (& buffer , "ballast-size=%s%%," , humanize .Ftoa (ss .BallastSize .Percent ))
139
111
}
140
112
}
141
- if len (ss .Attributes . Attrs ) > 0 {
113
+ if len (ss .Attributes ) > 0 {
142
114
fmt .Fprint (& buffer , "attrs=" )
143
- for i , attr := range ss .Attributes . Attrs {
115
+ for i , attr := range ss .Attributes {
144
116
if i != 0 {
145
117
fmt .Fprint (& buffer , ":" )
146
118
}
@@ -154,9 +126,9 @@ func (ss StoreSpec) String() string {
154
126
fmt .Fprint (& buffer , optsStr )
155
127
fmt .Fprint (& buffer , "," )
156
128
}
157
- if ss .ProvisionedRateSpec .ProvisionedBandwidth > 0 {
129
+ if ss .ProvisionedRate .ProvisionedBandwidth > 0 {
158
130
fmt .Fprintf (& buffer , "provisioned-rate=bandwidth=%s/s," ,
159
- humanizeutil .IBytes (ss .ProvisionedRateSpec .ProvisionedBandwidth ))
131
+ humanizeutil .IBytes (ss .ProvisionedRate .ProvisionedBandwidth ))
160
132
}
161
133
// Trim the extra comma from the end if it exists.
162
134
if l := buffer .Len (); l > 0 {
@@ -165,11 +137,6 @@ func (ss StoreSpec) String() string {
165
137
return buffer .String ()
166
138
}
167
139
168
- // IsEncrypted returns whether the StoreSpec has encryption enabled.
169
- func (ss StoreSpec ) IsEncrypted () bool {
170
- return ss .EncryptionOptions != nil
171
- }
172
-
173
140
// NewStoreSpec parses the string passed into a --store flag and returns a
174
141
// StoreSpec if it is correctly parsed.
175
142
// There are five possible fields that can be passed in, comma separated:
@@ -229,30 +196,22 @@ func NewStoreSpec(value string) (StoreSpec, error) {
229
196
ss .Path = value
230
197
case "size" :
231
198
var err error
232
- var minBytesAllowed int64 = MinimumStoreSize
233
- var minPercent float64 = 1
234
- var maxPercent float64 = 100
235
- ss .Size , err = storageconfig .NewSizeSpec (
236
- "store" ,
237
- value ,
238
- & storageconfig.IntInterval {Min : & minBytesAllowed },
239
- & storageconfig.FloatInterval {Min : & minPercent , Max : & maxPercent },
240
- )
199
+ constraints := storageconfig.SizeSpecConstraints {
200
+ MinBytes : MinimumStoreSize ,
201
+ MinPercent : 1 ,
202
+ MaxPercent : 100 ,
203
+ }
204
+ ss .Size , err = storageconfig .ParseSizeSpec (value , constraints )
241
205
if err != nil {
242
206
return StoreSpec {}, err
243
207
}
244
208
case "ballast-size" :
245
- var minBytesAllowed int64
246
- var minPercent float64 = 0
247
- var maxPercent float64 = 50
248
- ballastSize , err := storageconfig .NewSizeSpec (
249
- "ballast" ,
250
- value ,
251
- & storageconfig.IntInterval {Min : & minBytesAllowed },
252
- & storageconfig.FloatInterval {Min : & minPercent , Max : & maxPercent },
253
- )
209
+ constraints := storageconfig.SizeSpecConstraints {
210
+ MaxPercent : 50 ,
211
+ }
212
+ ballastSize , err := storageconfig .ParseSizeSpec (value , constraints )
254
213
if err != nil {
255
- return StoreSpec {}, err
214
+ return StoreSpec {}, errors . Wrap ( err , "ballast" )
256
215
}
257
216
ss .BallastSize = & ballastSize
258
217
case "attrs" :
@@ -265,9 +224,9 @@ func NewStoreSpec(value string) (StoreSpec, error) {
265
224
attrMap [attribute ] = struct {}{}
266
225
}
267
226
for attribute := range attrMap {
268
- ss .Attributes . Attrs = append (ss .Attributes . Attrs , attribute )
227
+ ss .Attributes = append (ss .Attributes , attribute )
269
228
}
270
- sort .Strings (ss .Attributes . Attrs )
229
+ sort .Strings (ss .Attributes )
271
230
case "type" :
272
231
if value == "mem" {
273
232
ss .InMemory = true
@@ -311,11 +270,11 @@ func NewStoreSpec(value string) (StoreSpec, error) {
311
270
}
312
271
ss .PebbleOptions = buf .String ()
313
272
case "provisioned-rate" :
314
- rateSpec , err := newStoreProvisionedRateSpec ("provisioned-rate" , value )
273
+ rateSpec , err := parseStoreProvisionedRate ("provisioned-rate" , value )
315
274
if err != nil {
316
275
return StoreSpec {}, err
317
276
}
318
- ss .ProvisionedRateSpec = rateSpec
277
+ ss .ProvisionedRate = rateSpec
319
278
320
279
default :
321
280
return StoreSpec {}, fmt .Errorf ("%s is not a valid store field" , field )
@@ -326,7 +285,7 @@ func NewStoreSpec(value string) (StoreSpec, error) {
326
285
if ss .Path != "" {
327
286
return StoreSpec {}, fmt .Errorf ("path specified for in memory store" )
328
287
}
329
- if ss .Size .Percent == 0 && ss .Size .Capacity == 0 {
288
+ if ss .Size .Percent == 0 && ss .Size .Bytes == 0 {
330
289
return StoreSpec {}, fmt .Errorf ("size must be specified for an in memory store" )
331
290
}
332
291
if ss .BallastSize != nil {
@@ -352,7 +311,7 @@ var _ pflag.Value = &StoreSpecList{}
352
311
func (ssl StoreSpecList ) String () string {
353
312
var buffer bytes.Buffer
354
313
for _ , ss := range ssl .Specs {
355
- fmt .Fprintf (& buffer , "--%s=%s " , cliflags .Store .Name , ss )
314
+ fmt .Fprintf (& buffer , "--%s=%s " , cliflags .Store .Name , StoreSpecCmdLineString ( ss ) )
356
315
}
357
316
// Trim the extra space from the end if it exists.
358
317
if l := buffer .Len (); l > 0 {
@@ -397,7 +356,10 @@ func (ssl StoreSpecList) PriorCriticalAlertError() (err error) {
397
356
err = errors .WithDetailf (err , "%v" , newErr )
398
357
}
399
358
for _ , ss := range ssl .Specs {
400
- path := ss .PreventedStartupFile ()
359
+ if ss .InMemory {
360
+ continue
361
+ }
362
+ path := PreventedStartupFile (filepath .Join (ss .Path , AuxiliaryDir ))
401
363
if path == "" {
402
364
continue
403
365
}
@@ -413,16 +375,6 @@ func (ssl StoreSpecList) PriorCriticalAlertError() (err error) {
413
375
return err
414
376
}
415
377
416
- // PreventedStartupFile returns the path to a file which, if it exists, should
417
- // prevent the server from starting up. Returns an empty string for in-memory
418
- // engines.
419
- func (ss StoreSpec ) PreventedStartupFile () string {
420
- if ss .InMemory {
421
- return ""
422
- }
423
- return PreventedStartupFile (filepath .Join (ss .Path , AuxiliaryDir ))
424
- }
425
-
426
378
// Type returns the underlying type in string form. This is part of pflag's
427
379
// value interface.
428
380
func (ssl * StoreSpecList ) Type () string {
0 commit comments