diff --git a/changelog/21.0/21.0.0/summary.md b/changelog/21.0/21.0.0/summary.md
index 1d894120cae..7946293f506 100644
--- a/changelog/21.0/21.0.0/summary.md
+++ b/changelog/21.0/21.0.0/summary.md
@@ -4,13 +4,14 @@
### Table of Contents
- **[Major Changes](#major-changes)**
- - **[Deletions](#deletions)**
+ - **[Deprecations and Deletions](#deprecations-and-deletions)**
- [Deletion of deprecated metrics](#metric-deletion)
+ - [VTTablet Flags](#vttablet-flags)
- **[Breaking changes](#breaking-changes)**
## Major Changes
-### Deletion
+### Deprecations and Deletions
#### Deletion of deprecated metrics
@@ -31,6 +32,9 @@ The following metrics that were deprecated in the previous release, have now bee
| `emergency_reparent_counts` |
| `planned_reparent_counts` |
| `reparent_shard_operation_timings` |
-
+#### VTTablet Flags
+
+- `queryserver-enable-settings-pool` flag, added in v15, has been on by default since v17.
+It is now deprecated and will be removed in a future release.
diff --git a/go/flags/endtoend/vtcombo.txt b/go/flags/endtoend/vtcombo.txt
index 8d868e9f49c..fa9b3d6907e 100644
--- a/go/flags/endtoend/vtcombo.txt
+++ b/go/flags/endtoend/vtcombo.txt
@@ -298,7 +298,6 @@ Flags:
--queryserver-config-truncate-error-len int truncate errors sent to client if they are longer than this value (0 means do not truncate)
--queryserver-config-txpool-timeout duration query server transaction pool timeout, it is how long vttablet waits if tx pool is full (default 1s)
--queryserver-config-warn-result-size int query server result size warning threshold, warn if number of rows returned from vttablet for non-streaming queries exceeds this
- --queryserver-enable-settings-pool Enable pooling of connections with modified system settings (default true)
--queryserver-enable-views Enable views support in vttablet.
--queryserver_enable_online_ddl Enable online DDL. (default true)
--redact-debug-ui-queries redact full queries and bind variables from debug UI
diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt
index d160968e014..40d686979c0 100644
--- a/go/flags/endtoend/vttablet.txt
+++ b/go/flags/endtoend/vttablet.txt
@@ -289,7 +289,6 @@ Flags:
--queryserver-config-truncate-error-len int truncate errors sent to client if they are longer than this value (0 means do not truncate)
--queryserver-config-txpool-timeout duration query server transaction pool timeout, it is how long vttablet waits if tx pool is full (default 1s)
--queryserver-config-warn-result-size int query server result size warning threshold, warn if number of rows returned from vttablet for non-streaming queries exceeds this
- --queryserver-enable-settings-pool Enable pooling of connections with modified system settings (default true)
--queryserver-enable-views Enable views support in vttablet.
--queryserver_enable_online_ddl Enable online DDL. (default true)
--redact-debug-ui-queries redact full queries and bind variables from debug UI
diff --git a/go/test/endtoend/reparent/prssettingspool/main_test.go b/go/test/endtoend/reparent/prssettingspool/main_test.go
index 872f1867c77..4364836841b 100644
--- a/go/test/endtoend/reparent/prssettingspool/main_test.go
+++ b/go/test/endtoend/reparent/prssettingspool/main_test.go
@@ -61,8 +61,6 @@ func TestMain(m *testing.M) {
Name: keyspaceName,
SchemaSQL: schemaSQL,
}
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs,
- "--queryserver-enable-settings-pool")
err = clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false)
if err != nil {
return 1
diff --git a/go/test/endtoend/vtgate/reservedconn/main_test.go b/go/test/endtoend/vtgate/reservedconn/main_test.go
index 528182a82e2..8c0278604f7 100644
--- a/go/test/endtoend/vtgate/reservedconn/main_test.go
+++ b/go/test/endtoend/vtgate/reservedconn/main_test.go
@@ -100,61 +100,46 @@ CREATE TABLE test_vdx (
`
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
-func runAllTests(m *testing.M) int {
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
-
- // Start keyspace
- keyspace := &cluster.Keyspace{
- Name: keyspaceName,
- SchemaSQL: sqlSchema,
- VSchema: vSchema,
- }
- clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "5s"}
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, false); err != nil {
- return 1
- }
-
- // Start vtgate
- // This test requires setting the mysql_server_version vtgate flag
- // to 5.7 regardless of the actual MySQL version used for the tests.
- clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s", "--mysql_server_version", "5.7.0"}
- clusterInstance.VtGatePlannerVersion = querypb.ExecuteOptions_Gen4
- if err := clusterInstance.StartVtgate(); err != nil {
- return 1
- }
-
- vtParams = mysql.ConnParams{
- Host: clusterInstance.Hostname,
- Port: clusterInstance.VtgateMySQLPort,
- }
- return m.Run()
+ // Start keyspace
+ keyspace := &cluster.Keyspace{
+ Name: keyspaceName,
+ SchemaSQL: sqlSchema,
+ VSchema: vSchema,
+ }
+ clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "5s"}
+ if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, false); err != nil {
+ return 1
+ }
+
+ // Start vtgate
+ // This test requires setting the mysql_server_version vtgate flag
+ // to 5.7 regardless of the actual MySQL version used for the tests.
+ clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s", "--mysql_server_version", "5.7.0"}
+ clusterInstance.VtGatePlannerVersion = querypb.ExecuteOptions_Gen4
+ if err := clusterInstance.StartVtgate(); err != nil {
+ return 1
+ }
+
+ vtParams = mysql.ConnParams{
+ Host: clusterInstance.Hostname,
+ Port: clusterInstance.VtgateMySQLPort,
+ }
+ return m.Run()
+ }()
+ os.Exit(exitCode)
}
func assertIsEmpty(t *testing.T, conn *mysql.Conn, query string) {
diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go
index 491ce6bc6ab..9a4d7c50dbd 100644
--- a/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go
+++ b/go/test/endtoend/vtgate/reservedconn/reconnect1/main_test.go
@@ -62,58 +62,42 @@ var (
`
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
-
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
-
-func runAllTests(m *testing.M) int {
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
- // Start keyspace
- keyspace := &cluster.Keyspace{
- Name: keyspaceName,
- SchemaSQL: sqlSchema,
- VSchema: vSchema,
- }
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
- return 1
- }
+ // Start keyspace
+ keyspace := &cluster.Keyspace{
+ Name: keyspaceName,
+ SchemaSQL: sqlSchema,
+ VSchema: vSchema,
+ }
+ if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
+ return 1
+ }
- // Start vtgate
- clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s"}
- if err := clusterInstance.StartVtgate(); err != nil {
- return 1
- }
+ // Start vtgate
+ clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s"}
+ if err := clusterInstance.StartVtgate(); err != nil {
+ return 1
+ }
- vtParams = mysql.ConnParams{
- Host: clusterInstance.Hostname,
- Port: clusterInstance.VtgateMySQLPort,
- }
- return m.Run()
+ vtParams = mysql.ConnParams{
+ Host: clusterInstance.Hostname,
+ Port: clusterInstance.VtgateMySQLPort,
+ }
+ return m.Run()
+ }()
+ os.Exit(exitCode)
}
func TestServingChange(t *testing.T) {
diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go
index a448574c282..915d76051a4 100644
--- a/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go
+++ b/go/test/endtoend/vtgate/reservedconn/reconnect2/main_test.go
@@ -63,58 +63,44 @@ var (
`
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
+
+ // Start keyspace
+ keyspace := &cluster.Keyspace{
+ Name: keyspaceName,
+ SchemaSQL: sqlSchema,
+ VSchema: vSchema,
+ }
+ clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "5s"}
+ if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
+ return 1
+ }
+
+ // Start vtgate
+ clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s"}
+ if err := clusterInstance.StartVtgate(); err != nil {
+ return 1
+ }
+
+ vtParams = mysql.ConnParams{
+ Host: clusterInstance.Hostname,
+ Port: clusterInstance.VtgateMySQLPort,
+ }
+ return m.Run()
+ }()
+ os.Exit(exitCode)
-func runAllTests(m *testing.M) int {
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
-
- // Start keyspace
- keyspace := &cluster.Keyspace{
- Name: keyspaceName,
- SchemaSQL: sqlSchema,
- VSchema: vSchema,
- }
- clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "5s"}
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true); err != nil {
- return 1
- }
-
- // Start vtgate
- clusterInstance.VtGateExtraArgs = []string{"--lock_heartbeat_time", "2s"}
- if err := clusterInstance.StartVtgate(); err != nil {
- return 1
- }
-
- vtParams = mysql.ConnParams{
- Host: clusterInstance.Hostname,
- Port: clusterInstance.VtgateMySQLPort,
- }
- return m.Run()
}
func TestTabletChange(t *testing.T) {
diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go
index 677c24666b2..20d255941db 100644
--- a/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go
+++ b/go/test/endtoend/vtgate/reservedconn/reconnect3/main_test.go
@@ -39,55 +39,40 @@ var (
sqlSchema = `create table test(id bigint primary key)Engine=InnoDB;`
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
-
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
-
-func runAllTests(m *testing.M) int {
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
-
- // Start keyspace
- keyspace := &cluster.Keyspace{
- Name: keyspaceName,
- SchemaSQL: sqlSchema,
- }
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil {
- return 1
- }
-
- // Start vtgate
- if err := clusterInstance.StartVtgate(); err != nil {
- return 1
- }
-
- vtParams = mysql.ConnParams{
- Host: clusterInstance.Hostname,
- Port: clusterInstance.VtgateMySQLPort,
- }
- return m.Run()
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
+
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
+
+ // Start keyspace
+ keyspace := &cluster.Keyspace{
+ Name: keyspaceName,
+ SchemaSQL: sqlSchema,
+ }
+ if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil {
+ return 1
+ }
+
+ // Start vtgate
+ if err := clusterInstance.StartVtgate(); err != nil {
+ return 1
+ }
+
+ vtParams = mysql.ConnParams{
+ Host: clusterInstance.Hostname,
+ Port: clusterInstance.VtgateMySQLPort,
+ }
+ return m.Run()
+ }()
+ os.Exit(exitCode)
}
func TestMysqlDownServingChange(t *testing.T) {
diff --git a/go/test/endtoend/vtgate/reservedconn/reconnect4/main_test.go b/go/test/endtoend/vtgate/reservedconn/reconnect4/main_test.go
index 1dc53a89506..d4a61665a6d 100644
--- a/go/test/endtoend/vtgate/reservedconn/reconnect4/main_test.go
+++ b/go/test/endtoend/vtgate/reservedconn/reconnect4/main_test.go
@@ -39,55 +39,40 @@ var (
sqlSchema = `create table test(id bigint primary key)Engine=InnoDB;`
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
-
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
-
-func runAllTests(m *testing.M) int {
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
-
- // Start keyspace
- keyspace := &cluster.Keyspace{
- Name: keyspaceName,
- SchemaSQL: sqlSchema,
- }
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil {
- return 1
- }
-
- // Start vtgate
- if err := clusterInstance.StartVtgate(); err != nil {
- return 1
- }
-
- vtParams = mysql.ConnParams{
- Host: clusterInstance.Hostname,
- Port: clusterInstance.VtgateMySQLPort,
- }
- return m.Run()
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
+
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
+
+ // Start keyspace
+ keyspace := &cluster.Keyspace{
+ Name: keyspaceName,
+ SchemaSQL: sqlSchema,
+ }
+ if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 2, false); err != nil {
+ return 1
+ }
+
+ // Start vtgate
+ if err := clusterInstance.StartVtgate(); err != nil {
+ return 1
+ }
+
+ vtParams = mysql.ConnParams{
+ Host: clusterInstance.Hostname,
+ Port: clusterInstance.VtgateMySQLPort,
+ }
+ return m.Run()
+ }()
+ os.Exit(exitCode)
}
func TestVttabletDownServingChange(t *testing.T) {
diff --git a/go/test/endtoend/vtgate/unsharded/main_test.go b/go/test/endtoend/vtgate/unsharded/main_test.go
index 461a3c73b35..91326acce4d 100644
--- a/go/test/endtoend/vtgate/unsharded/main_test.go
+++ b/go/test/endtoend/vtgate/unsharded/main_test.go
@@ -146,62 +146,47 @@ END;
`}
)
-var enableSettingsPool bool
-
func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()
- code := runAllTests(m)
- if code != 0 {
- os.Exit(code)
- }
-
- println("running with settings pool enabled")
- // run again with settings pool enabled.
- enableSettingsPool = true
- code = runAllTests(m)
- os.Exit(code)
-}
-
-func runAllTests(m *testing.M) int {
- clusterInstance = cluster.NewCluster(cell, hostname)
- defer clusterInstance.Teardown()
-
- // Start topo server
- if err := clusterInstance.StartTopo(); err != nil {
- return 1
- }
-
- // Start keyspace
- Keyspace := &cluster.Keyspace{
- Name: KeyspaceName,
- SchemaSQL: SchemaSQL,
- VSchema: VSchema,
- }
- clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "3s", "--queryserver-config-max-result-size", "30"}
- if enableSettingsPool {
- clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, "--queryserver-enable-settings-pool")
- }
- if err := clusterInstance.StartUnshardedKeyspace(*Keyspace, 0, false); err != nil {
- log.Fatal(err.Error())
- return 1
- }
-
- // Start vtgate
- clusterInstance.VtGateExtraArgs = []string{"--warn_sharded_only=true"}
- if err := clusterInstance.StartVtgate(); err != nil {
- log.Fatal(err.Error())
- return 1
- }
-
- primaryTablet := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet().VttabletProcess
- if err := primaryTablet.QueryTabletMultiple(createProcSQL, KeyspaceName, true); err != nil {
- log.Fatal(err.Error())
- return 1
- }
-
- return m.Run()
+ exitCode := func() int {
+ clusterInstance = cluster.NewCluster(cell, hostname)
+ defer clusterInstance.Teardown()
+
+ // Start topo server
+ if err := clusterInstance.StartTopo(); err != nil {
+ return 1
+ }
+
+ // Start keyspace
+ Keyspace := &cluster.Keyspace{
+ Name: KeyspaceName,
+ SchemaSQL: SchemaSQL,
+ VSchema: VSchema,
+ }
+ clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-transaction-timeout", "3s", "--queryserver-config-max-result-size", "30"}
+ if err := clusterInstance.StartUnshardedKeyspace(*Keyspace, 0, false); err != nil {
+ log.Fatal(err.Error())
+ return 1
+ }
+
+ // Start vtgate
+ clusterInstance.VtGateExtraArgs = []string{"--warn_sharded_only=true"}
+ if err := clusterInstance.StartVtgate(); err != nil {
+ log.Fatal(err.Error())
+ return 1
+ }
+
+ primaryTablet := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet().VttabletProcess
+ if err := primaryTablet.QueryTabletMultiple(createProcSQL, KeyspaceName, true); err != nil {
+ log.Fatal(err.Error())
+ return 1
+ }
+
+ return m.Run()
+ }()
+ os.Exit(exitCode)
}
func TestSelectIntoAndLoadFrom(t *testing.T) {
diff --git a/go/vt/vttablet/endtoend/reserve_test.go b/go/vt/vttablet/endtoend/reserve_test.go
index d3fb685dd49..0712233c559 100644
--- a/go/vt/vttablet/endtoend/reserve_test.go
+++ b/go/vt/vttablet/endtoend/reserve_test.go
@@ -17,1178 +17,13 @@ limitations under the License.
package endtoend
import (
- "fmt"
- "sync"
"testing"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
-
"vitess.io/vitess/go/vt/vttablet/endtoend/framework"
)
-func TestMultipleReserveHaveDifferentConnection(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client1 := framework.NewClient()
- client2 := framework.NewClient()
-
- query := "select connection_id()"
-
- qrc1_1, err := client1.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- defer client1.Release()
- qrc2_1, err := client2.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- defer client2.Release()
- require.NotEqual(t, qrc1_1.Rows, qrc2_1.Rows)
-
- qrc1_2, err := client1.Execute(query, nil)
- require.NoError(t, err)
- qrc2_2, err := client2.Execute(query, nil)
- require.NoError(t, err)
- require.Equal(t, qrc1_1.Rows, qrc1_2.Rows)
- require.Equal(t, qrc2_1.Rows, qrc2_2.Rows)
-}
-
-func TestReserveBeginRelease(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qr1, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- qr2, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, client.ReservedID(), client.TransactionID())
-
- require.NoError(t, client.Release())
-}
-
-func TestBeginReserveRelease(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qr1, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- qr2, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, client.ReservedID(), client.TransactionID())
-
- require.NoError(t, client.Release())
-}
-
-func TestReserveBeginExecuteRelease(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"
- selQuery := "select intval from vitess_test where intval = 4"
- _, err := client.ReserveBeginExecute(insQuery, nil, nil, nil)
- require.NoError(t, err)
-
- qr, err := client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[[INT32(4)]]`, fmt.Sprintf("%v", qr.Rows))
-
- err = client.Release()
- require.NoError(t, err)
-
- qr, err = client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))
-}
-
-func TestMultipleReserveBeginHaveDifferentConnection(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client1 := framework.NewClient()
- client2 := framework.NewClient()
-
- query := "select connection_id()"
-
- qrc1_1, err := client1.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client1.Release()
- qrc2_1, err := client2.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client2.Release()
- require.NotEqual(t, qrc1_1.Rows, qrc2_1.Rows)
-
- qrc1_2, err := client1.Execute(query, nil)
- require.NoError(t, err)
- qrc2_2, err := client2.Execute(query, nil)
- require.NoError(t, err)
- require.Equal(t, qrc1_1.Rows, qrc1_2.Rows)
- require.Equal(t, qrc2_1.Rows, qrc2_2.Rows)
-}
-
-func TestCommitOnReserveBeginConn(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- oldRID := client.ReservedID()
- err = client.Commit()
- require.NoError(t, err)
- assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after commit")
- assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")
-
- qr2, err := client.Execute(query, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
-}
-
-func TestRollbackOnReserveBeginConn(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- oldRID := client.ReservedID()
- err = client.Rollback()
- require.NoError(t, err)
- assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")
- assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")
-
- qr2, err := client.Execute(query, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
-}
-
-func TestReserveBeginRollbackAndBeginCommitAgain(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qr1, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- oldRID := client.ReservedID()
- err = client.Rollback()
- require.NoError(t, err)
- assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after rollback")
- assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")
-
- oldRID = client.ReservedID()
-
- qr2, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
-
- err = client.Commit()
- require.NoError(t, err)
- assert.EqualValues(t, 0, client.TransactionID(), "transactionID should be 0 after commit")
- assert.NotEqual(t, client.ReservedID(), oldRID, "reservedID must change after rollback")
-
- qr3, err := client.Execute(query, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, qr2.Rows, qr3.Rows)
-
- require.NoError(t,
- client.Release())
-}
-
-func TestReserveBeginCommitFailToReuseTxID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- _, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- oldTxID := client.TransactionID()
-
- err = client.Commit()
- require.NoError(t, err)
-
- client.SetTransactionID(oldTxID)
-
- _, err = client.Execute(query, nil)
- require.Error(t, err)
- require.NoError(t,
- client.Release())
-}
-
-func TestReserveBeginRollbackFailToReuseTxID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- _, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- oldTxID := client.TransactionID()
-
- err = client.Rollback()
- require.NoError(t, err)
-
- client.SetTransactionID(oldTxID)
-
- _, err = client.Execute(query, nil)
- require.Error(t, err)
- require.NoError(t,
- client.Release())
-}
-
-func TestReserveBeginCommitFailToReuseOldReservedID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- _, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
-
- oldRID := client.ReservedID()
-
- err = client.Commit()
- require.NoError(t, err)
- newRID := client.ReservedID()
-
- client.SetReservedID(oldRID)
-
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-
- client.SetReservedID(newRID)
- require.NoError(t,
- client.Release())
-}
-
-func TestReserveBeginRollbackFailToReuseOldReservedID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- _, err := client.ReserveBeginExecute(query, nil, nil, nil)
- require.NoError(t, err)
-
- oldRID := client.ReservedID()
-
- err = client.Rollback()
- require.NoError(t, err)
- newRID := client.ReservedID()
-
- client.SetReservedID(oldRID)
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-
- client.SetReservedID(newRID)
- require.NoError(t,
- client.Release())
-}
-
-func TestReserveReleaseAndFailToUseReservedIDAgain(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select 42"
-
- _, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
-
- rID := client.ReservedID()
- require.NoError(t,
- client.Release())
-
- client.SetReservedID(rID)
-
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-}
-
-func TestReserveAndFailToRunTwiceConcurrently(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select 42"
-
- _, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- // WaitGroup will make defer call to wait for go func to complete.
- wg := &sync.WaitGroup{}
- wg.Add(1)
- go func() {
- _, err = client.Execute("select sleep(1)", nil)
- wg.Done()
- }()
- _, err2 := client.Execute("select sleep(1)", nil)
- wg.Wait()
-
- if err == nil && err2 == nil {
- assert.Fail(t, "at least one execution should fail")
- }
-}
-
-func TestBeginReserveCommitAndNewTransactionsOnSameReservedID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qrTx, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
-
- qrRID, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Commit()
- require.NoError(t, err)
-
- qrTx, err = client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Commit()
- require.NoError(t, err)
-
- qrTx, err = client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Rollback()
- require.NoError(t, err)
-
- require.NoError(t,
- client.Release())
-}
-
-func TestBeginReserveRollbackAndNewTransactionsOnSameReservedID(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select connection_id()"
-
- qrTx, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
-
- qrRID, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Rollback()
- require.NoError(t, err)
-
- qrTx, err = client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Commit()
- require.NoError(t, err)
-
- qrTx, err = client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
- require.Equal(t, qrTx.Rows, qrRID.Rows)
-
- err = client.Rollback()
- require.NoError(t, err)
-
- require.NoError(t,
- client.Release())
-}
-
-func TestBeginReserveReleaseAndFailToUseReservedIDAndTxIDAgain(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select 42"
-
- _, err := client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
-
- _, err = client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
-
- rID := client.ReservedID()
- txID := client.TransactionID()
-
- require.NoError(t,
- client.Release())
-
- client.SetReservedID(rID)
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-
- client.SetReservedID(0)
- client.SetTransactionID(txID)
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-}
-
-func TestReserveBeginReleaseAndFailToUseReservedIDAndTxIDAgain(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- query := "select 42"
-
- _, err := client.ReserveExecute(query, nil, nil)
- require.NoError(t, err)
-
- _, err = client.BeginExecute(query, nil, nil)
- require.NoError(t, err)
-
- rID := client.ReservedID()
- txID := client.TransactionID()
-
- require.NoError(t,
- client.Release())
-
- client.SetReservedID(rID)
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-
- client.SetReservedID(0)
- client.SetTransactionID(txID)
- _, err = client.Execute(query, nil)
- require.Error(t, err)
-}
-
-func TestReserveExecuteWithFailingQueryAndReserveConnectionRemainsOpen(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- _, err := client.ReserveExecute("select foo", nil, nil)
- require.Error(t, err)
- defer client.Release()
- require.NotEqual(t, int64(0), client.ReservedID())
-
- _, err = client.Execute("select 42", nil)
- require.NoError(t, err)
- require.NoError(t, client.Release())
-}
-
-func TestReserveAndExecuteWithFailingQueryAndReserveConnectionRemainsOpen(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- qr1, err := client.ReserveExecute("select connection_id()", nil, nil)
- require.NoError(t, err)
- defer client.Release()
-
- _, err = client.Execute("select foo", nil)
- require.Error(t, err)
-
- qr2, err := client.Execute("select connection_id()", nil)
- require.NoError(t, err)
- require.Equal(t, qr1.Rows, qr2.Rows)
- require.NoError(t, client.Release())
-}
-
-func TestReserveBeginExecuteWithFailingQueryAndReserveConnAndTxRemainsOpen(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- _, err := client.ReserveBeginExecute("select foo", nil, nil, nil)
- require.Error(t, err)
-
- // Save the connection id to check in the end that everything got executed on same connection.
- qr1, err := client.Execute("select connection_id()", nil)
- require.NoError(t, err)
-
- _, err = client.Execute("insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)", nil)
- require.NoError(t, err)
-
- qr, err := client.Execute("select intval from vitess_test", nil)
- require.NoError(t, err)
- assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]", fmt.Sprintf("%v", qr.Rows))
-
- err = client.Rollback()
- require.NoError(t, err)
-
- qr, err = client.Execute("select intval from vitess_test", nil)
- require.NoError(t, err)
- assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)]]", fmt.Sprintf("%v", qr.Rows))
-
- qr2, err := client.Execute("select connection_id()", nil)
- require.NoError(t, err)
- require.Equal(t, qr1.Rows, qr2.Rows)
-
- require.NoError(t, client.Release())
-}
-
-func TestReserveAndBeginExecuteWithFailingQueryAndReserveConnAndTxRemainsOpen(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- // Save the connection id to check in the end that everything got executed on same connection.
- qr1, err := client.ReserveExecute("select connection_id()", nil, nil)
- require.NoError(t, err)
-
- _, err = client.BeginExecute("select foo", nil, nil)
- require.Error(t, err)
-
- _, err = client.Execute("insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)", nil)
- require.NoError(t, err)
-
- qr, err := client.Execute("select intval from vitess_test", nil)
- require.NoError(t, err)
- assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]", fmt.Sprintf("%v", qr.Rows))
-
- err = client.Rollback()
- require.NoError(t, err)
-
- qr, err = client.Execute("select intval from vitess_test", nil)
- require.NoError(t, err)
- assert.Equal(t, "[[INT32(1)] [INT32(2)] [INT32(3)]]", fmt.Sprintf("%v", qr.Rows))
-
- qr2, err := client.Execute("select connection_id()", nil)
- require.NoError(t, err)
- require.Equal(t, qr1.Rows, qr2.Rows)
-
- require.NoError(t, client.Release())
-}
-
-func TestReserveExecuteWithPreQueriesAndCheckConnectionState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client1 := framework.NewClient()
- client2 := framework.NewClient()
-
- selQuery := "select str_to_date('00/00/0000', '%m/%d/%Y')"
- warnQuery := "show warnings"
- preQueries1 := []string{
- "set sql_mode = ''",
- }
- preQueries2 := []string{
- "set sql_mode = 'NO_ZERO_DATE'",
- }
-
- qr1, err := client1.ReserveExecute(selQuery, preQueries1, nil)
- require.NoError(t, err)
- defer client1.Release()
-
- qr2, err := client2.ReserveExecute(selQuery, preQueries2, nil)
- require.NoError(t, err)
- defer client2.Release()
-
- assert.NotEqual(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, `[[DATE("0000-00-00")]]`, fmt.Sprintf("%v", qr1.Rows))
- assert.Equal(t, `[[NULL]]`, fmt.Sprintf("%v", qr2.Rows))
-
- qr1, err = client1.Execute(warnQuery, nil)
- require.NoError(t, err)
-
- qr2, err = client2.Execute(warnQuery, nil)
- require.NoError(t, err)
-
- assert.NotEqual(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, `[]`, fmt.Sprintf("%v", qr1.Rows))
- assert.Equal(t, `[[VARCHAR("Warning") UINT32(1411) VARCHAR("Incorrect datetime value: '00/00/0000' for function str_to_date")]]`, fmt.Sprintf("%v", qr2.Rows))
-}
-
-func TestReserveExecuteWithPreQueriesAndSavepoint(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
- defer client.Release()
-
- insQuery := "insert into vitess_test (intval) values (5)"
- selQuery := "select intval from vitess_test where intval = 5"
- preQueries := []string{
- "set sql_mode = ''",
- }
-
- postBeginQueries1 := []string{
- "savepoint a",
- }
- // savepoint there after begin.
- _, err := client.ReserveBeginExecute(insQuery, preQueries, postBeginQueries1, nil)
- require.NoError(t, err)
-
- qr, err := client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))
-
- _, err = client.Execute("rollback to a", nil)
- require.NoError(t, err)
-
- qr, err = client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))
-
- err = client.Release()
- require.NoError(t, err)
-
- postBeginQueries2 := []string{
- "savepoint a",
- "release savepoint a",
- "savepoint b",
- }
- // no savepoint after begin
- _, err = client.ReserveBeginExecute(insQuery, preQueries, postBeginQueries2, nil)
- require.NoError(t, err)
-
- qr, err = client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))
-
- // no savepoint a
- _, err = client.Execute("rollback to a", nil)
- require.Error(t, err)
-
- // no savepoint a.
- _, err = client.Execute("release a", nil)
- require.Error(t, err)
-
- // record still exists.
- qr, err = client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[[INT32(5)]]`, fmt.Sprintf("%v", qr.Rows))
-
- _, err = client.Execute("rollback to b", nil)
- require.NoError(t, err)
-
- qr, err = client.Execute(selQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, `[]`, fmt.Sprintf("%v", qr.Rows))
-}
-
-func TestReserveBeginExecuteWithPreQueriesAndCheckConnectionState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- rcClient := framework.NewClient()
- rucClient := framework.NewClient()
-
- insRcQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"
- insRucQuery := "insert into vitess_test (intval, floatval, charval, binval) values (5, null, null, null)"
- selQuery := "select intval from vitess_test"
- delQuery := "delete from vitess_test where intval = 5"
- rcQuery := []string{
- "set session transaction isolation level read committed",
- }
- rucQuery := []string{
- "set session transaction isolation level read uncommitted",
- }
-
- _, err := rcClient.ReserveBeginExecute(insRcQuery, rcQuery, nil, nil)
- require.NoError(t, err)
- defer rcClient.Release()
-
- _, err = rucClient.ReserveBeginExecute(insRucQuery, rucQuery, nil, nil)
- require.NoError(t, err)
- defer rucClient.Release()
-
- qr1, err := rcClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- qr2, err := rucClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- assert.NotEqual(t, qr1.Rows, qr2.Rows)
- // As the transaction is read committed it is not able to see #5.
- assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)]]`, fmt.Sprintf("%v", qr1.Rows))
- // As the transaction is read uncommitted it is able to see #4.
- assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)] [INT32(5)]]`, fmt.Sprintf("%v", qr2.Rows))
-
- err = rucClient.Commit()
- require.NoError(t, err)
-
- qr1, err = rcClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- qr2, err = rucClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- // As the transaction on read uncommitted client got committed, transaction with read committed will be able to see #5.
- assert.Equal(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(4)] [INT32(5)]]`, fmt.Sprintf("%v", qr1.Rows))
-
- err = rcClient.Rollback()
- require.NoError(t, err)
-
- qr1, err = rcClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- qr2, err = rucClient.Execute(selQuery, nil)
- require.NoError(t, err)
-
- // As the transaction on read committed client got rolled back, table will forget #4.
- assert.Equal(t, qr1.Rows, qr2.Rows)
- assert.Equal(t, `[[INT32(1)] [INT32(2)] [INT32(3)] [INT32(5)]]`, fmt.Sprintf("%v", qr2.Rows))
-
- // This is executed on reserved connection without transaction as the transaction was committed.
- _, err = rucClient.Execute(delQuery, nil)
- require.NoError(t, err)
-}
-
-func TestReserveExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- selQuery := "select 42"
- preQueries := []string{
- "set @@no_sys_var = 42",
- }
-
- _, err := client.ReserveExecute(selQuery, preQueries, nil)
- require.Error(t, err)
-
- err = client.Release()
- require.Error(t, err)
-}
-
-func TestReserveBeginExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- selQuery := "select 42"
- preQueries := []string{
- "set @@no_sys_var = 42",
- }
-
- _, err := client.ReserveBeginExecute(selQuery, preQueries, nil, nil)
- require.Error(t, err)
-
- err = client.Commit()
- require.Error(t, err)
-
- err = client.Release()
- require.Error(t, err)
-}
-
-func TestBeginReserveExecuteWithFailingPreQueriesAndCheckConnectionState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- selQuery := "select 42"
- preQueries := []string{
- "set @@no_sys_var = 42",
- }
-
- _, err := client.BeginExecute(selQuery, nil, nil)
- require.NoError(t, err)
-
- _, err = client.ReserveExecute(selQuery, preQueries, nil)
- require.Error(t, err)
-
- err = client.Commit()
- require.Error(t, err)
-
- err = client.Release()
- require.Error(t, err)
-}
-
-func TestReserveBeginExecuteWithCommitFailureAndCheckConnectionAndDBState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- connQuery := "select connection_id()"
- insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"
- selQuery := "select intval from vitess_test where intval = 4"
-
- connQr, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)
- require.NoError(t, err)
-
- _, err = client.Execute(insQuery, nil)
- require.NoError(t, err)
-
- killConnection(t, connQr.Rows[0][0].ToString())
-
- err = client.Commit()
- require.Error(t, err)
- require.Zero(t, client.ReservedID())
-
- qr, err := client.Execute(selQuery, nil)
- require.NoError(t, err)
- require.Empty(t, qr.Rows)
-
- qr, err = client.Execute(connQuery, nil)
- require.NoError(t, err)
- require.NotEqual(t, connQr.Rows, qr.Rows)
-
- require.Error(t, client.Release())
-}
-
-func TestReserveBeginExecuteWithRollbackFailureAndCheckConnectionAndDBState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- connQuery := "select connection_id()"
- insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"
- selQuery := "select intval from vitess_test where intval = 4"
-
- connQr, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)
- require.NoError(t, err)
-
- _, err = client.Execute(insQuery, nil)
- require.NoError(t, err)
-
- killConnection(t, connQr.Rows[0][0].ToString())
-
- err = client.Rollback()
- require.Error(t, err)
- require.Zero(t, client.ReservedID())
-
- qr, err := client.Execute(selQuery, nil)
- require.NoError(t, err)
- require.Empty(t, qr.Rows)
-
- qr, err = client.Execute(connQuery, nil)
- require.NoError(t, err)
- require.NotEqual(t, connQr.Rows, qr.Rows)
-
- require.Error(t, client.Release())
-}
-
-func TestReserveExecuteWithExecuteFailureAndCheckConnectionAndDBState(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- connQuery := "select connection_id()"
- insQuery := "insert into vitess_test (intval, floatval, charval, binval) values (4, null, null, null)"
- selQuery := "select intval from vitess_test where intval = 4"
-
- connQr, err := client.ReserveExecute(connQuery, nil, nil)
- require.NoError(t, err)
-
- killConnection(t, connQr.Rows[0][0].ToString())
-
- _, err = client.Execute(insQuery, nil)
- require.Error(t, err)
- // Expectation - require.Zero(t, client.ReservedID())
- // Reality
- require.NotZero(t, client.ReservedID())
-
- // Client still has transaction id and client id as non-zero.
- _, err = client.Execute(selQuery, nil)
- require.Error(t, err)
- client.SetTransactionID(0)
-
- _, err = client.Execute(selQuery, nil)
- require.Error(t, err)
- client.SetReservedID(0)
-
- qr, err := client.Execute(selQuery, nil)
- require.NoError(t, err)
- require.Empty(t, qr.Rows)
-
- qr, err = client.Execute(connQuery, nil)
- require.NoError(t, err)
- require.NotEqual(t, connQr.Rows, qr.Rows)
-
- require.Error(t, client.Release())
-}
-
-func TestReserveExecuteDDLWithoutTx(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
- defer client.Release()
-
- connQuery := "select connection_id()"
- createQuery := "create table vitess_test_ddl(id bigint primary key)"
- dropQuery := "drop table vitess_test_ddl"
- descQuery := "describe vitess_test_ddl"
-
- qr1, err := client.ReserveExecute(connQuery, nil, nil)
- require.NoError(t, err)
-
- _, err = client.Execute(createQuery, nil)
- require.NoError(t, err)
- require.Zero(t, client.TransactionID())
- defer client.Execute(dropQuery, nil)
-
- qr2, err := client.Execute(connQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
-
- qr3, err := client.Execute(descQuery, nil)
- require.NoError(t, err)
- require.NotZero(t, qr3.Rows)
-}
-
-func TestReserveExecuteDDLWithTx(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
- defer client.Release()
-
- connQuery := "select connection_id()"
- createQuery := "create table vitess_test_ddl(id bigint primary key)"
- dropQuery := "drop table vitess_test_ddl"
- descQuery := "describe vitess_test_ddl"
-
- qr1, err := client.ReserveBeginExecute(connQuery, nil, nil, nil)
- require.NoError(t, err)
-
- _, err = client.Execute(createQuery, nil)
- require.NoError(t, err)
- require.NotZero(t, client.TransactionID())
- defer client.Execute(dropQuery, nil)
-
- qr2, err := client.Execute(connQuery, nil)
- require.NoError(t, err)
- assert.Equal(t, qr1.Rows, qr2.Rows)
-
- qr3, err := client.Execute(descQuery, nil)
- require.NoError(t, err)
- require.NotZero(t, qr3.Rows)
-}
-
-func killConnection(t *testing.T, connID string) {
- client := framework.NewClient()
- _, err := client.ReserveExecute("select 1", []string{fmt.Sprintf("kill %s", connID)}, nil)
- require.NoError(t, err)
- defer client.Release()
-}
-
-func BenchmarkPreQueries(b *testing.B) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- tcases := []struct {
- name string
- settings []string
- }{{
- name: "split_1",
- settings: []string{
- "set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"},
- }, {
- name: "split_2",
- settings: []string{
- "set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'",
- "set @@sql_safe_updates = false"},
- }, {
- name: "split_3",
- settings: []string{
- "set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'",
- "set @@sql_safe_updates = false",
- "set @@read_buffer_size = 9191181919"},
- }, {
- name: "split_4",
- settings: []string{
- "set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'",
- "set @@sql_safe_updates = false", "set @@read_buffer_size = 9191181919",
- "set @@max_heap_table_size = 10204023"},
- }, {
- name: "combined_2",
- settings: []string{"set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', @@sql_safe_updates = false"},
- }, {
- name: "combined_3",
- settings: []string{"set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', @@sql_safe_updates = false, @@read_buffer_size = 9191181919"},
- }, {
- name: "combined_4",
- settings: []string{"set @@sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', @@sql_safe_updates = false, @@read_buffer_size = 9191181919, @@max_heap_table_size = 10204023"},
- }}
- query := "select connection_id()"
-
- for _, tcase := range tcases {
- b.Run(tcase.name, func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- if _, err := client.ReserveExecute(query, tcase.settings, nil); err != nil {
- b.Error(err)
- }
- if err := client.Release(); err != nil {
- b.Error(err)
- }
- }
- })
- }
-}
-
-func TestFailInfiniteSessions(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
- qr, err := client.Execute("select @@max_connections", nil)
- require.NoError(t, err)
- maxConn, err := qr.Rows[0][0].ToInt64()
- require.NoError(t, err)
-
- // twice the number of sessions than the pool size.
- numOfSessions := int(maxConn * 2)
-
- var clients []*framework.QueryClient
-
- // read session
- var failed bool
- for i := 0; i < numOfSessions; i++ {
- client := framework.NewClient()
- _, err := client.ReserveExecute("select 1", []string{"set sql_mode = ''"}, nil)
- if err != nil {
- failed = true
- require.Contains(t, err.Error(), "immediate error from server errorCode=1040 errorMsg=Too many connections")
- break
- }
- clients = append(clients, client)
- }
- require.True(t, failed, "should have failed to create more sessions than the max mysql connection")
-
- // Release all the sessions.
- for _, client := range clients {
- require.NoError(t,
- client.Release())
- }
- clients = nil
-
- // write session
- failed = false
- for i := 0; i < numOfSessions; i++ {
- client := framework.NewClient()
- _, err := client.ReserveBeginExecute("select 1", []string{"set sql_mode = ''"}, nil, nil)
- if err != nil {
- failed = true
- require.Contains(t, err.Error(), "immediate error from server errorCode=1040 errorMsg=Too many connections")
- break
- }
- require.NoError(t,
- client.Commit())
- clients = append(clients, client)
- }
- require.True(t, failed, "should have failed to create more sessions than the max mysql connection")
-
- // Release all the sessions.
- for _, client := range clients {
- require.NoError(t,
- client.Release())
- }
-}
-
-func TestReserveQueryTimeout(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
- defer func() {
- framework.Server.Config().EnableSettingsPool = true
- }()
- client := framework.NewClient()
-
- _, err := client.ReserveExecute("select sleep(19)", []string{"set sql_mode = ''"}, nil)
- assert.NoError(t, err)
- assert.NoError(t,
- client.Release())
-
- _, err = client.ReserveStreamExecute("select sleep(19)", []string{"set sql_mode = ''"}, nil)
- assert.NoError(t, err)
- assert.NoError(t,
- client.Release())
-}
-
// TestReserveFlushTables checks that `flush table with read lock` works only with reserve api.
func TestReserveFlushTables(t *testing.T) {
client := framework.NewClient()
diff --git a/go/vt/vttablet/endtoend/settings_test.go b/go/vt/vttablet/endtoend/settings_test.go
index d0a3b4987dd..a459ad15844 100644
--- a/go/vt/vttablet/endtoend/settings_test.go
+++ b/go/vt/vttablet/endtoend/settings_test.go
@@ -355,21 +355,25 @@ func TestInfiniteSessions(t *testing.T) {
}
func TestSetQueriesMultipleWays(t *testing.T) {
- framework.Server.Config().EnableSettingsPool = false
client := framework.NewClient()
defer client.Release()
+ client2 := framework.NewClient()
+ defer client2.Release()
+
+ // This will not reserve the connection, instead use a connection from the pool and change settings.
+ // The connection will be stored with settings state in the pool
_, err := client.ReserveExecute("select 1", []string{"set sql_safe_updates = 1"}, nil)
require.NoError(t, err)
- _, err = client.Execute("set sql_safe_updates = 1", nil)
- require.NoError(t, err)
+ // As no connection is reserved, set statement will fail to execute.
+ _, err = client.Execute("set sql_safe_updates = 0", nil)
+ assert.ErrorContains(t, err, "Set not allowed without reserved connection")
- framework.Server.Config().EnableSettingsPool = true
- client2 := framework.NewClient()
- _, err = client2.ReserveExecute("select 1", []string{"set sql_safe_updates = 1"}, nil)
- require.NoError(t, err)
+ // This will reserve the connection as this is part of the query execution and not the pre-queries to Reserve API
+ _, err = client2.ReserveExecute("set sql_safe_updates = 1", nil, nil)
+ assert.NoError(t, err)
- // this should not panic.
- _, err = client.Execute("set sql_safe_updates = 1", nil)
- require.NoError(t, err)
+ // This will not error out as it gets executed on the reserved connection,
+ _, err = client2.Execute("set sql_safe_updates = 0", nil)
+ assert.NoError(t, err)
}
diff --git a/go/vt/vttablet/tabletserver/tabletenv/config.go b/go/vt/vttablet/tabletserver/tabletenv/config.go
index 1b89829825b..f2cf7e638cf 100644
--- a/go/vt/vttablet/tabletserver/tabletenv/config.go
+++ b/go/vt/vttablet/tabletserver/tabletenv/config.go
@@ -200,7 +200,8 @@ func registerTabletEnvFlags(fs *pflag.FlagSet) {
fs.BoolVar(&enableReplicationReporter, "enable_replication_reporter", false, "Use polling to track replication lag.")
fs.BoolVar(¤tConfig.EnableOnlineDDL, "queryserver_enable_online_ddl", true, "Enable online DDL.")
fs.BoolVar(¤tConfig.SanitizeLogMessages, "sanitize_log_messages", false, "Remove potentially sensitive information in tablet INFO, WARNING, and ERROR log messages such as query parameters.")
- fs.BoolVar(¤tConfig.EnableSettingsPool, "queryserver-enable-settings-pool", true, "Enable pooling of connections with modified system settings")
+ _ = fs.Bool("queryserver-enable-settings-pool", true, "Enable pooling of connections with modified system settings")
+ fs.MarkDeprecated("queryserver-enable-settings-pool", "New pool implementation does it internally and at the api level this has been enabled since v17")
fs.Int64Var(¤tConfig.RowStreamer.MaxInnoDBTrxHistLen, "vreplication_copy_phase_max_innodb_history_list_length", 1000000, "The maximum InnoDB transaction history that can exist on a vstreamer (source) before starting another round of copying rows. This helps to limit the impact on the source tablet.")
fs.Int64Var(¤tConfig.RowStreamer.MaxMySQLReplLagSecs, "vreplication_copy_phase_max_mysql_replication_lag", 43200, "The maximum MySQL replication lag (in seconds) that can exist on a vstreamer (source) before starting another round of copying rows. This helps to limit the impact on the source tablet.")
@@ -354,7 +355,6 @@ type TabletConfig struct {
EnforceStrictTransTables bool `json:"-"`
EnableOnlineDDL bool `json:"-"`
- EnableSettingsPool bool `json:"-"`
RowStreamer RowStreamerConfig `json:"rowStreamer,omitempty"`
@@ -1076,7 +1076,6 @@ var defaultConfig = TabletConfig{
},
EnablePerWorkloadTableMetrics: false,
- EnableSettingsPool: true,
}
// defaultTxThrottlerConfig returns the default TxThrottlerConfigFlag object based on
diff --git a/go/vt/vttablet/tabletserver/tabletserver.go b/go/vt/vttablet/tabletserver/tabletserver.go
index db01e6f2912..eb140454c2a 100644
--- a/go/vt/vttablet/tabletserver/tabletserver.go
+++ b/go/vt/vttablet/tabletserver/tabletserver.go
@@ -1221,19 +1221,19 @@ func (tsv *TabletServer) VStreamResults(ctx context.Context, target *querypb.Tar
// ReserveBeginExecute implements the QueryService interface
func (tsv *TabletServer) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, postBeginQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (state queryservice.ReservedTransactionState, result *sqltypes.Result, err error) {
- if tsv.config.EnableSettingsPool {
- state, result, err = tsv.beginExecuteWithSettings(ctx, target, preQueries, postBeginQueries, sql, bindVariables, options)
- // If there is an error and the error message is about allowing query in reserved connection only,
- // then we do not return an error from here and continue to use the reserved connection path.
- // This is specially for get_lock function call from vtgate that needs a reserved connection.
- if err == nil || !strings.Contains(err.Error(), "not allowed without reserved connection") {
- return state, result, err
- }
- // rollback if transaction was started.
- if state.TransactionID != 0 {
- _, _ = tsv.Rollback(ctx, target, state.TransactionID)
- }
+ state, result, err = tsv.beginExecuteWithSettings(ctx, target, preQueries, postBeginQueries, sql, bindVariables, options)
+ // If there is an error and the error message is about allowing query in reserved connection only,
+ // then we do not return an error from here and continue to use the reserved connection path.
+ // This is specially for get_lock function call from vtgate that needs a reserved connection.
+ if err == nil || !strings.Contains(err.Error(), "not allowed without reserved connection") {
+ return state, result, err
}
+ // rollback if transaction was started.
+ if state.TransactionID != 0 {
+ _, _ = tsv.Rollback(ctx, target, state.TransactionID)
+ }
+
+ // needs a reserved connection.
var connID int64
var sessionStateChanges string
state.TabletAlias = tsv.alias
@@ -1274,65 +1274,34 @@ func (tsv *TabletServer) ReserveBeginExecute(ctx context.Context, target *queryp
func (tsv *TabletServer) ReserveBeginStreamExecute(
ctx context.Context,
target *querypb.Target,
- preQueries []string,
- postBeginQueries []string,
+ settings []string,
+ savepointQueries []string,
sql string,
bindVariables map[string]*querypb.BindVariable,
options *querypb.ExecuteOptions,
callback func(*sqltypes.Result) error,
) (state queryservice.ReservedTransactionState, err error) {
- if tsv.config.EnableSettingsPool {
- return tsv.beginStreamExecuteWithSettings(ctx, target, preQueries, postBeginQueries, sql, bindVariables, options, callback)
- }
-
- var connID int64
- var sessionStateChanges string
-
- err = tsv.execRequest(
- ctx, tsv.loadQueryTimeout(),
- "ReserveBegin", "begin", bindVariables,
- target, options, false, /* allowOnShutdown */
- func(ctx context.Context, logStats *tabletenv.LogStats) error {
- defer tsv.stats.QueryTimings.Record("RESERVE", time.Now())
- targetType, err := tsv.resolveTargetType(ctx, target)
- if err != nil {
- return err
- }
- defer tsv.stats.QueryTimingsByTabletType.Record(targetType.String(), time.Now())
- connID, sessionStateChanges, err = tsv.te.ReserveBegin(ctx, options, preQueries, postBeginQueries)
- if err != nil {
- return err
- }
- logStats.TransactionID = connID
- logStats.ReservedID = connID
- return nil
- },
- )
-
+ txState, err := tsv.begin(ctx, target, savepointQueries, 0, settings, options)
if err != nil {
- return state, err
+ return txToReserveState(txState), err
}
- state.ReservedID = connID
- state.TransactionID = connID
- state.TabletAlias = tsv.alias
- state.SessionStateChanges = sessionStateChanges
- err = tsv.streamExecute(ctx, target, sql, bindVariables, state.TransactionID, state.ReservedID, nil, options, callback)
- return state, err
+ err = tsv.streamExecute(ctx, target, sql, bindVariables, txState.TransactionID, 0, settings, options, callback)
+ return txToReserveState(txState), err
}
// ReserveExecute implements the QueryService interface
func (tsv *TabletServer) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (state queryservice.ReservedState, result *sqltypes.Result, err error) {
- if tsv.config.EnableSettingsPool {
- result, err = tsv.executeWithSettings(ctx, target, preQueries, sql, bindVariables, transactionID, options)
- // If there is an error and the error message is about allowing query in reserved connection only,
- // then we do not return an error from here and continue to use the reserved connection path.
- // This is specially for get_lock function call from vtgate that needs a reserved connection.
- if err == nil || !strings.Contains(err.Error(), "not allowed without reserved connection") {
- return state, result, err
- }
+
+ result, err = tsv.executeWithSettings(ctx, target, preQueries, sql, bindVariables, transactionID, options)
+ // If there is an error and the error message is about allowing query in reserved connection only,
+ // then we do not return an error from here and continue to use the reserved connection path.
+ // This is specially for get_lock function call from vtgate that needs a reserved connection.
+ if err == nil || !strings.Contains(err.Error(), "not allowed without reserved connection") {
+ return state, result, err
}
+ // needs a reserved connection to execute the query.
state.TabletAlias = tsv.alias
allowOnShutdown := false
@@ -1386,48 +1355,7 @@ func (tsv *TabletServer) ReserveStreamExecute(
options *querypb.ExecuteOptions,
callback func(*sqltypes.Result) error,
) (state queryservice.ReservedState, err error) {
- if tsv.config.EnableSettingsPool {
- return state, tsv.streamExecute(ctx, target, sql, bindVariables, transactionID, 0, preQueries, options, callback)
- }
-
- state.TabletAlias = tsv.alias
-
- allowOnShutdown := false
- var timeout time.Duration
- if transactionID != 0 {
- allowOnShutdown = true
- // Use the transaction timeout. ReserveStreamExecute is used for OLAP
- // only, so we can directly fetch the OLAP TX timeout.
- timeout = tsv.config.TxTimeoutForWorkload(querypb.ExecuteOptions_OLAP)
- }
-
- err = tsv.execRequest(
- ctx, timeout,
- "Reserve", "", bindVariables,
- target, options, allowOnShutdown,
- func(ctx context.Context, logStats *tabletenv.LogStats) error {
- defer tsv.stats.QueryTimings.Record("RESERVE", time.Now())
- targetType, err := tsv.resolveTargetType(ctx, target)
- if err != nil {
- return err
- }
- defer tsv.stats.QueryTimingsByTabletType.Record(targetType.String(), time.Now())
- state.ReservedID, err = tsv.te.Reserve(ctx, options, transactionID, preQueries)
- if err != nil {
- return err
- }
- logStats.TransactionID = state.ReservedID
- logStats.ReservedID = state.ReservedID
- return nil
- },
- )
-
- if err != nil {
- return state, err
- }
-
- err = tsv.streamExecute(ctx, target, sql, bindVariables, transactionID, state.ReservedID, nil, options, callback)
- return state, err
+ return state, tsv.streamExecute(ctx, target, sql, bindVariables, transactionID, 0, preQueries, options, callback)
}
// Release implements the QueryService interface
@@ -1477,16 +1405,6 @@ func (tsv *TabletServer) beginExecuteWithSettings(ctx context.Context, target *q
return txToReserveState(txState), result, err
}
-func (tsv *TabletServer) beginStreamExecuteWithSettings(ctx context.Context, target *querypb.Target, settings []string, savepointQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.ReservedTransactionState, error) {
- txState, err := tsv.begin(ctx, target, savepointQueries, 0, settings, options)
- if err != nil {
- return txToReserveState(txState), err
- }
-
- err = tsv.streamExecute(ctx, target, sql, bindVariables, txState.TransactionID, 0, settings, options, callback)
- return txToReserveState(txState), err
-}
-
func txToReserveState(state queryservice.TransactionState) queryservice.ReservedTransactionState {
return queryservice.ReservedTransactionState{
TabletAlias: state.TabletAlias,
diff --git a/go/vt/vttablet/tabletserver/tabletserver_test.go b/go/vt/vttablet/tabletserver/tabletserver_test.go
index ee91f05c2a5..563ab5e84b3 100644
--- a/go/vt/vttablet/tabletserver/tabletserver_test.go
+++ b/go/vt/vttablet/tabletserver/tabletserver_test.go
@@ -675,7 +675,6 @@ func TestTabletServerReserveConnection(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
@@ -684,7 +683,7 @@ func TestTabletServerReserveConnection(t *testing.T) {
options := &querypb.ExecuteOptions{}
// reserve a connection
- state, _, err := tsv.ReserveExecute(ctx, &target, nil, "select 42", nil, 0, options)
+ state, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, 0, options)
require.NoError(t, err)
// run a query in it
@@ -747,7 +746,6 @@ func TestTabletServerReserveAndBeginCommit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
@@ -756,7 +754,7 @@ func TestTabletServerReserveAndBeginCommit(t *testing.T) {
options := &querypb.ExecuteOptions{}
// reserve a connection and a transaction
- state, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "select 42", nil, options)
+ state, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "set sql_mode = ''", nil, options)
require.NoError(t, err)
defer func() {
// fallback so the test finishes quickly
@@ -2192,20 +2190,19 @@ func TestReserveBeginExecute(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
target := querypb.Target{TabletType: topodatapb.TabletType_PRIMARY}
+ db.AddQueryPattern("set @@sql_mode = ''", &sqltypes.Result{})
- state, _, err := tsv.ReserveBeginExecute(ctx, &target, []string{"select 43"}, nil, "select 42", nil, &querypb.ExecuteOptions{})
+ state, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "set @@sql_mode = ''", nil, &querypb.ExecuteOptions{})
require.NoError(t, err)
assert.Greater(t, state.TransactionID, int64(0), "transactionID")
- assert.Equal(t, state.ReservedID, state.TransactionID, "reservedID should equal transactionID")
+ assert.Equal(t, state.TransactionID, state.ReservedID, "reservedID should equal transactionID")
expected := []string{
- "select 43",
"begin",
- "select 42 from dual limit 10001",
+ "set @@sql_mode = ''",
}
splitOutput := strings.Split(db.QueryLog(), ";")
for _, exp := range expected {
@@ -2219,18 +2216,17 @@ func TestReserveExecute_WithoutTx(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
+ db.AddQueryPattern("set @@sql_mode = ''", &sqltypes.Result{})
target := querypb.Target{TabletType: topodatapb.TabletType_PRIMARY}
- state, _, err := tsv.ReserveExecute(ctx, &target, []string{"select 43"}, "select 42", nil, 0, &querypb.ExecuteOptions{})
+ state, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, 0, &querypb.ExecuteOptions{})
require.NoError(t, err)
assert.NotEqual(t, int64(0), state.ReservedID, "reservedID should not be zero")
expected := []string{
- "select 43",
- "select 42 from dual limit 10001",
+ "set @@sql_mode = ''",
}
splitOutput := strings.Split(db.QueryLog(), ";")
for _, exp := range expected {
@@ -2244,9 +2240,10 @@ func TestReserveExecute_WithTx(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
+
+ db.AddQueryPattern("set @@sql_mode = ''", &sqltypes.Result{})
target := querypb.Target{TabletType: topodatapb.TabletType_PRIMARY}
beginState, err := tsv.Begin(ctx, &target, &querypb.ExecuteOptions{})
@@ -2254,13 +2251,12 @@ func TestReserveExecute_WithTx(t *testing.T) {
require.NotEqual(t, int64(0), beginState.TransactionID)
db.ResetQueryLog()
- reserveState, _, err := tsv.ReserveExecute(ctx, &target, []string{"select 43"}, "select 42", nil, beginState.TransactionID, &querypb.ExecuteOptions{})
+ reserveState, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, beginState.TransactionID, &querypb.ExecuteOptions{})
require.NoError(t, err)
defer tsv.Release(ctx, &target, beginState.TransactionID, reserveState.ReservedID)
assert.Equal(t, beginState.TransactionID, reserveState.ReservedID, "reservedID should be equal to transactionID")
expected := []string{
- "select 43",
- "select 42 from dual limit 10001",
+ "set @@sql_mode = ''",
}
splitOutput := strings.Split(db.QueryLog(), ";")
for _, exp := range expected {
@@ -2306,7 +2302,6 @@ func TestRelease(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
db.AddQueryPattern(".*", &sqltypes.Result{})
@@ -2316,7 +2311,7 @@ func TestRelease(t *testing.T) {
switch {
case test.begin && test.reserve:
- state, _, err := tsv.ReserveBeginExecute(ctx, &target, []string{"select 1212"}, nil, "select 42", nil, &querypb.ExecuteOptions{})
+ state, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "set sql_mode = ''", nil, &querypb.ExecuteOptions{})
require.NoError(t, err)
transactionID = state.TransactionID
reservedID = state.ReservedID
@@ -2328,7 +2323,7 @@ func TestRelease(t *testing.T) {
transactionID = state.TransactionID
require.NotEqual(t, int64(0), transactionID)
case test.reserve:
- state, _, err := tsv.ReserveExecute(ctx, &target, nil, "select 42", nil, 0, &querypb.ExecuteOptions{})
+ state, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, 0, &querypb.ExecuteOptions{})
require.NoError(t, err)
reservedID = state.ReservedID
require.NotEqual(t, int64(0), reservedID)
@@ -2351,10 +2346,10 @@ func TestReserveStats(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "")
- tsv.config.EnableSettingsPool = false
defer tsv.StopService()
defer db.Close()
+ db.AddQueryPattern("set @@sql_mode = ''", &sqltypes.Result{})
target := querypb.Target{TabletType: topodatapb.TabletType_PRIMARY}
callerID := &querypb.VTGateCallerID{
@@ -2363,12 +2358,12 @@ func TestReserveStats(t *testing.T) {
ctx = callerid.NewContext(ctx, nil, callerID)
// Starts reserved connection and transaction
- rbeState, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "select 42", nil, &querypb.ExecuteOptions{})
+ rbeState, _, err := tsv.ReserveBeginExecute(ctx, &target, nil, nil, "set sql_mode = ''", nil, &querypb.ExecuteOptions{})
require.NoError(t, err)
assert.EqualValues(t, 1, tsv.te.txPool.env.Stats().UserActiveReservedCount.Counts()["test"])
// Starts reserved connection
- reState, _, err := tsv.ReserveExecute(ctx, &target, nil, "select 42", nil, 0, &querypb.ExecuteOptions{})
+ reState, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, 0, &querypb.ExecuteOptions{})
require.NoError(t, err)
assert.EqualValues(t, 2, tsv.te.txPool.env.Stats().UserActiveReservedCount.Counts()["test"])
@@ -2383,7 +2378,7 @@ func TestReserveStats(t *testing.T) {
assert.EqualValues(t, 2, tsv.te.txPool.env.Stats().UserActiveReservedCount.Counts()["test"])
// Reserved the connection on previous transaction
- beReState, _, err := tsv.ReserveExecute(ctx, &target, nil, "select 42", nil, beState.TransactionID, &querypb.ExecuteOptions{})
+ beReState, _, err := tsv.ReserveExecute(ctx, &target, nil, "set sql_mode = ''", nil, beState.TransactionID, &querypb.ExecuteOptions{})
require.NoError(t, err)
assert.EqualValues(t, 3, tsv.te.txPool.env.Stats().UserActiveReservedCount.Counts()["test"])
@@ -2526,12 +2521,11 @@ func TestDatabaseNameReplaceByKeyspaceNameReserveExecuteMethod(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, tsv := setupTabletServerTest(t, ctx, "keyspaceName")
- tsv.config.EnableSettingsPool = false
setDBName(db, tsv, "databaseInMysql")
defer tsv.StopService()
defer db.Close()
- executeSQL := "select * from test_table limit 1000"
+ executeSQL := "select 43"
executeSQLResult := &sqltypes.Result{
Fields: []*querypb.Field{
{
@@ -2539,24 +2533,21 @@ func TestDatabaseNameReplaceByKeyspaceNameReserveExecuteMethod(t *testing.T) {
Database: "databaseInMysql",
},
},
- RowsAffected: 1,
Rows: [][]sqltypes.Value{
- {sqltypes.NewVarBinary("row01")},
+ {sqltypes.NewInt64(43)},
},
}
- db.AddQuery(executeSQL, executeSQLResult)
+ db.AddQuery("select 43 from dual limit 10001", executeSQLResult)
target := tsv.sm.target
// Test ReserveExecute
- state, res, err := tsv.ReserveExecute(ctx, target, nil, executeSQL, nil, 0, &querypb.ExecuteOptions{
+ _, res, err := tsv.ReserveExecute(ctx, target, nil, executeSQL, nil, 0, &querypb.ExecuteOptions{
IncludedFields: querypb.ExecuteOptions_ALL,
})
require.NoError(t, err)
for _, field := range res.Fields {
require.Equal(t, "keyspaceName", field.Database)
}
- err = tsv.Release(ctx, target, 0, state.ReservedID)
- require.NoError(t, err)
}
func TestDatabaseNameReplaceByKeyspaceNameReserveBeginExecuteMethod(t *testing.T) {