From b07f0b232ab2cc30166e0450aed0847fd7390467 Mon Sep 17 00:00:00 2001 From: Jackson Owens Date: Wed, 16 Oct 2024 22:32:17 -0400 Subject: [PATCH] db: fix Options.Parse handling of unrecognized comparer 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. --- options.go | 6 +++++- options_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index d973a4923e..7b2ff26291 100644 --- a/options.go +++ b/options.go @@ -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": diff --git a/options_test.go b/options_test.go index 2ea4895bfe..757e1d0f45 100644 --- a/options_test.go +++ b/options_test.go @@ -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" @@ -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