From 6da641acb95009041b177c4893f2a58fddea44d9 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Tue, 27 Sep 2022 14:42:37 +0530 Subject: [PATCH] refactor: minor refactor in partial shard routing and change in flag to dashes (#11357) Signed-off-by: Harshit Gangal Signed-off-by: Harshit Gangal --- go/flags/endtoend/vtgate.txt | 2 +- go/test/endtoend/cluster/cluster_process.go | 2 +- .../vreplication/resharding_workflows_v2_test.go | 2 +- go/vt/vtgate/planbuilder/bypass.go | 12 +----------- go/vt/vtgate/planbuilder/plan_test.go | 4 ++++ go/vt/vtgate/planbuilder/plancontext/vschema.go | 3 +++ go/vt/vtgate/vcursor_impl.go | 5 +++++ go/vt/vtgate/vtgate.go | 4 +--- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/go/flags/endtoend/vtgate.txt b/go/flags/endtoend/vtgate.txt index 098c70b62d7..b34f868673c 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -20,11 +20,11 @@ Usage of vtgate: --discovery_high_replication_lag_minimum_serving duration Threshold above which replication lag is considered too high when applying the min_number_serving_vttablets flag. (default 2h0m0s) --discovery_low_replication_lag duration Threshold below which replication lag is considered low enough to be healthy. (default 30s) --emit_stats If set, emit stats to push-based monitoring and stats backends + --enable-partial-keyspace-migration (Experimental) Follow shard routing rules: enable only while migrating a keyspace shard by shard. See documentation on Partial MoveTables for more. (default false) --enable_buffer Enable buffering (stalling) of primary traffic during failovers. --enable_buffer_dry_run Detect and log failover events, but do not actually buffer requests. --enable_direct_ddl Allow users to submit direct DDL statements (default true) --enable_online_ddl Allow users to submit, review and control Online DDL (default true) - --enable_partial_keyspace_migration (Experimental) Follow shard routing rules: enable only while migrating a keyspace shard by shard. See documentation on Partial MoveTables for more. (default false) --enable_set_var This will enable the use of MySQL's SET_VAR query hint for certain system variables instead of using reserved connections (default true) --enable_system_settings This will enable the system settings to be changed per session at the database connection level (default true) --foreign_key_mode string This is to provide how to handle foreign key constraint in create/alter table. Valid values are: allow, disallow (default "allow") diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index eaf7396ebea..b4978396ed6 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -641,7 +641,7 @@ func (cluster *LocalProcessCluster) SetupCluster(keyspace *Keyspace, shards []Sh // StartVtgate starts vtgate func (cluster *LocalProcessCluster) StartVtgate() (err error) { if cluster.HasPartialKeyspaces { - cluster.VtGateExtraArgs = append(cluster.VtGateExtraArgs, "--enable_partial_keyspace_migration") + cluster.VtGateExtraArgs = append(cluster.VtGateExtraArgs, "--enable-partial-keyspace-migration") } vtgateInstance := *cluster.NewVtgateInstance() cluster.VtgateProcess = vtgateInstance diff --git a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go index 55c3338a793..7b085a9321b 100644 --- a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go +++ b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go @@ -272,7 +272,7 @@ func TestPartialMoveTables(t *testing.T) { // tracking is enabled then vtgate will produce an error about the // unknown symbol before attempting to route the query. extraVTGateArgs = append(extraVTGateArgs, []string{ - "--enable_partial_keyspace_migration", + "--enable-partial-keyspace-migration", "--schema_change_signal=false", }...) defer func() { diff --git a/go/vt/vtgate/planbuilder/bypass.go b/go/vt/vtgate/planbuilder/bypass.go index b9ea1ee753b..3703dc84710 100644 --- a/go/vt/vtgate/planbuilder/bypass.go +++ b/go/vt/vtgate/planbuilder/bypass.go @@ -26,16 +26,6 @@ import ( "vitess.io/vitess/go/vt/vtgate/vindexes" ) -var enableShardRouting bool - -func EnableShardRoutingFlag(val bool) { - enableShardRouting = val -} - -func IsShardRoutingEnabled() bool { - return enableShardRouting -} - func buildPlanForBypass(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vschema plancontext.VSchema) (*planResult, error) { keyspace, err := vschema.DefaultKeyspace() if err != nil { @@ -48,7 +38,7 @@ func buildPlanForBypass(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vsc return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "INSERT not supported when targeting a key range: %s", vschema.TargetString()) } case key.DestinationShard: - if !IsShardRoutingEnabled() { + if !vschema.IsShardRoutingEnabled() { break } shard := string(dest) diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index e0b33e85bba..e1151edda91 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -538,6 +538,10 @@ type vschemaWrapper struct { version plancontext.PlannerVersion } +func (vw *vschemaWrapper) IsShardRoutingEnabled() bool { + return false +} + func (vw *vschemaWrapper) GetVSchema() *vindexes.VSchema { return vw.v } diff --git a/go/vt/vtgate/planbuilder/plancontext/vschema.go b/go/vt/vtgate/planbuilder/plancontext/vschema.go index 2f76ce86a6b..46aa544f33d 100644 --- a/go/vt/vtgate/planbuilder/plancontext/vschema.go +++ b/go/vt/vtgate/planbuilder/plancontext/vschema.go @@ -60,6 +60,9 @@ type VSchema interface { GetSrvVschema() *vschemapb.SrvVSchema // FindRoutedShard looks up shard routing rules for a shard FindRoutedShard(keyspace, shard string) (string, error) + + // IsShardRoutingEnabled returns true if partial shard routing is enabled + IsShardRoutingEnabled() bool } // PlannerNameToVersion returns the numerical representation of the planner diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index 6d60cec8328..5bf0e7d730f 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -207,6 +207,11 @@ func (vc *vcursorImpl) RecordWarning(warning *querypb.QueryWarning) { vc.safeSession.RecordWarning(warning) } +// IsShardRoutingEnabled implements the VCursor interface. +func (vc *vcursorImpl) IsShardRoutingEnabled() bool { + return enableShardRouting +} + // FindTable finds the specified table. If the keyspace what specified in the input, it gets used as qualifier. // Otherwise, the keyspace from the request is used, if one was provided. func (vc *vcursorImpl) FindTable(name sqlparser.TableName) (*vindexes.Table, string, topodatapb.TabletType, key.Destination, error) { diff --git a/go/vt/vtgate/vtgate.go b/go/vt/vtgate/vtgate.go index 34065e67d1c..8d969f4ab91 100644 --- a/go/vt/vtgate/vtgate.go +++ b/go/vt/vtgate/vtgate.go @@ -43,7 +43,6 @@ import ( "vitess.io/vitess/go/vt/srvtopo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vterrors" - "vitess.io/vitess/go/vt/vtgate/planbuilder" "vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext" "vitess.io/vitess/go/vt/vtgate/vtgateservice" @@ -115,7 +114,7 @@ func registerFlags(fs *pflag.FlagSet) { fs.StringVar(&defaultDDLStrategy, "ddl_strategy", defaultDDLStrategy, "Set default strategy for DDL statements. Override with @@ddl_strategy session variable") fs.StringVar(&dbDDLPlugin, "dbddl_plugin", dbDDLPlugin, "controls how to handle CREATE/DROP DATABASE. use it if you are using your own database provisioning service") fs.BoolVar(&noScatter, "no_scatter", noScatter, "when set to true, the planner will fail instead of producing a plan that includes scatter queries") - fs.BoolVar(&enableShardRouting, "enable_partial_keyspace_migration", enableShardRouting, "(Experimental) Follow shard routing rules: enable only while migrating a keyspace shard by shard. See documentation on Partial MoveTables for more. (default false)") + fs.BoolVar(&enableShardRouting, "enable-partial-keyspace-migration", enableShardRouting, "(Experimental) Follow shard routing rules: enable only while migrating a keyspace shard by shard. See documentation on Partial MoveTables for more. (default false)") fs.DurationVar(&healthCheckRetryDelay, "healthcheck_retry_delay", healthCheckRetryDelay, "health check retry delay") fs.DurationVar(&healthCheckTimeout, "healthcheck_timeout", healthCheckTimeout, "the health check timeout period") fs.IntVar(&maxPayloadSize, "max_payload_size", maxPayloadSize, "The threshold for query payloads in bytes. A payload greater than this threshold will result in a failure to handle the query.") @@ -339,7 +338,6 @@ func Init( } initAPI(gw.hc) - planbuilder.EnableShardRoutingFlag(enableShardRouting) return rpcVTGate }