Skip to content
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
2 changes: 1 addition & 1 deletion docker/vttestserver/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rm -vf "$VTDATAROOT"/"$tablet_dir"/{mysql.sock,mysql.sock.lock}
-foreign_key_mode "${FOREIGN_KEY_MODE:-allow}" \
-enable_online_ddl="${ENABLE_ONLINE_DDL:-true}" \
-enable_direct_ddl="${ENABLE_DIRECT_DDL:-true}" \
-planner_version="${PLANNER_VERSION:-v3}" \
-planner-version="${PLANNER_VERSION:-v3}" \
-vschema_ddl_authorized_users=% \
-schema_dir="/vt/schema/"

26 changes: 16 additions & 10 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"strings"
"time"

"vitess.io/vitess/go/vt/env"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"

"vitess.io/vitess/go/vt/vttest"

"google.golang.org/protobuf/proto"
Expand All @@ -53,24 +56,22 @@ import (
)

var (
tpb vttestpb.VTTestTopology

schemaDir = flag.String("schema_dir", "", "Schema base directory. Should contain one directory per keyspace, with a vschema.json file if necessary.")

startMysql = flag.Bool("start_mysql", false, "Should vtcombo also start mysql")

mysqlPort = flag.Int("mysql_port", 3306, "mysql port")

schemaDir = flag.String("schema_dir", "", "Schema base directory. Should contain one directory per keyspace, with a vschema.json file if necessary.")
startMysql = flag.Bool("start_mysql", false, "Should vtcombo also start mysql")
mysqlPort = flag.Int("mysql_port", 3306, "mysql port")
externalTopoServer = flag.Bool("external_topo_server", false, "Should vtcombo use an external topology server instead of starting its own in-memory topology server. "+
"If true, vtcombo will use the flags defined in topo/server.go to open topo server")
plannerVersion = flag.String("planner-version", "gen4", "Sets the default planner to use when the session has not changed it. Valid values are: V3, Gen4, Gen4Greedy and Gen4Fallback. Gen4Fallback tries the gen4 planner and falls back to the V3 planner if the gen4 fails.")
plannerVersionDeprecated = flag.String("planner_version", "", "Deprecated flag. Use planner-version instead")

tpb vttestpb.VTTestTopology
ts *topo.Server
resilientServer *srvtopo.ResilientServer
)

func init() {
flag.Var(vttest.TextTopoData(&tpb), "proto_topo", "vttest proto definition of the topology, encoded in compact text format. See vttest.proto for more information.")
flag.Var(vttest.JsonTopoData(&tpb), "json_topo", "vttest proto definition of the topology, encoded in json format. See vttest.proto for more information.")
flag.Var(vttest.JSONTopoData(&tpb), "json_topo", "vttest proto definition of the topology, encoded in json format. See vttest.proto for more information.")

servenv.RegisterDefaultFlags()
}
Expand Down Expand Up @@ -241,12 +242,17 @@ func main() {
topodatapb.TabletType_REPLICA,
topodatapb.TabletType_RDONLY,
}
version, err := env.CheckPlannerVersionFlag(plannerVersion, plannerVersionDeprecated)
if err != nil {
log.Exitf("failed to get planner version from flags: %v", err)
}
plannerVersion, _ := plancontext.PlannerNameToVersion(version)

vtgate.QueryLogHandler = "/debug/vtgate/querylog"
vtgate.QueryLogzHandler = "/debug/vtgate/querylogz"
vtgate.QueryzHandler = "/debug/vtgate/queryz"
// pass nil for healthcheck, it will get created
vtg := vtgate.Init(context.Background(), nil, resilientServer, tpb.Cells[0], tabletTypesToWait)
vtg := vtgate.Init(context.Background(), nil, resilientServer, tpb.Cells[0], tabletTypesToWait, plannerVersion)

// vtctld configuration and init
err = vtctld.InitVtctld(ts)
Expand Down
18 changes: 9 additions & 9 deletions go/cmd/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"os"

"vitess.io/vitess/go/vt/env"

"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"

