Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
31572: storage: ensure kv.bulk_io_write settings are positive r=mjibson a=mjibson

Fixes cockroachdb#31571

Release note (bug fix): fix a panic when setting some kv.bulk_io_write
settings to a value < 1

Co-authored-by: Matt Jibson <[email protected]>
  • Loading branch information
craig[bot] and maddyblue committed Oct 18, 2018
2 parents 1f852af + ad15bd6 commit 6e7ed1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/settings/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ func RegisterNonNegativeIntSetting(key, desc string, defaultValue int64) *IntSet
})
}

// RegisterPositiveIntSetting defines a new setting with type int.
func RegisterPositiveIntSetting(key, desc string, defaultValue int64) *IntSetting {
return RegisterValidatedIntSetting(key, desc, defaultValue, func(v int64) error {
if v < 1 {
return errors.Errorf("cannot set %s to a value < 1: %d", key, v)
}
return nil
})
}

// RegisterValidatedIntSetting defines a new setting with type int with a
// validation function.
func RegisterValidatedIntSetting(
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var bulkIOWriteLimit = settings.RegisterByteSizeSetting(
)

// importRequestsLimit limits concurrent import requests.
var importRequestsLimit = settings.RegisterIntSetting(
var importRequestsLimit = settings.RegisterPositiveIntSetting(
"kv.bulk_io_write.concurrent_import_requests",
"number of import requests a store will handle concurrently before queuing",
1,
Expand All @@ -126,7 +126,7 @@ var importRequestsLimit = settings.RegisterIntSetting(
// by a guessing - it could be improved by more measured heuristics. Exported
// here since we check it in in the caller to limit generated requests as well
// to prevent excessive queuing.
var ExportRequestsLimit = settings.RegisterIntSetting(
var ExportRequestsLimit = settings.RegisterPositiveIntSetting(
"kv.bulk_io_write.concurrent_export_requests",
"number of export requests a store will handle concurrently before queuing",
5,
Expand Down

0 comments on commit 6e7ed1b

Please sign in to comment.