Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of @@enable_system_settings to vtgate #7300

Merged
merged 10 commits into from
Jan 20, 2021
Prev Previous commit
Next Next commit
New tests and condition on vcursor SysVarSetEnabled
Signed-off-by: Florent Poinsard <[email protected]>
frouioui committed Jan 17, 2021
commit 59702c1e6944d87df0b3d6f9e134058095fc4a3b
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -261,6 +261,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -582,6 +583,7 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
2 changes: 1 addition & 1 deletion go/vt/sysvars/sysvars.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ var (
Charset = SystemVariable{Name: "charset", Default: utf8, IdentifierAsString: true}
Names = SystemVariable{Name: "names", Default: utf8, IdentifierAsString: true}
SessionUUID = SystemVariable{Name: "session_uuid", IdentifierAsString: true}
AllowUseReservedConn = SystemVariable{Name: "use_reserved_connection", IsBoolean: true, Default: off}
AllowUseReservedConn = SystemVariable{Name: "use_reserved_connection", IsBoolean: true, Default: on}
// Online DDL
DDLStrategy = SystemVariable{Name: "ddl_strategy", IdentifierAsString: true}
VitessVersion = SystemVariable{Name: "vitess_version", IdentifierAsString: true}
4 changes: 4 additions & 0 deletions go/vt/vtgate/engine/fake_vcursor_test.go
Original file line number Diff line number Diff line change
@@ -77,6 +77,10 @@ func (t noopVCursor) SetAllowUseReservedConn(allow bool) error {
panic("implement me")
}

func (t noopVCursor) GetAllowUseReservedConn() bool {
panic("implement me")
}

func (t noopVCursor) SetReadAfterWriteTimeout(f float64) {
panic("implement me")
}
1 change: 1 addition & 0 deletions go/vt/vtgate/engine/primitive.go
Original file line number Diff line number Diff line change
@@ -135,6 +135,7 @@ type (
GetSessionUUID() string

SetAllowUseReservedConn(bool) error
GetAllowUseReservedConn() bool

// SetReadAfterWriteGTID sets the GTID that the user expects a replica to have caught up with before answering a query
SetReadAfterWriteGTID(string)
19 changes: 19 additions & 0 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
@@ -228,6 +228,24 @@ func TestExecutorSet(t *testing.T) {
}, {
in: "set session transaction read write",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set @@use_reserved_connection = on",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: true},
}, {
in: "set @@use_reserved_connection = off",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: false},
}, {
in: "set @@use_reserved_connection = 1",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: true},
}, {
in: "set @@use_reserved_connection = 0",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: false},
}, {
in: "set @@use_reserved_connection = true",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: true},
}, {
in: "set @@use_reserved_connection = false",
out: &vtgatepb.Session{Autocommit: true, UseReservedConnection: false},
}}
for i, tcase := range testcases {
t.Run(fmt.Sprintf("%d-%s", i, tcase.in), func(t *testing.T) {
@@ -317,6 +335,7 @@ func TestExecutorSetOp(t *testing.T) {
t.Run(tcase.in, func(t *testing.T) {
session := NewAutocommitSession(masterSession)
session.TargetString = KsTestUnsharded
session.UseReservedConnection = true
_, err := executor.Execute(
context.Background(),
"TestExecute",
7 changes: 4 additions & 3 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
@@ -342,9 +342,10 @@ func (vh *vtgateHandler) session(c *mysql.Conn) *vtgatepb.Session {
IncludedFields: querypb.ExecuteOptions_ALL,
Workload: querypb.ExecuteOptions_Workload(mysqlDefaultWorkload),
},
Autocommit: true,
DDLStrategy: *defaultDDLStrategy,
SessionUUID: u.String(),
Autocommit: true,
DDLStrategy: *defaultDDLStrategy,
SessionUUID: u.String(),
UseReservedConnection: true,
}
if c.Capabilities&mysql.CapabilityClientFoundRows != 0 {
session.Options.ClientFoundRows = true
9 changes: 8 additions & 1 deletion go/vt/vtgate/safe_session.go
Original file line number Diff line number Diff line change
@@ -478,13 +478,20 @@ func (session *SafeSession) GetSessionUUID() string {
return session.SessionUUID
}

// SetAllowUseReservedConn returns the AllowUseReservedConn value.
// SetAllowUseReservedConn set the AllowUseReservedConn setting.
func (session *SafeSession) SetAllowUseReservedConn(allow bool) {
session.mu.Lock()
defer session.mu.Unlock()
session.UseReservedConnection = allow
}

// GetAllowUseReservedConn returns the AllowUseReservedConn value.
func (session *SafeSession) GetAllowUseReservedConn() bool {
session.mu.Lock()
defer session.mu.Unlock()
return session.UseReservedConnection
}

// SetReadAfterWriteGTID set the ReadAfterWriteGtid setting.
func (session *SafeSession) SetReadAfterWriteGTID(vtgtid string) {
session.mu.Lock()
7 changes: 6 additions & 1 deletion go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
@@ -329,7 +329,7 @@ func (vc *vcursorImpl) FirstSortedKeyspace() (*vindexes.Keyspace, error) {

// SysVarSetEnabled implements the ContextVSchema interface
func (vc *vcursorImpl) SysVarSetEnabled() bool {
return *sysVarSetEnabled
return vc.GetAllowUseReservedConn() && *sysVarSetEnabled
}

// KeyspaceExists provides whether the keyspace exists or not.
@@ -667,6 +667,11 @@ func (vc *vcursorImpl) SetAllowUseReservedConn(allow bool) error {
return nil
}

// GetAllowUseReservedConn implements the SessionActions interface
func (vc *vcursorImpl) GetAllowUseReservedConn() bool {
return vc.safeSession.GetAllowUseReservedConn()
}

// SetReadAfterWriteGTID implements the SessionActions interface
func (vc *vcursorImpl) SetReadAfterWriteGTID(vtgtid string) {
vc.safeSession.SetReadAfterWriteGTID(vtgtid)