Skip to content

Commit c5a115d

Browse files
committed
storageconfig: move provisioned rate
Move `base.ProvisionedRateSpec` to `storageconfig.ProvisionedRate`. Epic: none Release note: None
1 parent f6e03c8 commit c5a115d

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed

pkg/base/store_spec.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,43 +50,37 @@ func GetAbsoluteFSPath(fieldName string, p string) (string, error) {
5050
return ret, nil
5151
}
5252

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(
53+
func parseStoreProvisionedRate(
6054
field redact.SafeString, value string,
61-
) (ProvisionedRateSpec, error) {
55+
) (storageconfig.ProvisionedRate, error) {
6256
split := strings.Split(value, "=")
6357
if len(split) != 2 {
64-
return ProvisionedRateSpec{}, errors.Errorf("%s field has invalid value %s", field, value)
58+
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field has invalid value %s", field, value)
6559
}
6660
subField := split[0]
6761
subValue := split[1]
6862
if subField != "bandwidth" {
69-
return ProvisionedRateSpec{}, errors.Errorf("%s field does not have bandwidth sub-field", field)
63+
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field does not have bandwidth sub-field", field)
7064
}
7165
if len(subValue) == 0 {
72-
return ProvisionedRateSpec{}, errors.Errorf("%s field has no value specified for bandwidth", field)
66+
return storageconfig.ProvisionedRate{}, errors.Errorf("%s field has no value specified for bandwidth", field)
7367
}
7468
if len(subValue) <= 2 || subValue[len(subValue)-2:] != "/s" {
75-
return ProvisionedRateSpec{},
69+
return storageconfig.ProvisionedRate{},
7670
errors.Errorf("%s field does not have bandwidth sub-field %s ending in /s",
7771
field, subValue)
7872
}
7973
bandwidthString := subValue[:len(subValue)-2]
8074
bandwidth, err := humanizeutil.ParseBytes(bandwidthString)
8175
if err != nil {
82-
return ProvisionedRateSpec{},
76+
return storageconfig.ProvisionedRate{},
8377
errors.Wrapf(err, "could not parse bandwidth in field %s", field)
8478
}
8579
if bandwidth == 0 {
86-
return ProvisionedRateSpec{},
80+
return storageconfig.ProvisionedRate{},
8781
errors.Errorf("%s field is trying to set bandwidth to 0", field)
8882
}
89-
return ProvisionedRateSpec{ProvisionedBandwidth: bandwidth}, nil
83+
return storageconfig.ProvisionedRate{ProvisionedBandwidth: bandwidth}, nil
9084
}
9185

9286
// StoreSpec contains the details that can be specified in the cli pertaining
@@ -110,8 +104,8 @@ type StoreSpec struct {
110104
PebbleOptions string
111105
// EncryptionOptions is set if encryption is enabled.
112106
EncryptionOptions *storageconfig.EncryptionOptions
113-
// ProvisionedRateSpec is optional.
114-
ProvisionedRateSpec ProvisionedRateSpec
107+
// ProvisionedRate is optional.
108+
ProvisionedRate storageconfig.ProvisionedRate
115109
}
116110

117111
// String returns a fully parsable version of the store spec.
@@ -154,9 +148,9 @@ func (ss StoreSpec) String() string {
154148
fmt.Fprint(&buffer, optsStr)
155149
fmt.Fprint(&buffer, ",")
156150
}
157-
if ss.ProvisionedRateSpec.ProvisionedBandwidth > 0 {
151+
if ss.ProvisionedRate.ProvisionedBandwidth > 0 {
158152
fmt.Fprintf(&buffer, "provisioned-rate=bandwidth=%s/s,",
159-
humanizeutil.IBytes(ss.ProvisionedRateSpec.ProvisionedBandwidth))
153+
humanizeutil.IBytes(ss.ProvisionedRate.ProvisionedBandwidth))
160154
}
161155
// Trim the extra comma from the end if it exists.
162156
if l := buffer.Len(); l > 0 {
@@ -303,11 +297,11 @@ func NewStoreSpec(value string) (StoreSpec, error) {
303297
}
304298
ss.PebbleOptions = buf.String()
305299
case "provisioned-rate":
306-
rateSpec, err := newStoreProvisionedRateSpec("provisioned-rate", value)
300+
rateSpec, err := parseStoreProvisionedRate("provisioned-rate", value)
307301
if err != nil {
308302
return StoreSpec{}, err
309303
}
310-
ss.ProvisionedRateSpec = rateSpec
304+
ss.ProvisionedRate = rateSpec
311305

312306
default:
313307
return StoreSpec{}, fmt.Errorf("%s is not a valid store field", field)

pkg/base/store_spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ target_file_size=2097152`
148148

149149
// provisioned rate
150150
{"path=/mnt/hda1,provisioned-rate=bandwidth=200MiB/s", "",
151-
StoreSpec{Path: "/mnt/hda1", ProvisionedRateSpec: base.ProvisionedRateSpec{ProvisionedBandwidth: 200 << 20}}},
151+
StoreSpec{Path: "/mnt/hda1", ProvisionedRate: storageconfig.ProvisionedRate{ProvisionedBandwidth: 200 << 20}}},
152152
{"path=/mnt/hda1,provisioned-rate=bandwidth=200MiB", "provisioned-rate field does not have bandwidth sub-field 200MiB ending in /s", StoreSpec{}},
153153
{"path=/mnt/hda1,provisioned-rate=200MiB/s", "provisioned-rate field has invalid value 200MiB/s", StoreSpec{}},
154154
{"path=/mnt/hda1,provisioned-rate=bandwidth=0B/s", "provisioned-rate field is trying to set bandwidth to 0", StoreSpec{}},

pkg/server/node.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/cockroachdb/cockroach/pkg/storage"
5353
"github.com/cockroachdb/cockroach/pkg/storage/disk"
5454
"github.com/cockroachdb/cockroach/pkg/storage/fs"
55+
"github.com/cockroachdb/cockroach/pkg/storage/storageconfig"
5556
"github.com/cockroachdb/cockroach/pkg/util"
5657
"github.com/cockroachdb/cockroach/pkg/util/admission"
5758
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
@@ -1254,7 +1255,7 @@ func (n *Node) UpdateIOThreshold(id roachpb.StoreID, threshold *admissionpb.IOTh
12541255
// diskStatsMap encapsulates all the logic for populating DiskStats for
12551256
// admission.StoreMetrics.
12561257
type diskStatsMap struct {
1257-
provisionedRate map[roachpb.StoreID]base.ProvisionedRateSpec
1258+
provisionedRate map[roachpb.StoreID]storageconfig.ProvisionedRate
12581259
diskMonitors map[roachpb.StoreID]kvserver.DiskStatsMonitor
12591260
}
12601261

@@ -1298,7 +1299,7 @@ func (dsm *diskStatsMap) initDiskStatsMap(
12981299
specs []base.StoreSpec, engines []storage.Engine, diskManager monitorManagerInterface,
12991300
) error {
13001301
*dsm = diskStatsMap{
1301-
provisionedRate: make(map[roachpb.StoreID]base.ProvisionedRateSpec),
1302+
provisionedRate: make(map[roachpb.StoreID]storageconfig.ProvisionedRate),
13021303
diskMonitors: make(map[roachpb.StoreID]kvserver.DiskStatsMonitor),
13031304
}
13041305
for i := range engines {
@@ -1313,7 +1314,7 @@ func (dsm *diskStatsMap) initDiskStatsMap(
13131314
if err != nil {
13141315
return err
13151316
}
1316-
dsm.provisionedRate[id.StoreID] = specs[i].ProvisionedRateSpec
1317+
dsm.provisionedRate[id.StoreID] = specs[i].ProvisionedRate
13171318
dsm.diskMonitors[id.StoreID] = monitor
13181319
}
13191320
return nil

pkg/server/node_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/cockroachdb/cockroach/pkg/storage"
3131
"github.com/cockroachdb/cockroach/pkg/storage/disk"
3232
"github.com/cockroachdb/cockroach/pkg/storage/fs"
33+
"github.com/cockroachdb/cockroach/pkg/storage/storageconfig"
3334
"github.com/cockroachdb/cockroach/pkg/testutils"
3435
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
3536
"github.com/cockroachdb/cockroach/pkg/util/admission"
@@ -1142,13 +1143,13 @@ func TestDiskStatsMap(t *testing.T) {
11421143

11431144
specs := []base.StoreSpec{
11441145
{
1145-
ProvisionedRateSpec: base.ProvisionedRateSpec{
1146+
ProvisionedRate: storageconfig.ProvisionedRate{
11461147
ProvisionedBandwidth: 0,
11471148
},
11481149
Path: "foo",
11491150
},
11501151
{
1151-
ProvisionedRateSpec: base.ProvisionedRateSpec{
1152+
ProvisionedRate: storageconfig.ProvisionedRate{
11521153
ProvisionedBandwidth: 200,
11531154
},
11541155
Path: "bar",

pkg/storage/storageconfig/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go_library(
66
"encryption_spec.go",
77
"node.go",
88
"size.go",
9+
"store.go",
910
"wal_failover.go",
1011
],
1112
importpath = "github.com/cockroachdb/cockroach/pkg/storage/storageconfig",

pkg/storage/storageconfig/store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package storageconfig
7+
8+
// ProvisionedRate defines the provisioned rate for a store.
9+
type ProvisionedRate struct {
10+
// ProvisionedBandwidth is the bandwidth provisioned for a store in bytes/s.
11+
ProvisionedBandwidth int64
12+
// In the future, we may add more fields here for IOPS or separate read and
13+
// write bandwidth.
14+
}

0 commit comments

Comments
 (0)