From 4ac36dc0e10a84905acda6ba61bded5ed54700ca Mon Sep 17 00:00:00 2001 From: Armand Parajon Date: Fri, 5 Apr 2024 15:43:09 -0700 Subject: [PATCH] Add `no_scatter` flag to vttestserver Signed-off-by: Armand Parajon --- go/cmd/vttestserver/cli/main.go | 2 ++ go/cmd/vttestserver/cli/main_test.go | 15 +++++++++++++++ go/flags/endtoend/vttestserver.txt | 1 + go/vt/vttest/local_cluster.go | 3 +++ go/vt/vttest/vtprocess.go | 1 + 5 files changed, 22 insertions(+) diff --git a/go/cmd/vttestserver/cli/main.go b/go/cmd/vttestserver/cli/main.go index 2cc59f539e1..5601623b2fa 100644 --- a/go/cmd/vttestserver/cli/main.go +++ b/go/cmd/vttestserver/cli/main.go @@ -224,6 +224,8 @@ func New() (cmd *cobra.Command) { cmd.Flags().DurationVar(&config.VtgateTabletRefreshInterval, "tablet_refresh_interval", 10*time.Second, "Interval at which vtgate refreshes tablet information from topology server.") cmd.Flags().BoolVar(&doCreateTCPUser, "initialize-with-vt-dba-tcp", false, "If this flag is enabled, MySQL will be initialized with an additional user named vt_dba_tcp, who will have access via TCP/IP connection.") + + cmd.Flags().BoolVar(&config.NoScatter, "no_scatter", false, "when set to true, the planner will fail instead of producing a plan that includes scatter queries") acl.RegisterFlags(cmd.Flags()) return cmd diff --git a/go/cmd/vttestserver/cli/main_test.go b/go/cmd/vttestserver/cli/main_test.go index 802f2533202..0ea0e6b7c19 100644 --- a/go/cmd/vttestserver/cli/main_test.go +++ b/go/cmd/vttestserver/cli/main_test.go @@ -186,6 +186,21 @@ func TestForeignKeysAndDDLModes(t *testing.T) { assert.NoError(t, err) } +func TestNoScatter(t *testing.T) { + conf := config + defer resetConfig(conf) + + cluster, err := startCluster("--no_scatter") + assert.NoError(t, err) + defer cluster.TearDown() + + _ = execOnCluster(cluster, "app_customer", func(conn *mysql.Conn) error { + _, err = conn.ExecuteFetch("SELECT * FROM customers", 100, false) + require.ErrorContains(t, err, "plan includes scatter, which is disallowed") + return nil + }) +} + // TestCreateDbaTCPUser tests that the vt_dba_tcp user is created and can connect through TCP/IP connection // when --initialize-with-vt-dba-tcp is set to true. func TestCreateDbaTCPUser(t *testing.T) { diff --git a/go/flags/endtoend/vttestserver.txt b/go/flags/endtoend/vttestserver.txt index 2683fb70171..8cce76afc65 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -92,6 +92,7 @@ Flags: --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") --mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init --mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions) + --no_scatter when set to true, the planner will fail instead of producing a plan that includes scatter queries --null_probability float The probability to initialize a field with 'NULL' if --initialize_with_random_data is true. Only applies to fields that can contain NULL values. (default 0.1) --num_shards strings Comma separated shard count (one per keyspace) (default [2]) --onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s) diff --git a/go/vt/vttest/local_cluster.go b/go/vt/vttest/local_cluster.go index da19d1c6fb8..3c65f7de1eb 100644 --- a/go/vt/vttest/local_cluster.go +++ b/go/vt/vttest/local_cluster.go @@ -156,6 +156,9 @@ type Config struct { ExternalTopoGlobalRoot string VtgateTabletRefreshInterval time.Duration + + // Set the planner to fail on scatter queries + NoScatter bool } // InitSchemas is a shortcut for tests that just want to setup a single diff --git a/go/vt/vttest/vtprocess.go b/go/vt/vttest/vtprocess.go index 808a9510cbe..2d2c9116c6d 100644 --- a/go/vt/vttest/vtprocess.go +++ b/go/vt/vttest/vtprocess.go @@ -235,6 +235,7 @@ func VtcomboProcess(environment Environment, args *Config, mysql MySQLManager) ( fmt.Sprintf("--enable_online_ddl=%t", args.EnableOnlineDDL), fmt.Sprintf("--enable_direct_ddl=%t", args.EnableDirectDDL), fmt.Sprintf("--enable_system_settings=%t", args.EnableSystemSettings), + fmt.Sprintf("--no_scatter=%t", args.NoScatter), }...) // If topo tablet refresh interval is not defined then we will give it value of 10s. Please note