Skip to content

Commit

Permalink
db: fix Options.Parse handling of unrecognized comparer
Browse files Browse the repository at this point in the history
In b3993ff the behavior of Options.Parse when no NewComparer hook is provided
changed. Parse began to nil out the Comparer field, clearing any existing
Comparer.
  • Loading branch information
jbowens committed Oct 17, 2024
1 parent 9f16461 commit b07f0b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,11 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
}
}
case "comparer":
o.Comparer, err = parseComparer(value)
var comparer *Comparer
comparer, err = parseComparer(value)
if comparer != nil {
o.Comparer = comparer
}
case "compaction_debt_concurrency":
o.Experimental.CompactionDebtConcurrency, err = strconv.ParseUint(value, 10, 64)
case "delete_range_flush_delay":
Expand Down
11 changes: 11 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/vfs"
"github.com/cockroachdb/pebble/wal"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -317,6 +318,16 @@ func TestOptionsParse(t *testing.T) {
}
}

func TestOptionsParseComparerOverwrite(t *testing.T) {
// Test that an unrecognized comparer in the OPTIONS file does not nil out
// the Comparer field.
o := &Options{Comparer: testkeys.Comparer}
err := o.Parse(`[Options]
comparer=unrecognized`, nil)
require.NoError(t, err)
require.Equal(t, testkeys.Comparer, o.Comparer)
}

func TestOptionsValidate(t *testing.T) {
testCases := []struct {
options string
Expand Down

0 comments on commit b07f0b2

Please sign in to comment.