Skip to content

Commit

Permalink
Query to read transaction state (#16431)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
GuptaManan100 and harshit-gangal authored Jul 24, 2024
1 parent 88fc8f0 commit 8ff313f
Show file tree
Hide file tree
Showing 25 changed files with 5,766 additions and 5,383 deletions.
15 changes: 15 additions & 0 deletions go/test/endtoend/transaction/twopc/twopc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package transaction
import (
"context"
_ "embed"
"fmt"
"reflect"
"sort"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -849,6 +851,19 @@ func TestDTResolveAfterTransactionRecord(t *testing.T) {
_, err = conn.Execute(newCtx, "commit", nil)
require.ErrorContains(t, err, "Fail After TR created")

t.Run("ReadTransactionState", func(t *testing.T) {
errStr := err.Error()
indx := strings.Index(errStr, "Fail")
require.Greater(t, indx, 0)
dtid := errStr[0 : indx-2]
res, err := conn.Execute(context.Background(), fmt.Sprintf(`show transaction status for '%v'`, dtid), nil)
require.NoError(t, err)
resStr := fmt.Sprintf("%v", res.Rows)
require.Contains(t, resStr, `[[VARCHAR("ks:80-`)
require.Contains(t, resStr, `VARCHAR("PREPARE") DATETIME("`)
require.Contains(t, resStr, `+0000 UTC") VARCHAR("ks:40-80")]]`)
})

// Below check ensures that the transaction is resolved by the resolver on receiving unresolved transaction signal from MM.
tableMap := make(map[string][]*querypb.Field)
dtMap := make(map[string]string)
Expand Down
12 changes: 9 additions & 3 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,11 @@ type (
Filter *ShowFilter
}

// ShowTransactionStatus is used to see the status of a distributed transaction in progress.
ShowTransactionStatus struct {
TransactionID string
}

// ShowCreate is of ShowInternal type, holds SHOW CREATE queries.
ShowCreate struct {
Command ShowCommandType
Expand All @@ -1683,9 +1688,10 @@ type (
}
)

func (*ShowBasic) isShowInternal() {}
func (*ShowCreate) isShowInternal() {}
func (*ShowOther) isShowInternal() {}
func (*ShowBasic) isShowInternal() {}
func (*ShowCreate) isShowInternal() {}
func (*ShowOther) isShowInternal() {}
func (*ShowTransactionStatus) isShowInternal() {}

// InsertRows represents the rows for an INSERT statement.
type InsertRows interface {
Expand Down
13 changes: 13 additions & 0 deletions go/vt/sqlparser/ast_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions go/vt/sqlparser/ast_copy_on_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions go/vt/sqlparser/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,10 @@ func (node *ShowBasic) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%v", node.Filter)
}

func (node *ShowTransactionStatus) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show transaction status for '%#s'", node.TransactionID)
}

// Format formats the node.
func (node *ShowCreate) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show%s %v", node.Command.ToString(), node.Op)
Expand Down
6 changes: 6 additions & 0 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions go/vt/sqlparser/ast_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions go/vt/sqlparser/ast_visit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions go/vt/sqlparser/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,17 @@ var (
input: "show vitess_migrations like '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90'",
}, {
input: "show vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' logs",
}, {
input: "show transaction status for 'ks:-80:232323238342'",
}, {
input: "show transaction status for \"ks:-80:232323238342\"",
output: "show transaction status for 'ks:-80:232323238342'",
}, {
input: "show transaction status 'ks:-80:232323238342'",
output: "show transaction status for 'ks:-80:232323238342'",
}, {
input: "show transaction status \"ks:-80:232323238342\"",
output: "show transaction status for 'ks:-80:232323238342'",
}, {
input: "revert vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90'",
}, {
Expand Down
Loading

0 comments on commit 8ff313f

Please sign in to comment.