Skip to content

Commit

Permalink
Merge pull request #8177 from planetscale/vttestserver-more-flags
Browse files Browse the repository at this point in the history
Add options to vttestserver to pass -foreign_key_mode, -enable_online_ddl, and -enable_direct_ddl through to vtcombo
  • Loading branch information
deepthi authored May 27, 2021
2 parents 3f1544c + 7da4c53 commit 1d649ea
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docker/vttestserver/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@
# Setup the Vschema Folder
/vt/setup_vschema_folder.sh "$KEYSPACES" "$NUM_SHARDS"
# Run the vttestserver binary
/vt/bin/vttestserver -port "$PORT" -keyspaces "$KEYSPACES" -num_shards "$NUM_SHARDS" -mysql_bind_host "${MYSQL_BIND_HOST:-127.0.0.1}" -mysql_server_version "${MYSQL_SERVER_VERSION:-$1}" -charset "${CHARSET:-utf8mb4}" -vschema_ddl_authorized_users=% -schema_dir="/vt/schema/"
/vt/bin/vttestserver \
-port "$PORT" \
-keyspaces "$KEYSPACES" \
-num_shards "$NUM_SHARDS" \
-mysql_bind_host "${MYSQL_BIND_HOST:-127.0.0.1}" \
-mysql_server_version "${MYSQL_SERVER_VERSION:-$1}" \
-charset "${CHARSET:-utf8mb4}" \
-foreign_key_mode "${FOREIGN_KEY_MODE:-allow}" \
-enable_online_ddl="${ENABLE_ONLINE_DDL:-true}" \
-enable_direct_ddl="${ENABLE_DIRECT_DDL:-true}" \
-vschema_ddl_authorized_users=% \
-schema_dir="/vt/schema/"

4 changes: 4 additions & 0 deletions go/cmd/vttestserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func init() {
flag.BoolVar(&config.InitWorkflowManager, "workflow_manager_init", false, "Enable workflow manager")

flag.StringVar(&config.VSchemaDDLAuthorizedUsers, "vschema_ddl_authorized_users", "", "Comma separated list of users authorized to execute vschema ddl operations via vtgate")

flag.StringVar(&config.ForeignKeyMode, "foreign_key_mode", "allow", "This is to provide how to handle foreign key constraint in create/alter table. Valid values are: allow, disallow")
flag.BoolVar(&config.EnableOnlineDDL, "enable_online_ddl", true, "Allow users to submit, review and control Online DDL")
flag.BoolVar(&config.EnableDirectDDL, "enable_direct_ddl", true, "Allow users to submit direct DDL statements")
}

func (t *topoFlags) buildTopology() (*vttestpb.VTTestTopology, error) {
Expand Down
96 changes: 96 additions & 0 deletions go/cmd/vttestserver/vttestserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,102 @@ func TestPersistentMode(t *testing.T) {
assert.Equal(t, expectedRows, res.Rows)
}

func TestForeignKeys(t *testing.T) {
args := os.Args
conf := config
defer resetFlags(args, conf)

cluster, err := startCluster("-foreign_key_mode=allow")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch(`CREATE TABLE test_table_2 (
id BIGINT,
test_table_id BIGINT,
FOREIGN KEY (test_table_id) REFERENCES test_table(id)
)`, 1, false)
return err
})
assert.NoError(t, err)

cluster.TearDown()
cluster, err = startCluster("-foreign_key_mode=disallow")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch(`CREATE TABLE test_table_2 (
id BIGINT,
test_table_id BIGINT,
FOREIGN KEY (test_table_id) REFERENCES test_table(id)
)`, 1, false)
return err
})
assert.Error(t, err)
}

func TestDDLModes(t *testing.T) {
args := os.Args
conf := config
defer resetFlags(args, conf)

cluster, err := startCluster("-enable_online_ddl=true")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch("SET @@ddl_strategy='online';", 1, false)
assert.NoError(t, err)
_, err = conn.ExecuteFetch("ALTER TABLE test_table ADD COLUMN something_else VARCHAR(255) NOT NULL DEFAULT ''", 1, false)
assert.NoError(t, err)
return nil
})
assert.NoError(t, err)

cluster.TearDown()
cluster, err = startCluster("-enable_online_ddl=false")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch("SET @@ddl_strategy='online';", 1, false)
assert.NoError(t, err)
_, err = conn.ExecuteFetch("ALTER TABLE test_table ADD COLUMN something_else VARCHAR(255) NOT NULL DEFAULT ''", 1, false)
return err
})
assert.Error(t, err)

cluster.TearDown()
cluster, err = startCluster("-enable_direct_ddl=true")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch("SET @@ddl_strategy='direct';", 1, false)
assert.NoError(t, err)
_, err = conn.ExecuteFetch("ALTER TABLE test_table ADD COLUMN something_else VARCHAR(255) NOT NULL DEFAULT ''", 1, false)
assert.NoError(t, err)
_, err = conn.ExecuteFetch("SELECT something_else FROM test_table", 1, false)
assert.NoError(t, err)
return nil
})
assert.NoError(t, err)

cluster.TearDown()
cluster, err = startCluster("-enable_direct_ddl=false")
assert.NoError(t, err)
defer cluster.TearDown()

err = execOnCluster(cluster, "test_keyspace", func(conn *mysql.Conn) error {
_, err := conn.ExecuteFetch("SET @@ddl_strategy='direct';", 1, false)
assert.NoError(t, err)
_, err = conn.ExecuteFetch("ALTER TABLE test_table ADD COLUMN something_else VARCHAR(255) NOT NULL DEFAULT ''", 1, false)
return err
})
assert.Error(t, err)
}

func TestCanVtGateExecute(t *testing.T) {
args := os.Args
conf := config
Expand Down
9 changes: 9 additions & 0 deletions go/vt/vttest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ type Config struct {

// Authorize vschema ddl operations to a list of users
VSchemaDDLAuthorizedUsers string

// How to handle foreign key constraint in CREATE/ALTER TABLE. Valid values are "allow", "disallow"
ForeignKeyMode string

// Allow users to submit, view, and control Online DDL
EnableOnlineDDL bool

// Allow users to submit direct DDL statements
EnableDirectDDL bool
}

// InitSchemas is a shortcut for tests that just want to setup a single
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vttest/vtprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func VtcomboProcess(env Environment, args *Config, mysql MySQLManager) *VtProces
"-normalize_queries",
"-enable_query_plan_field_caching=false",
"-dbddl_plugin", "vttest",
"-foreign_key_mode", args.ForeignKeyMode,
fmt.Sprintf("-enable_online_ddl=%t", args.EnableOnlineDDL),
fmt.Sprintf("-enable_direct_ddl=%t", args.EnableDirectDDL),
}...)

vt.ExtraArgs = append(vt.ExtraArgs, QueryServerArgs...)
Expand Down

0 comments on commit 1d649ea

Please sign in to comment.