Skip to content

Commit

Permalink
refactor: minor refactor in partial shard routing and change in flag …
Browse files Browse the repository at this point in the history
…to dashes (#11357)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal authored Sep 27, 2022
1 parent 00600f5 commit 6da641a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go/flags/endtoend/vtgate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 1 addition & 11 deletions go/vt/vtgate/planbuilder/bypass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vtgate/planbuilder/plancontext/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions go/vt/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -339,7 +338,6 @@ func Init(
}

initAPI(gw.hc)
planbuilder.EnableShardRoutingFlag(enableShardRouting)
return rpcVTGate
}

Expand Down

0 comments on commit 6da641a

Please sign in to comment.