Skip to content

Commit

Permalink
Add support for vtgate --no_scatter and SINGLE transaction mode to
Browse files Browse the repository at this point in the history
vtexplain

Signed-off-by: Jacques Grove <aquarapid@gmail.com>
aquarapid committed Oct 19, 2022
1 parent cdfa0c4 commit 5dc1147
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go/cmd/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ var (
normalize bool
dbName string
plannerVersionStr string
noScatter bool

numShards = 2
replicationMode = "ROW"
@@ -65,8 +66,9 @@ func registerFlags(fs *pflag.FlagSet) {
fs.BoolVar(&normalize, "normalize", normalize, "Whether to enable vtgate normalization")
fs.StringVar(&dbName, "dbname", dbName, "Optional database target to override normal routing")
fs.StringVar(&plannerVersionStr, "planner-version", plannerVersionStr, "Sets the query planner version to use when generating the explain output. Valid values are V3 and Gen4")
fs.BoolVar(&noScatter, "no_scatter", noScatter, "when set to true, the planner will fail instead of producing a plan that includes scatter queries")
fs.IntVar(&numShards, "shards", numShards, "Number of shards per keyspace. Passing --ks-shard-map/--ks-shard-map-file causes this flag to be ignored.")
fs.StringVar(&executionMode, "execution-mode", executionMode, "The execution mode to simulate -- must be set to multi, legacy-autocommit, or twopc")
fs.StringVar(&executionMode, "execution-mode", executionMode, "The execution mode to simulate -- must be set to multi, legacy-autocommit, single, or twopc")
fs.StringVar(&outputMode, "output-mode", outputMode, "Output in human-friendly text or json")

acl.RegisterFlags(fs)
@@ -144,6 +146,7 @@ func parseAndRun() error {
ReplicationMode: replicationMode,
NumShards: numShards,
Normalize: normalize,
NoScatter: noScatter,
Target: dbName,
}

6 changes: 6 additions & 0 deletions go/vt/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
@@ -58,6 +58,9 @@ const (
// ModeMulti is the default mode with autocommit implemented at vtgate
ModeMulti = "multi"

// ModeSingle is a mode that will allow transactions only across a single shard
ModeSingle = "single"

// ModeTwoPC enables the twopc feature
ModeTwoPC = "twopc"
)
@@ -81,6 +84,9 @@ type (
// Normalize controls whether or not vtgate does query normalization
Normalize bool

// Noscatter controls whether scatter queries are allowed
NoScatter bool

// ExecutionMode must be set to one of the modes above
ExecutionMode string

5 changes: 4 additions & 1 deletion go/vt/vtexplain/vtexplain_vtgate.go
Original file line number Diff line number Diff line change
@@ -72,7 +72,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, streamSize, cache.DefaultConfig, schemaTracker, false, opts.PlannerVersion)
vte.vtgateExecutor = vtgate.NewExecutor(context.Background(), vte.explainTopo, vtexplainCell, resolver, opts.Normalize, false, streamSize, cache.DefaultConfig, schemaTracker, opts.NoScatter, opts.PlannerVersion)

queryLogBufferSize := 10
vtgate.QueryLogger = streamlog.New("VTGate", queryLogBufferSize)
@@ -89,6 +89,9 @@ func (vte *VTExplain) newFakeResolver(opts *Options, serv srvtopo.Server, cell s
if opts.ExecutionMode == ModeTwoPC {
txMode = vtgatepb.TransactionMode_TWOPC
}
if opts.ExecutionMode == ModeSingle {
txMode = vtgatepb.TransactionMode_SINGLE
}
tc := vtgate.NewTxConn(gw, txMode)
sc := vtgate.NewScatterConn("", tc, gw)
srvResolver := srvtopo.NewResolver(serv, gw, cell)

0 comments on commit 5dc1147

Please sign in to comment.