Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changefeedccl: use new bulk oracle for changefeed planning #120077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/ccl/changefeedccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ go_library(
"//pkg/ccl/changefeedccl/kvevent",
"//pkg/ccl/changefeedccl/kvfeed",
"//pkg/ccl/changefeedccl/schemafeed",
"//pkg/ccl/kvccl/kvfollowerreadsccl",
"//pkg/ccl/utilccl",
"//pkg/cloud",
"//pkg/cloud/externalconn",
Expand Down
11 changes: 11 additions & 0 deletions pkg/ccl/changefeedccl/changefeed_dist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdceval"
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/changefeedbase"
"github.com/cockroachdb/cockroach/pkg/ccl/kvccl/kvfollowerreadsccl"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/jobs/jobsprofiler"
"github.com/cockroachdb/cockroach/pkg/keys"
Expand Down Expand Up @@ -358,6 +359,12 @@ var RangeDistributionStrategy = settings.RegisterEnumSetting(
},
settings.WithPublic)

var useBulkOracle = settings.RegisterBoolSetting(
settings.ApplicationLevel,
"changefeed.random_replica_selection.enabled",
"randomize the selection of which replica backs up each range",
true)

func makePlan(
execCtx sql.JobExecContext,
jobID jobspb.JobID,
Expand Down Expand Up @@ -386,7 +393,11 @@ func makePlan(
}

rangeDistribution := RangeDistributionStrategy.Get(sv)
evalCtx := execCtx.ExtendedEvalContext()
oracle := replicaoracle.NewOracle(replicaOracleChoice, dsp.ReplicaOracleConfig(locFilter))
if useBulkOracle.Get(&evalCtx.Settings.SV) {
oracle = kvfollowerreadsccl.NewBulkOracle(dsp.ReplicaOracleConfig(evalCtx.Locality), locFilter, kvfollowerreadsccl.StreakConfig{})
}
planCtx := dsp.NewPlanningCtxWithOracle(ctx, execCtx.ExtendedEvalContext(), nil, /* planner */
blankTxn, sql.DistributionType(distMode), oracle, locFilter)
spanPartitions, err := dsp.PartitionSpans(ctx, planCtx, trackedSpans)
Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/changefeedccl/changefeed_dist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ func TestChangefeedWithNoDistributionStrategy(t *testing.T) {
defer tester.cleanup()

tester.sqlDB.Exec(t, "SET CLUSTER SETTING changefeed.default_range_distribution_strategy = 'default'")
tester.sqlDB.Exec(t, "SET CLUSTER SETTING changefeed.random_replica_selection.enabled = false")
tester.sqlDB.Exec(t, "CREATE CHANGEFEED FOR x INTO 'null://' WITH initial_scan='no'")
partitions := tester.getPartitions()
counts := tester.countRangesPerNode(partitions)
Expand Down
6 changes: 5 additions & 1 deletion pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6190,7 +6190,7 @@ func TestChangefeedHandlesRollingRestart(t *testing.T) {
t.Fatal("did not get signal to proceed")
}
},
// Handle tarnsient changefeed error. We expect to see node drain error.
// Handle transient changefeed error. We expect to see node drain error.
// When we do, notify drainNotification, and reset node drain channel.
HandleDistChangefeedError: func(err error) error {
errCh <- err
Expand Down Expand Up @@ -6227,6 +6227,10 @@ func TestChangefeedHandlesRollingRestart(t *testing.T) {
serverutils.SetClusterSetting(t, tc, "kv.closed_timestamp.target_duration", 10*time.Millisecond)
serverutils.SetClusterSetting(t, tc, "changefeed.experimental_poll_interval", 10*time.Millisecond)
serverutils.SetClusterSetting(t, tc, "changefeed.aggregator.heartbeat", 10*time.Millisecond)
// Randomizing replica assignment can cause timeouts or other
// failures due to assumptions in the testing knobs about balanced
// assignments.
serverutils.SetClusterSetting(t, tc, "changefeed.random_replica_selection.enabled", false)

sqlutils.CreateTable(
t, db, "foo",
Expand Down
Loading