Skip to content

Commit

Permalink
Support SHOW VITESS_MIGRATIONS from inside a transaction (vitessio#…
Browse files Browse the repository at this point in the history
…16399)

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach authored Jul 18, 2024
1 parent 96974ef commit 8e9d294
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ func testScheduler(t *testing.T) {
}
})
})
t.Run("show vitess_migrations in transaction", func(t *testing.T) {
// The function validates there is no error
rs := onlineddl.VtgateExecQueryInTransaction(t, &vtParams, "show vitess_migrations", "")
assert.NotEmpty(t, rs.Rows)
})

forceCutoverCapable, err := capableOf(capabilities.PerformanceSchemaDataLocksTableCapability) // 8.0
require.NoError(t, err)
Expand Down
23 changes: 23 additions & 0 deletions go/test/endtoend/onlineddl/vtgate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ func VtgateExecQuery(t *testing.T, vtParams *mysql.ConnParams, query string, exp
return qr
}

// VtgateExecQueryInTransaction runs a query on VTGate using given query params, inside a transaction
func VtgateExecQueryInTransaction(t *testing.T, vtParams *mysql.ConnParams, query string, expectError string) *sqltypes.Result {
t.Helper()

ctx := context.Background()
conn, err := mysql.Connect(ctx, vtParams)
require.Nil(t, err)
defer conn.Close()

_, err = conn.ExecuteFetch("begin", -1, true)
require.NoError(t, err)
qr, err := conn.ExecuteFetch(query, -1, true)
if expectError == "" {
require.NoError(t, err)
} else {
require.Error(t, err, "error should not be nil")
assert.Contains(t, err.Error(), expectError, "Unexpected error")
}
_, err = conn.ExecuteFetch("commit", -1, true)
require.NoError(t, err)
return qr
}

// VtgateExecDDL executes a DDL query with given strategy
func VtgateExecDDL(t *testing.T, vtParams *mysql.ConnParams, ddlStrategy string, query string, expectError string) *sqltypes.Result {
t.Helper()
Expand Down
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletserver/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (qre *QueryExecutor) Execute() (reply *sqltypes.Result, err error) {
case p.PlanRevertMigration:
return qre.execRevertMigration()
case p.PlanShowMigrations:
return qre.execShowMigrations()
return qre.execShowMigrations(nil)
case p.PlanShowMigrationLogs:
return qre.execShowMigrationLogs()
case p.PlanShowThrottledApps:
Expand Down Expand Up @@ -308,6 +308,8 @@ func (qre *QueryExecutor) txConnExec(conn *StatefulConnection) (*sqltypes.Result
return qre.execLoad(conn)
case p.PlanCallProc:
return qre.execProc(conn)
case p.PlanShowMigrations:
return qre.execShowMigrations(conn)
}
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] %s unexpected plan type", qre.plan.PlanID.String())
}
Expand Down Expand Up @@ -958,7 +960,7 @@ func (qre *QueryExecutor) execRevertMigration() (*sqltypes.Result, error) {
return qre.tsv.onlineDDLExecutor.SubmitMigration(qre.ctx, qre.plan.FullStmt)
}

func (qre *QueryExecutor) execShowMigrations() (*sqltypes.Result, error) {
func (qre *QueryExecutor) execShowMigrations(conn *StatefulConnection) (*sqltypes.Result, error) {
if showStmt, ok := qre.plan.FullStmt.(*sqlparser.Show); ok {
return qre.tsv.onlineDDLExecutor.ShowMigrations(qre.ctx, showStmt)
}
Expand Down

0 comments on commit 8e9d294

Please sign in to comment.