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

fix: transaction_isolation to be applied at session level #12281

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions go/test/endtoend/vtgate/transaction/tx_test.go
Expand Up @@ -209,6 +209,31 @@ func TestTransactionAccessModes(t *testing.T) {
utils.Exec(t, conn, "rollback")
}

// TestTransactionIsolationInTx tests transaction isolation level inside transaction
// and setting isolation level to different values.
func TestTransactionIsolationInTx(t *testing.T) {
ctx := context.Background()

conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

utils.Exec(t, conn, "set transaction isolation level read committed")
utils.Exec(t, conn, "begin")
utils.AssertMatches(t, conn, "select @@transaction_isolation", `[[VARCHAR("READ-COMMITTED")]]`)
utils.Exec(t, conn, "commit")

utils.Exec(t, conn, "set transaction isolation level serializable")
utils.Exec(t, conn, "begin")
utils.AssertMatches(t, conn, "select @@transaction_isolation", `[[VARCHAR("SERIALIZABLE")]]`)
utils.Exec(t, conn, "commit")

utils.Exec(t, conn, "set transaction isolation level read committed")
utils.Exec(t, conn, "begin")
utils.AssertMatches(t, conn, "select @@transaction_isolation", `[[VARCHAR("READ-COMMITTED")]]`)
utils.Exec(t, conn, "commit")
}

func start(t *testing.T) func() {
deleteAll := func() {
conn, err := mysql.Connect(context.Background(), &vtParams)
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtgate/engine/fake_vcursor_test.go
Expand Up @@ -355,6 +355,8 @@ type loggingVCursor struct {

// map different shards to keyspaces in the test.
ksShardMap map[string][]string

shardSession []*srvtopo.ResolvedShard
}

type tableRoutes struct {
Expand Down Expand Up @@ -420,7 +422,7 @@ func (f *loggingVCursor) InReservedConn() bool {
}

func (f *loggingVCursor) ShardSession() []*srvtopo.ResolvedShard {
return nil
return f.shardSession
}

func (f *loggingVCursor) ExecuteVSchema(context.Context, string, *sqlparser.AlterVschema) error {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/set.go
Expand Up @@ -313,7 +313,7 @@ func (svs *SysVarReservedConn) Execute(ctx context.Context, vcursor VCursor, env
queries := make([]*querypb.BoundQuery, len(rss))
for i := 0; i < len(rss); i++ {
queries[i] = &querypb.BoundQuery{
Sql: fmt.Sprintf("set @@%s = %s", svs.Name, svs.Expr),
Sql: fmt.Sprintf("set %s = %s", svs.Name, svs.Expr),
BindVariables: env.BindVars,
}
}
Expand Down
3 changes: 3 additions & 0 deletions go/vt/vtgate/engine/set_test.go
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/srvtopo"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -59,6 +60,7 @@ func TestSetSystemVariableAsString(t *testing.T) {
),
"foobar",
)},
shardSession: []*srvtopo.ResolvedShard{{Target: &querypb.Target{Keyspace: "ks", Shard: "-20"}}},
}
_, err := set.TryExecute(context.Background(), vc, map[string]*querypb.BindVariable{}, false)
require.NoError(t, err)
Expand All @@ -68,6 +70,7 @@ func TestSetSystemVariableAsString(t *testing.T) {
"ExecuteMultiShard ks.-20: select dummy_expr from dual where @@x != dummy_expr {} false false",
"SysVar set with (x,'foobar')",
"Needs Reserved Conn",
"ExecuteMultiShard ks.-20: set x = dummy_expr {} false false",
})
}

Expand Down