Skip to content

Commit

Permalink
Validate DDL strategy flags for vitess/online strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Oct 26, 2023
1 parent 6311b54 commit 83bb623
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions go/vt/schema/ddl_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"
"time"

"github.com/google/shlex"
Expand Down Expand Up @@ -115,6 +116,14 @@ func ParseDDLStrategy(strategyVariable string) (*DDLStrategySetting, error) {
if _, err := setting.RetainArtifactsDuration(); err != nil {
return nil, err
}

switch setting.Strategy {
case DDLStrategyVitess, DDLStrategyOnline:
if opts := setting.RuntimeOptions(); len(opts) > 0 {
return nil, fmt.Errorf("invalid flags for vitess strategy: %s", strings.Join(opts, " "))
}
}

return setting, nil
}

Expand Down
21 changes: 20 additions & 1 deletion go/vt/schema/ddl_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestParseDDLStrategy(t *testing.T) {
cutOverThreshold time.Duration
expireArtifacts time.Duration
runtimeOptions string
err error
expectError string
}{
{
strategyVariable: "direct",
Expand Down Expand Up @@ -317,10 +317,29 @@ func TestParseDDLStrategy(t *testing.T) {
runtimeOptions: "",
analyzeTable: true,
},

{
strategyVariable: "vitess --alow-concrrnt", // intentional typo
strategy: DDLStrategyVitess,
options: "",
runtimeOptions: "",
expectError: "invalid flags",
},
{
strategyVariable: "vitess --declarative --max-load=Threads_running=100",
strategy: DDLStrategyVitess,
options: "--declarative --max-load=Threads_running=100",
runtimeOptions: "--max-load=Threads_running=100",
expectError: "invalid flags",
},
}
for _, ts := range tt {
t.Run(ts.strategyVariable, func(t *testing.T) {
setting, err := ParseDDLStrategy(ts.strategyVariable)
if ts.expectError != "" {
assert.ErrorContains(t, err, ts.expectError)
return
}
assert.NoError(t, err)
assert.Equal(t, ts.strategy, setting.Strategy)
assert.Equal(t, ts.options, setting.Options)
Expand Down

0 comments on commit 83bb623

Please sign in to comment.