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

[release-18.0] Online DDL: lint DDL strategy flags (#14373) #14399

Merged
merged 1 commit into from
Oct 31, 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
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, DDLStrategyMySQL, DDLStrategyDirect:
if opts := setting.RuntimeOptions(); len(opts) > 0 {
return nil, fmt.Errorf("invalid flags for %v strategy: %s", setting.Strategy, strings.Join(opts, " "))
}
}

return setting, nil
}

Expand Down
66 changes: 51 additions & 15 deletions go/vt/schema/ddl_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ func TestIsDirect(t *testing.T) {

func TestIsCutOverThresholdFlag(t *testing.T) {
tt := []struct {
s string
expect bool
val string
d time.Duration
s string
expect bool
expectError string
val string
d time.Duration
}{
{
s: "something",
s: "something",
expectError: "invalid flags",
},
{
s: "-cut-over-threshold",
s: "-cut-over-threshold",
expectError: "invalid flags",
},
{
s: "--cut-over-threshold",
s: "--cut-over-threshold",
expectError: "invalid flags",
},
{
s: "--cut-over-threshold=",
Expand Down Expand Up @@ -87,6 +91,11 @@ func TestIsCutOverThresholdFlag(t *testing.T) {
for _, ts := range tt {
t.Run(ts.s, func(t *testing.T) {
setting, err := ParseDDLStrategy("online " + ts.s)
if ts.expectError != "" {
assert.ErrorContains(t, err, ts.expectError)
return
}

assert.NoError(t, err)

val, isCutOver := isCutOverThresholdFlag(ts.s)
Expand All @@ -104,19 +113,23 @@ func TestIsCutOverThresholdFlag(t *testing.T) {

func TestIsExpireArtifactsFlag(t *testing.T) {
tt := []struct {
s string
expect bool
val string
d time.Duration
s string
expect bool
expectError string
val string
d time.Duration
}{
{
s: "something",
s: "something",
expectError: "invalid flags",
},
{
s: "-retain-artifacts",
s: "-retain-artifacts",
expectError: "invalid flags",
},
{
s: "--retain-artifacts",
s: "--retain-artifacts",
expectError: "invalid flags",
},
{
s: "--retain-artifacts=",
Expand Down Expand Up @@ -150,6 +163,10 @@ func TestIsExpireArtifactsFlag(t *testing.T) {
for _, ts := range tt {
t.Run(ts.s, func(t *testing.T) {
setting, err := ParseDDLStrategy("online " + ts.s)
if ts.expectError != "" {
assert.ErrorContains(t, err, ts.expectError)
return
}
assert.NoError(t, err)

val, isRetainArtifacts := isRetainArtifactsFlag(ts.s)
Expand Down Expand Up @@ -183,7 +200,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 +334,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
Loading