"vitess.io/vitess/go/exit"
Expand Down Expand Up @@ -50,8 +52,8 @@ var (
normalize = flag.Bool("normalize", false, "Whether to enable vtgate normalization")
outputMode = flag.String("output-mode", "text", "Output in human-friendly text or json")
dbName = flag.String("dbname", "", "Optional database target to override normal routing")
badPlannerVersion = flag.String("planner-version", "", "Deprecated flag. Use planner_version instead")
plannerVersionStr = flag.String("planner_version", "gen4", "Sets the query planner version to use when generating the explain output. Valid values are V3 and Gen4")
plannerVersionStr = flag.String("planner-version", "gen4", "Sets the query planner version to use when generating the explain output. Valid values are V3 and Gen4")
badPlannerVersion = flag.String("planner_version", "", "Deprecated flag. Use planner-version instead")

// vtexplainFlags lists all the flags that should show in usage
vtexplainFlags = []string{
Expand Down Expand Up @@ -147,14 +149,12 @@ func parseAndRun() error {
return err
}

if badPlannerVersion != nil {
if plannerVersionStr != nil && *badPlannerVersion != *plannerVersionStr {
return fmt.Errorf("can't specify planner-version and planner_version with different versions")
}
log.Warningf("planner-version is deprecated. please use planner_version instead")
plannerVersionStr = badPlannerVersion
verStr, err := env.CheckPlannerVersionFlag(plannerVersionStr, badPlannerVersion)
if err != nil {
return err
}
plannerVersion, _ := plancontext.PlannerNameToVersion(*plannerVersionStr)

plannerVersion, _ := plancontext.PlannerNameToVersion(verStr)
if plannerVersion != querypb.ExecuteOptions_V3 && plannerVersion != querypb.ExecuteOptions_Gen4 {
return fmt.Errorf("invalid value specified for planner-version of '%s' -- valid values are V3 and Gen4", *plannerVersionStr)
}
Expand Down
17 changes: 14 additions & 3 deletions go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strings"
"time"

"vitess.io/vitess/go/vt/env"
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"

"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

Expand All @@ -39,8 +42,10 @@ import (
)

var (
cell = flag.String("cell", "test_nj", "cell to use")
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
cell = flag.String("cell", "test_nj", "cell to use")
tabletTypesToWait = flag.String("tablet_types_to_wait", "", "wait till connected for specified tablet types during Gateway initialization")
plannerVersion = flag.String("planner-version", "gen4", "Sets the default planner to use when the session has not changed it. Valid values are: V3, Gen4, Gen4Greedy and Gen4Fallback. Gen4Fallback tries the gen4 planner and falls back to the V3 planner if the gen4 fails.")
plannerVersionDeprecated = flag.String("planner_version", "", "Deprecated flag. Use planner-version instead")
)

var resilientServer *srvtopo.ResilientServer
Expand Down Expand Up @@ -142,8 +147,14 @@ func main() {
log.Exitf("cells_to_watch validation failed: %v", err)
}

version, err := env.CheckPlannerVersionFlag(plannerVersion, plannerVersionDeprecated)
if err != nil {
log.Exitf("failed to get planner version from flags: %v", err)
}
plannerVersion, _ := plancontext.PlannerNameToVersion(version)

// pass nil for HealthCheck and it will be created
vtg := vtgate.Init(context.Background(), nil, resilientServer, *cell, tabletTypes)
vtg := vtgate.Init(context.Background(), nil, resilientServer, *cell, tabletTypes, plannerVersion)

servenv.OnRun(func() {
// Flags are parsed now. Parse the template using the actual flag value and overwrite the current template.
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/vttestserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func init() {

flag.StringVar(&config.Charset, "charset", "utf8mb4", "MySQL charset")

flag.StringVar(&config.PlannerVersion, "planner_version", "gen4", "Sets the default planner to use when the session has not changed it. Valid values are: V3, Gen4, Gen4Greedy and Gen4Fallback. Gen4Fallback tries the new gen4 planner and falls back to the V3 planner if the gen4 fails.")
flag.StringVar(&config.PlannerVersion, "planner-version", "gen4", "Sets the default planner to use when the session has not changed it. Valid values are: V3, Gen4, Gen4Greedy and Gen4Fallback. Gen4Fallback tries the new gen4 planner and falls back to the V3 planner if the gen4 fails.")
flag.StringVar(&config.PlannerVersionDeprecated, "planner_version", "", "planner_version is deprecated. Please use planner-version instead")

flag.StringVar(&config.SnapshotFile, "snapshot_file", "",
"A MySQL DB snapshot file")
Expand Down
4 changes: 3 additions & 1 deletion go/flags/endtoend/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ var (
URI of opentsdb /api/put method
--pid_file string
If set, the process will write its pid to the named file, and delete it on graceful shutdown.
--planner_version string
--planner-version string
Sets the default planner to use when the session has not changed it. Valid values are: V3, Gen4, Gen4Greedy and Gen4Fallback. Gen4Fallback tries the gen4 planner and falls back to the V3 planner if the gen4 fails. (default gen4)
--planner_version string
Deprecated flag. Use planner-version instead
--port int
port for the server
--pprof string
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/cluster/vtgate_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (vtgate *VtgateProcess) Setup() (err error) {
"--mysql_auth_server_impl", vtgate.MySQLAuthServerImpl,
}
if vtgate.PlannerVersion > 0 {
args = append(args, "--planner_version", vtgate.PlannerVersion.String())
args = append(args, "--planner-version", vtgate.PlannerVersion.String())
}
if vtgate.SysVarSetEnabled {
args = append(args, "--enable_system_settings")
Expand Down
4 changes: 1 addition & 3 deletions go/test/endtoend/tabletmanager/qps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ func TestQPS(t *testing.T) {
// after that we'll see 0.0 QPS rates again. If this becomes actually
// flaky, we need to read continuously in a separate thread.

n := 0
for n < 15 {
n++
for n := 0; n < 15; n++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so strange

// Run queries via vtGate so that they are counted.
utils.Exec(t, vtGateConn, "select * from t1")
}
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/vtcombo/vttest_sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestMain(m *testing.M) {
exitcode, err := func() (int, error) {
var topology vttestpb.VTTestTopology

data := vttest.JsonTopoData(&topology)
data := vttest.JSONTopoData(&topology)
err := data.Set(jsonTopo)
if err != nil {
return 1, err
Expand Down Expand Up @@ -253,7 +253,7 @@ func assertTabletsPresent(t *testing.T) {
}
parts := strings.Split(line, " ")
if parts[1] == "routed" {
numRouted += 1
numRouted++
continue
}

Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/partialfailure/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestMain(m *testing.M) {
}

// Start vtgate
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--planner_version", "Gen4Fallback")
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--planner-version", "Gen4Fallback")
if err := clusterInstance.StartVtgate(); err != nil {
return 1
}
Expand Down
18 changes: 18 additions & 0 deletions go/vt/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"path"
"path/filepath"
"strings"

"vitess.io/vitess/go/vt/log"
)

const (
Expand Down Expand Up @@ -100,3 +102,19 @@ func VtMysqlBaseDir() (string, error) {
}
return root, nil
}

// CheckPlannerVersionFlag takes two string references and checks that just one
// has a value or that they agree with each other.
func CheckPlannerVersionFlag(correct, deprecated *string) (string, error) {
if deprecated != nil && *deprecated != "" {
if correct != nil && *deprecated != *correct {
return "", fmt.Errorf("can't specify planner-version and planner_version with different versions")
}
log.Warningf("planner_version is deprecated. please use planner-version instead")
return *deprecated, nil
}
if correct == nil {
return "", nil
}
return *correct, nil
}
2 changes: 1 addition & 1 deletion go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (vte *VTExplain) initVtgateExecutor(vSchemaStr, ksShardMapStr string, opts

streamSize := 10
var schemaTracker vtgate.SchemaInfo // no schema tracker for these tests
vte.vtgateExecutor = vtgate.NewExecutor(context.Background(), vte.explainTopo, vtexplainCell, resolver, opts.Normalize, false /*do not warn for sharded only*/, streamSize, cache.DefaultConfig, schemaTracker, false /*no-scatter*/)
vte.vtgateExecutor = vtgate.NewExecutor(context.Background(), vte.explainTopo, vtexplainCell, resolver, opts.Normalize, false, streamSize, cache.DefaultConfig, schemaTracker, false, opts.PlannerVersion)

return nil
}
Expand Down
19 changes: 17 additions & 2 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"sync"
"time"

"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"

"vitess.io/vitess/go/vt/vtgate/evalengine"

"vitess.io/vitess/go/acl"
Expand Down Expand Up @@ -89,6 +91,7 @@ type Executor struct {
resolver *Resolver
scatterConn *ScatterConn
txConn *TxConn
pv plancontext.PlannerVersion

mu sync.Mutex
vschema *vindexes.VSchema
Expand All @@ -113,7 +116,18 @@ const pathScatterStats = "/debug/scatter_stats"
const pathVSchema = "/debug/vschema"

// NewExecutor creates a new Executor.
func NewExecutor(ctx context.Context, serv srvtopo.Server, cell string, resolver *Resolver, normalize, warnOnShardedOnly bool, streamSize int, cacheCfg *cache.Config, schemaTracker SchemaInfo, noScatter bool) *Executor {
func NewExecutor(
ctx context.Context,
serv srvtopo.Server,
cell string,
resolver *Resolver,
normalize, warnOnShardedOnly bool,
streamSize int,
cacheCfg *cache.Config,
schemaTracker SchemaInfo,
noScatter bool,
pv plancontext.PlannerVersion,
) *Executor {
e := &Executor{
serv: serv,
cell: cell,
Expand All @@ -126,6 +140,7 @@ func NewExecutor(ctx context.Context, serv srvtopo.Server, cell string, resolver
streamSize: streamSize,
schemaTracker: schemaTracker,
allowScatter: !noScatter,
pv: pv,
}

vschemaacl.Init()
Expand Down Expand Up @@ -1221,7 +1236,7 @@ func (e *Executor) prepare(ctx context.Context, safeSession *SafeSession, sql st
func (e *Executor) handlePrepare(ctx context.Context, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable, logStats *LogStats) ([]*querypb.Field, error) {
// V3 mode.
query, comments := sqlparser.SplitMarginComments(sql)
vcursor, _ := newVCursorImpl(ctx, safeSession, comments, e, logStats, e.vm, e.VSchema(), e.resolver.resolver, e.serv, e.warnShardedOnly)
vcursor, _ := newVCursorImpl(ctx, safeSession, comments, e, logStats, e.vm, e.VSchema(), e.resolver.resolver, e.serv, e.warnShardedOnly, e.pv)
plan, err := e.getPlan(
vcursor,
query,
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/executor_dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestUpdateEqual(t *testing.T) {

func TestUpdateFromSubQuery(t *testing.T) {
executor, sbc1, sbc2, _ := createExecutorEnv()

executor.pv = querypb.ExecuteOptions_Gen4
logChan := QueryLogger.Subscribe("Test")
defer QueryLogger.Unsubscribe(logChan)

Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/executor_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func createExecutorEnv() (executor *Executor, sbc1, sbc2, sbclookup *sandboxconn
bad.VSchema = badVSchema

getSandbox(KsTestUnsharded).VSchema = unshardedVSchema
executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)
executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false, querypb.ExecuteOptions_V3)

key.AnyShardPicker = DestinationAnyShardPickerFirstShard{}
// create a new session each time so that ShardSessions don't get re-used across tests
Expand All @@ -493,7 +493,7 @@ func createCustomExecutor(vschema string) (executor *Executor, sbc1, sbc2, sbclo
sbclookup = hc.AddTestTablet(cell, "0", 1, KsTestUnsharded, "0", topodatapb.TabletType_PRIMARY, true, 1, nil)
getSandbox(KsTestUnsharded).VSchema = unshardedVSchema

executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)
executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false, querypb.ExecuteOptions_V3)
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
Expand Down Expand Up @@ -522,7 +522,7 @@ func createCustomExecutorSetValues(vschema string, values []*sqltypes.Result) (e
sbclookup = hc.AddTestTablet(cell, "0", 1, KsTestUnsharded, "0", topodatapb.TabletType_PRIMARY, true, 1, nil)
getSandbox(KsTestUnsharded).VSchema = unshardedVSchema

executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)
executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false, querypb.ExecuteOptions_V3)
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
Expand Down
Loading