Skip to content

Commit b8cd014

Browse files
committed
storageconf: support YAML
Add support for marshaling `storageconfig.Store` as yaml and parsing it back. This is in support of switching from command-line flags to a configuration file. Size is now a tri-state that differentiates between unset or set to 0 bytes. We also clean up some of the related code and move the validation of a store config into `storageconfig`. This PR does not cover marshaling/unmarshaling of encryption options; this will be in a follow-up PR. Epic: none Release note: None
1 parent 36e539b commit b8cd014

23 files changed

+702
-270
lines changed

pkg/acceptance/cluster/dockercluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ func (l *DockerCluster) startNode(ctx context.Context, node *testNode, singleNod
485485
for _, store := range node.stores {
486486
storeSpec := base.StoreSpec{
487487
Path: store.dir,
488-
Size: storageconfig.Size{Bytes: int64(store.config.MaxRanges) * maxRangeBytes},
488+
}
489+
if store.config.MaxRanges != 0 {
490+
storeSpec.Size = storageconfig.BytesSize(int64(store.config.MaxRanges) * maxRangeBytes)
489491
}
490492
cmd = append(cmd, fmt.Sprintf("--store=%s", base.StoreSpecCmdLineString(storeSpec)))
491493
}

pkg/base/store_spec.go

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,13 @@ import (
2020
"github.com/cockroachdb/errors"
2121
"github.com/cockroachdb/errors/oserror"
2222
"github.com/cockroachdb/pebble"
23-
"github.com/cockroachdb/redact"
24-
humanize "github.com/dustin/go-humanize"
23+
"github.com/dustin/go-humanize"
2524
"github.com/spf13/pflag"
2625
)
2726

2827
// This file implements method receivers for server.Config struct
2928
// -- 'Stores', which satisfies pflag's value interface
3029

31-
// MinimumStoreSize is the smallest size in bytes that a store can have. This
32-
// number is based on config's defaultZoneConfig's RangeMaxBytes, which is
33-
// extremely stable. To avoid adding the dependency on config here, it is just
34-
// hard coded to 640MiB.
35-
const MinimumStoreSize = 10 * 64 << 20
36-
3730
// GetAbsoluteFSPath takes a (possibly relative) and returns the absolute path.
3831
// Returns an error if the path begins with '~' or Abs fails.
3932
// 'fieldName' is used in error strings.
@@ -49,39 +42,6 @@ func GetAbsoluteFSPath(fieldName string, p string) (string, error) {
4942
return ret, nil
5043
}
5144

52-
func parseStoreProvisionedRate(
53-
field redact.SafeString, value string,
54-
) (storageconfig.ProvisionedRate, error) {
55-
split := strings.Split(value, "=")
56-
if len(split) != 2 {
57-
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field has invalid value %s", field, value)
58-
}
59-
subField := split[0]
60-
subValue := split[1]
61-
if subField != "bandwidth" {
62-
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field does not have bandwidth sub-field", field)
63-
}
64-
if len(subValue) == 0 {
65-
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field has no value specified for bandwidth", field)
66-
}
67-
if len(subValue) <= 2 || subValue[len(subValue)-2:] != "/s" {
68-
return storageconfig.ProvisionedRate{},
69-
errors.Errorf("%s field does not have bandwidth sub-field %s ending in /s",
70-
field, subValue)
71-
}
72-
bandwidthString := subValue[:len(subValue)-2]
73-
bandwidth, err := humanizeutil.ParseBytes(bandwidthString)
74-
if err != nil {
75-
return storageconfig.ProvisionedRate{},
76-
errors.Wrapf(err, "could not parse bandwidth in field %s", field)
77-
}
78-
if bandwidth == 0 {
79-
return storageconfig.ProvisionedRate{},
80-
errors.Errorf("%s field is trying to set bandwidth to 0", field)
81-
}
82-
return storageconfig.ProvisionedRate{ProvisionedBandwidth: bandwidth}, nil
83-
}
84-
8545
// StoreSpec contains the details that can be specified in the cli pertaining
8646
// to the --store flag.
8747
type StoreSpec = storageconfig.Store
@@ -96,19 +56,15 @@ func StoreSpecCmdLineString(ss storageconfig.Store) string {
9656
if ss.InMemory {
9757
fmt.Fprint(&buffer, "type=mem,")
9858
}
99-
if ss.Size.Bytes > 0 {
100-
fmt.Fprintf(&buffer, "size=%s,", humanizeutil.IBytes(ss.Size.Bytes))
59+
if ss.Size.IsBytes() {
60+
fmt.Fprintf(&buffer, "size=%s,", humanizeutil.IBytes(ss.Size.Bytes()))
61+
} else if ss.Size.IsPercent() {
62+
fmt.Fprintf(&buffer, "size=%s%%,", humanize.Ftoa(ss.Size.Percent()))
10163
}
102-
if ss.Size.Percent > 0 {
103-
fmt.Fprintf(&buffer, "size=%s%%,", humanize.Ftoa(ss.Size.Percent))
104-
}
105-
if ss.BallastSize != nil {
106-
if ss.BallastSize.Bytes > 0 {
107-
fmt.Fprintf(&buffer, "ballast-size=%s,", humanizeutil.IBytes(ss.BallastSize.Bytes))
108-
}
109-
if ss.BallastSize.Percent > 0 {
110-
fmt.Fprintf(&buffer, "ballast-size=%s%%,", humanize.Ftoa(ss.BallastSize.Percent))
111-
}
64+
if ss.BallastSize.IsBytes() {
65+
fmt.Fprintf(&buffer, "ballast-size=%s,", humanizeutil.IBytes(ss.BallastSize.Bytes()))
66+
} else if ss.BallastSize.IsPercent() {
67+
fmt.Fprintf(&buffer, "ballast-size=%s%%,", humanize.Ftoa(ss.BallastSize.Percent()))
11268
}
11369
if len(ss.Attributes) > 0 {
11470
fmt.Fprint(&buffer, "attrs=")
@@ -196,24 +152,16 @@ func NewStoreSpec(value string) (StoreSpec, error) {
196152
ss.Path = value
197153
case "size":
198154
var err error
199-
constraints := storageconfig.SizeSpecConstraints{
200-
MinBytes: MinimumStoreSize,
201-
MinPercent: 1,
202-
MaxPercent: 100,
203-
}
204-
ss.Size, err = storageconfig.ParseSizeSpec(value, constraints)
155+
ss.Size, err = storageconfig.ParseSizeSpec(value)
205156
if err != nil {
206157
return StoreSpec{}, err
207158
}
208159
case "ballast-size":
209-
constraints := storageconfig.SizeSpecConstraints{
210-
MaxPercent: 50,
211-
}
212-
ballastSize, err := storageconfig.ParseSizeSpec(value, constraints)
160+
ballastSize, err := storageconfig.ParseSizeSpec(value)
213161
if err != nil {
214162
return StoreSpec{}, errors.Wrap(err, "ballast")
215163
}
216-
ss.BallastSize = &ballastSize
164+
ss.BallastSize = ballastSize
217165
case "attrs":
218166
// Check to make sure there are no duplicate attributes.
219167
attrMap := make(map[string]struct{})
@@ -270,7 +218,7 @@ func NewStoreSpec(value string) (StoreSpec, error) {
270218
}
271219
ss.PebbleOptions = buf.String()
272220
case "provisioned-rate":
273-
rateSpec, err := parseStoreProvisionedRate("provisioned-rate", value)
221+
rateSpec, err := storageconfig.ParseProvisionedRate(value)
274222
if err != nil {
275223
return StoreSpec{}, err
276224
}
@@ -280,19 +228,8 @@ func NewStoreSpec(value string) (StoreSpec, error) {
280228
return StoreSpec{}, fmt.Errorf("%s is not a valid store field", field)
281229
}
282230
}
283-
if ss.InMemory {
284-
// Only in memory stores don't need a path and require a size.
285-
if ss.Path != "" {
286-
return StoreSpec{}, fmt.Errorf("path specified for in memory store")
287-
}
288-
if ss.Size.Percent == 0 && ss.Size.Bytes == 0 {
289-
return StoreSpec{}, fmt.Errorf("size must be specified for an in memory store")
290-
}
291-
if ss.BallastSize != nil {
292-
return StoreSpec{}, fmt.Errorf("ballast-size specified for in memory store")
293-
}
294-
} else if ss.Path == "" {
295-
return StoreSpec{}, fmt.Errorf("no path specified")
231+
if err := ss.Validate(); err != nil {
232+
return StoreSpec{}, err
296233
}
297234
return ss, nil
298235
}

pkg/base/store_spec_test.go

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -92,53 +92,53 @@ target_file_size=2097152`
9292
{"path=/mnt/hda1,attrs=hdd,attrs=ssd", "attrs field was used twice in store definition", StoreSpec{}},
9393

9494
// size
95-
{"path=/mnt/hda1,size=671088640", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 671088640}}},
96-
{"path=/mnt/hda1,size=20GB", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 20000000000}}},
97-
{"size=20GiB,path=/mnt/hda1", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 21474836480}}},
98-
{"size=0.1TiB,path=/mnt/hda1", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 109951162777}}},
99-
{"path=/mnt/hda1,size=.1TiB", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 109951162777}}},
100-
{"path=/mnt/hda1,size=123TB", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 123000000000000}}},
101-
{"path=/mnt/hda1,size=123TiB", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Bytes: 135239930216448}}},
95+
{"path=/mnt/hda1,size=671088640", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(671088640)}},
96+
{"path=/mnt/hda1,size=20GB", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(20000000000)}},
97+
{"size=20GiB,path=/mnt/hda1", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(21474836480)}},
98+
{"size=0.1TiB,path=/mnt/hda1", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(109951162778)}},
99+
{"path=/mnt/hda1,size=.1TiB", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(109951162778)}},
100+
{"path=/mnt/hda1,size=123TB", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(123000000000000)}},
101+
{"path=/mnt/hda1,size=123TiB", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.BytesSize(135239930216448)}},
102102
// %
103-
{"path=/mnt/hda1,size=50.5%", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 50.5}}},
104-
{"path=/mnt/hda1,size=100%", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 100}}},
105-
{"path=/mnt/hda1,size=1%", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 1}}},
106-
{"path=/mnt/hda1,size=0.999999%", "size (0.999999%) must be between 1% and 100%", StoreSpec{}},
107-
{"path=/mnt/hda1,size=100.0001%", "size (100.0001%) must be between 1% and 100%", StoreSpec{}},
103+
{"path=/mnt/hda1,size=50.5%", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(50.5)}},
104+
{"path=/mnt/hda1,size=100%", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(100)}},
105+
{"path=/mnt/hda1,size=1%", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(1)}},
106+
{"path=/mnt/hda1,size=0.999999%", "store size (0.999999%) must be at least 1%", StoreSpec{}},
107+
{"path=/mnt/hda1,size=100.0001%", "size (100.0001%) must be between 0% and 100%", StoreSpec{}},
108108
// 0.xxx
109-
{"path=/mnt/hda1,size=0.99", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 99}}},
110-
{"path=/mnt/hda1,size=0.5000000", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 50}}},
111-
{"path=/mnt/hda1,size=0.01", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 1}}},
112-
{"path=/mnt/hda1,size=0.009999", "size (0.009999) must be between 1% and 100%", StoreSpec{}},
109+
{"path=/mnt/hda1,size=0.99", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(99)}},
110+
{"path=/mnt/hda1,size=0.5000000", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(50)}},
111+
{"path=/mnt/hda1,size=0.01", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(1)}},
112+
{"path=/mnt/hda1,size=0.009999", "store size (0.9999%) must be at least 1%", StoreSpec{}},
113113
// .xxx
114-
{"path=/mnt/hda1,size=.999", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 99.9}}},
115-
{"path=/mnt/hda1,size=.5000000", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 50}}},
116-
{"path=/mnt/hda1,size=.01", "", StoreSpec{Path: "/mnt/hda1", Size: SizeSpec{Percent: 1}}},
117-
{"path=/mnt/hda1,size=.009999", "size (.009999) must be between 1% and 100%", StoreSpec{}},
114+
{"path=/mnt/hda1,size=.999", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(99.9)}},
115+
{"path=/mnt/hda1,size=.5000000", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(50)}},
116+
{"path=/mnt/hda1,size=.01", "", StoreSpec{Path: "/mnt/hda1", Size: storageconfig.PercentSize(1)}},
117+
{"path=/mnt/hda1,size=.009999", "store size (0.9999%) must be at least 1%", StoreSpec{}},
118118
// errors
119-
{"path=/mnt/hda1,size=0", "size (0) must be at least 640 MiB", StoreSpec{}},
120-
{"path=/mnt/hda1,size=abc", "could not parse size (abc): strconv.ParseFloat: parsing \"\": invalid syntax", StoreSpec{}},
119+
{"path=/mnt/hda1,size=0", "store size (0 B) must be at least 640 MiB", StoreSpec{}},
120+
{"path=/mnt/hda1,size=abc", "could not parse size (abc): cannot parse number from \"abc\"", StoreSpec{}},
121121
{"path=/mnt/hda1,size=", "no value specified for size", StoreSpec{}},
122122
{"size=20GiB,path=/mnt/hda1,size=20GiB", "size field was used twice in store definition", StoreSpec{}},
123123
{"size=123TB", "no path specified", StoreSpec{}},
124124

125125
// ballast size
126-
{"path=/mnt/hda1,ballast-size=671088640", "", StoreSpec{Path: "/mnt/hda1", BallastSize: &SizeSpec{Bytes: 671088640}}},
127-
{"path=/mnt/hda1,ballast-size=20GB", "", StoreSpec{Path: "/mnt/hda1", BallastSize: &SizeSpec{Bytes: 20000000000}}},
128-
{"path=/mnt/hda1,ballast-size=1%", "", StoreSpec{Path: "/mnt/hda1", BallastSize: &SizeSpec{Percent: 1}}},
129-
{"path=/mnt/hda1,ballast-size=100.000%", "ballast: size (100.000%) must be between 0% and 50%", StoreSpec{}},
126+
{"path=/mnt/hda1,ballast-size=671088640", "", StoreSpec{Path: "/mnt/hda1", BallastSize: storageconfig.BytesSize(671088640)}},
127+
{"path=/mnt/hda1,ballast-size=20GB", "", StoreSpec{Path: "/mnt/hda1", BallastSize: storageconfig.BytesSize(20000000000)}},
128+
{"path=/mnt/hda1,ballast-size=1%", "", StoreSpec{Path: "/mnt/hda1", BallastSize: storageconfig.PercentSize(1)}},
129+
{"path=/mnt/hda1,ballast-size=100.000%", "ballast size (100%) must be at most 50%", StoreSpec{}},
130130
{"ballast-size=20GiB,path=/mnt/hda1,ballast-size=20GiB", "ballast-size field was used twice in store definition", StoreSpec{}},
131131

132132
// type
133-
{"type=mem,size=20GiB", "", StoreSpec{Size: SizeSpec{Bytes: 21474836480}, InMemory: true}},
134-
{"size=20GiB,type=mem", "", StoreSpec{Size: SizeSpec{Bytes: 21474836480}, InMemory: true}},
135-
{"size=20.5GiB,type=mem", "", StoreSpec{Size: SizeSpec{Bytes: 22011707392}, InMemory: true}},
133+
{"type=mem,size=20GiB", "", StoreSpec{Size: storageconfig.BytesSize(21474836480), InMemory: true}},
134+
{"size=20GiB,type=mem", "", StoreSpec{Size: storageconfig.BytesSize(21474836480), InMemory: true}},
135+
{"size=20.5GiB,type=mem", "", StoreSpec{Size: storageconfig.BytesSize(22011707392), InMemory: true}},
136136
{"size=20GiB,type=mem,attrs=mem", "", StoreSpec{
137-
Size: SizeSpec{Bytes: 21474836480},
137+
Size: storageconfig.BytesSize(21474836480),
138138
InMemory: true,
139139
Attributes: []string{"mem"},
140140
}},
141-
{"type=mem,size=20", "size (20) must be at least 640 MiB", StoreSpec{}},
141+
{"type=mem,size=20", "store size (20 B) must be at least 640 MiB", StoreSpec{}},
142142
{"type=mem,size=", "no value specified for size", StoreSpec{}},
143143
{"type=mem,attrs=ssd", "size must be specified for an in memory store", StoreSpec{}},
144144
{"path=/mnt/hda1,type=mem", "path specified for in memory store", StoreSpec{}},
@@ -148,9 +148,9 @@ target_file_size=2097152`
148148
// provisioned rate
149149
{"path=/mnt/hda1,provisioned-rate=bandwidth=200MiB/s", "",
150150
StoreSpec{Path: "/mnt/hda1", ProvisionedRate: storageconfig.ProvisionedRate{ProvisionedBandwidth: 200 << 20}}},
151-
{"path=/mnt/hda1,provisioned-rate=bandwidth=200MiB", "provisioned-rate field does not have bandwidth sub-field 200MiB ending in /s", StoreSpec{}},
152-
{"path=/mnt/hda1,provisioned-rate=200MiB/s", "provisioned-rate field has invalid value 200MiB/s", StoreSpec{}},
153-
{"path=/mnt/hda1,provisioned-rate=bandwidth=0B/s", "provisioned-rate field is trying to set bandwidth to 0", StoreSpec{}},
151+
{"path=/mnt/hda1,provisioned-rate=bandwidth=200MiB", "provisioned-rate has invalid bandwidth value \"200MiB\"", StoreSpec{}},
152+
{"path=/mnt/hda1,provisioned-rate=200MiB/s", "provisioned-rate has invalid value \"200MiB/s\"", StoreSpec{}},
153+
{"path=/mnt/hda1,provisioned-rate=bandwidth=0B/s", "provisioned-rate has invalid bandwidth value \"0B/s\"", StoreSpec{}},
154154

155155
// Pebble
156156
{"path=/,pebble=[Options] l0_compaction_threshold=2 l0_stop_writes_threshold=10", "", StoreSpec{Path: "/",
@@ -161,11 +161,11 @@ target_file_size=2097152`
161161
// all together
162162
{"path=/mnt/hda1,attrs=hdd:ssd,size=20GiB", "", StoreSpec{
163163
Path: "/mnt/hda1",
164-
Size: SizeSpec{Bytes: 21474836480},
164+
Size: storageconfig.BytesSize(21474836480),
165165
Attributes: []string{"hdd", "ssd"},
166166
}},
167167
{"type=mem,attrs=hdd:ssd,size=20GiB", "", StoreSpec{
168-
Size: SizeSpec{Bytes: 21474836480},
168+
Size: storageconfig.BytesSize(21474836480),
169169
InMemory: true,
170170
Attributes: []string{"hdd", "ssd"},
171171
}},
@@ -204,7 +204,7 @@ target_file_size=2097152`
204204
storeSpecString := base.StoreSpecCmdLineString(storeSpec)
205205
storeSpec2, err := base.NewStoreSpec(storeSpecString)
206206
if err != nil {
207-
t.Errorf("%d(%s): error parsing String() result: %s", i, testCase.value, err)
207+
t.Errorf("%d(%s): error parsing String() result: %s\n%s", i, testCase.value, err, storeSpecString)
208208
continue
209209
}
210210
// Compare strings to deal with floats not matching exactly.
@@ -218,9 +218,6 @@ target_file_size=2097152`
218218
// StoreSpec aliases base.StoreSpec for convenience.
219219
type StoreSpec = base.StoreSpec
220220

221-
// Size aliases storageconfig.Size for convenience.
222-
type SizeSpec = storageconfig.Size
223-
224221
func TestStoreSpecListPreventedStartupMessage(t *testing.T) {
225222
defer leaktest.AfterTest(t)()
226223

pkg/base/test_server_args.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,7 @@ func InternalNonDefaultDecision(
598598
// with no special attributes.
599599
var DefaultTestStoreSpec = storageconfig.Store{
600600
InMemory: true,
601-
Size: storageconfig.Size{
602-
Bytes: 512 << 20,
603-
},
601+
Size: storageconfig.BytesSize(512 << 20),
604602
}
605603

606604
// DefaultTestTempStorageConfig is the associated temp storage for

pkg/ccl/storageccl/engineccl/encrypted_fs_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestPebbleEncryption(t *testing.T) {
252252
ctx,
253253
base.StoreSpec{
254254
InMemory: true,
255-
Size: storageconfig.Size{Bytes: 512 << 20},
255+
Size: storageconfig.BytesSize(512 << 20),
256256
EncryptionOptions: encOptions,
257257
StickyVFSID: stickyVFSID,
258258
},
@@ -304,7 +304,7 @@ func TestPebbleEncryption(t *testing.T) {
304304
ctx,
305305
base.StoreSpec{
306306
InMemory: true,
307-
Size: storageconfig.Size{Bytes: 512 << 20},
307+
Size: storageconfig.BytesSize(512 << 20),
308308
EncryptionOptions: encOptions,
309309
StickyVFSID: stickyVFSID,
310310
},
@@ -395,7 +395,7 @@ func TestPebbleEncryption2(t *testing.T) {
395395
ctx,
396396
base.StoreSpec{
397397
InMemory: true,
398-
Size: storageconfig.Size{Bytes: 512 << 20},
398+
Size: storageconfig.BytesSize(512 << 20),
399399
EncryptionOptions: encOptions,
400400
StickyVFSID: stickyVFSID,
401401
},

pkg/cli/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func setDebugContextDefaults() {
470470
debugCtx.sizes = false
471471
debugCtx.replicated = false
472472
debugCtx.inputFile = ""
473-
debugCtx.ballastSize = storageconfig.Size{Bytes: 1000000000}
473+
debugCtx.ballastSize = storageconfig.BytesSize(1000000000)
474474
debugCtx.maxResults = 0
475475
debugCtx.decodeAsTableDesc = ""
476476
debugCtx.verbose = false

pkg/cli/debug.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,15 @@ func runDebugBallast(cmd *cobra.Command, args []string) error {
397397
usedBytes := du.TotalBytes - du.AvailBytes
398398

399399
var targetUsage uint64
400-
p := debugCtx.ballastSize.Percent
401-
if math.Abs(p) > 100 {
402-
return errors.Errorf("absolute percentage value %f greater than 100", p)
403-
}
404-
b := debugCtx.ballastSize.Bytes
405-
if p != 0 && b != 0 {
406-
return errors.New("expected exactly one of percentage or bytes non-zero, found both")
400+
var p float64
401+
var b int64
402+
if debugCtx.ballastSize.IsPercent() {
403+
p = debugCtx.ballastSize.Percent()
404+
if math.Abs(p) > 100 {
405+
return errors.Errorf("absolute percentage value %f greater than 100", p)
406+
}
407+
} else if debugCtx.ballastSize.IsBytes() {
408+
b = debugCtx.ballastSize.Bytes()
407409
}
408410
switch {
409411
case p > 0:

0 commit comments

Comments
 (0)