Skip to content

Commit

Permalink
server: introduce COCKROACH_FALLBACK_SPANCONFIG_NUM_REPLICAS_OVERRIDE
Browse files Browse the repository at this point in the history
It controls what replication factor is used for ranges with no explicit
span configs set. This is a backportable form of the
spanconfig.store.fallback_config_override we added in cockroachdb#92466.

Release note: None
  • Loading branch information
irfansharif committed Dec 6, 2022
1 parent 208b1d3 commit c6656c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kv/kvserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ go_test(
"//pkg/util/contextutil",
"//pkg/util/ctxgroup",
"//pkg/util/encoding",
"//pkg/util/envutil",
"//pkg/util/hlc",
"//pkg/util/humanizeutil",
"//pkg/util/leaktest",
Expand Down
18 changes: 18 additions & 0 deletions pkg/kv/kvserver/client_spanconfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sqlutil"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -100,6 +101,23 @@ func TestSpanConfigUpdateAppliedToReplica(t *testing.T) {
})
}

// TestFallbackSpanConfigOverride ensures that
// COCKROACH_FALLBACK_SPANCONFIG_NUM_REPLICAS_OVERRIDE works as expected.
func TestFallbackSpanConfigNumReplicasOverride(t *testing.T) {
defer leaktest.AfterTest(t)()
defer envutil.TestSetEnv(t,
"COCKROACH_FALLBACK_SPANCONFIG_NUM_REPLICAS_OVERRIDE", "42")()

ctx := context.Background()
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(context.Background())
scKVSubscriber := s.SpanConfigKVSubscriber().(spanconfig.KVSubscriber)

conf, err := scKVSubscriber.GetSpanConfigForKey(ctx, roachpb.RKey("non-existent"))
require.NoError(t, err)
require.Equal(t, int32(42), conf.NumReplicas)
}

type mockSpanConfigSubscriber struct {
callback func(ctx context.Context, config roachpb.Span)
spanconfig.Store
Expand Down
7 changes: 7 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/ts"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/goschedstats"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -600,6 +601,12 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
// really only applies to user table ranges
fallbackConf.GCPolicy.IgnoreStrictEnforcement = true

// fallbackSpanConfigNumReplicasOverride controls what replication
// factor is used for ranges with no explicit span configs set.
var fallbackSpanConfigNumReplicasOverride = envutil.EnvOrDefaultInt(
"COCKROACH_FALLBACK_SPANCONFIG_NUM_REPLICAS_OVERRIDE", int(fallbackConf.NumReplicas))
fallbackConf.NumReplicas = int32(fallbackSpanConfigNumReplicasOverride)

spanConfig.subscriber = spanconfigkvsubscriber.New(
clock,
rangeFeedFactory,
Expand Down

0 comments on commit c6656c0

Please sign in to comment.