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
11 changes: 9 additions & 2 deletions go/test/endtoend/cluster/vtgate_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type VtgateProcess struct {
MySQLAuthServerImpl string
Directory string
VerifyURL string
SysVarSetEnabled bool
//Extra Args to be set before starting the vtgate process
ExtraArgs []string

Expand All @@ -63,8 +64,7 @@ type VtgateProcess struct {
// Setup starts Vtgate process with required arguements
func (vtgate *VtgateProcess) Setup() (err error) {

vtgate.proc = exec.Command(
vtgate.Binary,
args := []string{
"-topo_implementation", vtgate.CommonArg.TopoImplementation,
"-topo_global_server_address", vtgate.CommonArg.TopoGlobalAddress,
"-topo_global_root", vtgate.CommonArg.TopoGlobalRoot,
Expand All @@ -80,6 +80,13 @@ func (vtgate *VtgateProcess) Setup() (err error) {
"-gateway_implementation", vtgate.GatewayImplementation,
"-service_map", vtgate.ServiceMap,
"-mysql_auth_server_impl", vtgate.MySQLAuthServerImpl,
}
if vtgate.SysVarSetEnabled {
args = append(args, "-enable_system_settings")
}
vtgate.proc = exec.Command(
vtgate.Binary,
args...,
)
if *isCoverage {
vtgate.proc.Args = append(vtgate.proc.Args, "-test.coverprofile="+getCoveragePath("vtgate.out"))
Expand Down
4 changes: 3 additions & 1 deletion go/test/endtoend/vtgate/setstatement/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func TestMain(m *testing.M) {
}

// Start vtgate
if err := clusterInstance.StartVtgate(); err != nil {
vtgateProcess := clusterInstance.NewVtgateInstance()
vtgateProcess.SysVarSetEnabled = true
if err := vtgateProcess.Setup(); err != nil {
return 1
}

Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func TestExecutorSet(t *testing.T) {

func TestExecutorSetOp(t *testing.T) {
executor, _, _, sbclookup := createLegacyExecutorEnv()
*sysVarSetEnabled = true

sbclookup.SetResults([]*sqltypes.Result{
sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_mode", "varchar"), "STRICT_ALL_TABLES,NO_AUTO_UPDATES"),
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type ContextVSchema interface {
TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error)
AnyKeyspace() (*vindexes.Keyspace, error)
FirstSortedKeyspace() (*vindexes.Keyspace, error)
SysVarSetEnabled() bool
}

//-------------------------------------------------------------------------
Expand Down
28 changes: 23 additions & 5 deletions go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func init() {

func TestPlan(t *testing.T) {
vschemaWrapper := &vschemaWrapper{
v: loadSchema(t, "schema_test.json"),
v: loadSchema(t, "schema_test.json"),
sysVarEnabled: true,
}

testOutputTempDir, err := ioutil.TempDir("", "plan_test")
Expand Down Expand Up @@ -178,6 +179,18 @@ func TestPlan(t *testing.T) {
testFile(t, "lock_cases.txt", testOutputTempDir, vschemaWrapper)
}

func TestSysVarSetDisabled(t *testing.T) {
vschemaWrapper := &vschemaWrapper{
v: loadSchema(t, "schema_test.json"),
sysVarEnabled: false,
}

testOutputTempDir, err := ioutil.TempDir("", "plan_test")
require.NoError(t, err)
defer os.RemoveAll(testOutputTempDir)
testFile(t, "set_sysvar_disabled_cases.txt", testOutputTempDir, vschemaWrapper)
}

func TestOne(t *testing.T) {
vschema := &vschemaWrapper{
v: loadSchema(t, "schema_test.json"),
Expand Down Expand Up @@ -258,10 +271,15 @@ func loadSchema(t *testing.T, filename string) *vindexes.VSchema {
var _ ContextVSchema = (*vschemaWrapper)(nil)

type vschemaWrapper struct {
v *vindexes.VSchema
keyspace *vindexes.Keyspace
tabletType topodatapb.TabletType
dest key.Destination
v *vindexes.VSchema
keyspace *vindexes.Keyspace
tabletType topodatapb.TabletType
dest key.Destination
sysVarEnabled bool
}

func (vw *vschemaWrapper) SysVarSetEnabled() bool {
return vw.sysVarEnabled
}

func (vw *vschemaWrapper) TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error) {
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vtgate/planbuilder/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ func expressionOkToDelegateToTablet(e sqlparser.Expr) bool {
}

func buildSetOpVarSet(expr *sqlparser.SetExpr, vschema ContextVSchema) (engine.SetOp, error) {
if !vschema.SysVarSetEnabled() {
return buildSetOpCheckAndIgnore(expr, vschema)
}
ks, err := vschema.AnyKeyspace()
if err != nil {
return nil, err
Expand Down
36 changes: 36 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/set_sysvar_disabled_cases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# set passthrough disabled - check and ignore plan
"set @@sql_mode = concat(@@sql_mode, ',NO_AUTO_CREATE_USER'), @@sql_safe_updates = 1"
{
"QueryType": "SET",
"Original": "set @@sql_mode = concat(@@sql_mode, ',NO_AUTO_CREATE_USER'), @@sql_safe_updates = 1",
"Instructions": {
"OperatorType": "Set",
"Ops": [
{
"Type": "SysVarCheckAndIgnore",
"Name": "sql_mode",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": {},
"Expr": "concat(@@sql_mode, ',NO_AUTO_CREATE_USER')"
},
{
"Type": "SysVarCheckAndIgnore",
"Name": "sql_safe_updates",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": {},
"Expr": "1"
}
],
"Inputs": [
{
"OperatorType": "SingleRow"
}
]
}
}
4 changes: 4 additions & 0 deletions go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ func (vc *vcursorImpl) TargetDestination(qualifier string) (key.Destination, *vi
return vc.destination, keyspace.Keyspace, vc.tabletType, nil
}

func (vc *vcursorImpl) SysVarSetEnabled() bool {
return *sysVarSetEnabled
}

// ParseDestinationTarget parses destination target string and sets default keyspace if possible.
func parseDestinationTarget(targetString string, vschema *vindexes.VSchema) (string, topodatapb.TabletType, key.Destination, error) {
destKeyspace, destTabletType, dest, err := topoprotopb.ParseDestination(targetString, defaultTabletType)
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ var (
HealthCheckTimeout = flag.Duration("healthcheck_timeout", time.Minute, "the health check timeout period")
maxPayloadSize = flag.Int("max_payload_size", 0, "The threshold for query payloads in bytes. A payload greater than this threshold will result in a failure to handle the query.")
warnPayloadSize = flag.Int("warn_payload_size", 0, "The warning threshold for query payloads in bytes. A payload greater than this threshold will cause the VtGateWarnings.WarnPayloadSizeExceeded counter to be incremented.")

// Put set-passthrough under a flag.
sysVarSetEnabled = flag.Bool("enable_system_settings", false, "This will enable the system settings to be changed per session at the database connection level")
)

func getTxMode() vtgatepb.TransactionMode {
Expand Down