Skip to content

Commit

Permalink
Merge pull request #93093 from irfansharif/221205.22.1-spanconfig-ove…
Browse files Browse the repository at this point in the history
…rride

release-22.1: server: introduce `COCKROACH_FALLBACK_SPANCONFIG_NUM_REPLICAS_OVERRIDE`
  • Loading branch information
irfansharif authored Dec 7, 2022
2 parents 8769a81 + f2a8856 commit 4b95005
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 @@ -395,6 +395,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 @@ -71,6 +71,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 @@ -570,6 +571,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 4b95005

Please sign in to comment.