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: Do not require rangefeed when running initial scan only. #99494

Merged
merged 1 commit into from
Mar 30, 2023
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
12 changes: 8 additions & 4 deletions pkg/ccl/changefeedccl/alter_changefeed_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ func alterChangefeedPlanHook(
}

fn := func(ctx context.Context, _ []sql.PlanNode, resultsCh chan<- tree.Datums) error {
if err := validateSettings(ctx, p); err != nil {
return err
}

typedExpr, err := alterChangefeedStmt.Jobs.TypeCheck(ctx, p.SemaCtx(), types.Int)
if err != nil {
return err
Expand Down Expand Up @@ -128,6 +124,14 @@ func alterChangefeedPlanHook(
return err
}

st, err := newOptions.GetInitialScanType()
if err != nil {
return err
}
if err := validateSettings(ctx, st != changefeedbase.OnlyInitialScan, p.ExecCfg()); err != nil {
return err
}

newTargets, newProgress, newStatementTime, originalSpecs, err := generateAndValidateNewTargets(
ctx, exprEval, p,
alterChangefeedStmt.Cmds,
Expand Down
16 changes: 9 additions & 7 deletions pkg/ccl/changefeedccl/changefeed_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ func changefeedPlanHook(
rowFn := func(ctx context.Context, _ []sql.PlanNode, resultsCh chan<- tree.Datums) error {
ctx, span := tracing.ChildSpan(ctx, stmt.StatementTag())
defer span.Finish()

if err := validateSettings(ctx, p); err != nil {
opts := changefeedbase.MakeStatementOptions(rawOpts)
st, err := opts.GetInitialScanType()
if err != nil {
return err
}
if err := validateSettings(ctx, st != changefeedbase.OnlyInitialScan, p.ExecCfg()); err != nil {
return err
}

Expand All @@ -186,8 +190,6 @@ func changefeedPlanHook(
return errors.New(`omit the SINK clause for inline results`)
}

opts := changefeedbase.MakeStatementOptions(rawOpts)

jr, err := createChangefeedJobRecord(
ctx,
p,
Expand Down Expand Up @@ -719,10 +721,10 @@ func createChangefeedJobRecord(
return jr, nil
}

func validateSettings(ctx context.Context, p sql.PlanHookState) error {
func validateSettings(ctx context.Context, needsRangeFeed bool, execCfg *sql.ExecutorConfig) error {
if err := featureflag.CheckEnabled(
ctx,
p.ExecCfg(),
execCfg,
featureChangefeedEnabled,
"CHANGEFEED",
); err != nil {
Expand All @@ -731,7 +733,7 @@ func validateSettings(ctx context.Context, p sql.PlanHookState) error {

// Changefeeds are based on the Rangefeed abstraction, which
// requires the `kv.rangefeed.enabled` setting to be true.
if !kvserver.RangefeedEnabled.Get(&p.ExecCfg().Settings.SV) {
if needsRangeFeed && !kvserver.RangefeedEnabled.Get(&execCfg.Settings.SV) {
return errors.Errorf("rangefeeds require the kv.rangefeed.enabled setting. See %s",
docs.URL(`change-data-capture.html#enable-rangefeeds-to-reduce-latency`))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/interactive_tests/test_demo_changefeeds.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ spawn $argv demo --no-line-editor --format=csv --auto-enable-rangefeeds=false
# We should start in a populated database.
eexpect "movr>"

# initial_scan=only prevents the changefeed from hanging waiting for more changes.
send "CREATE CHANGEFEED FOR users WITH initial_scan='only';\r"
# changefeed should exist since rangefeed not enabled.
send "CREATE CHANGEFEED FOR users;\r"

# changefeed should fail fast with an informative error.
eexpect "ERROR: rangefeeds require the kv.rangefeed.enabled setting."
Expand Down