diff --git a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go index c059f68b8b7..c0541a04aea 100644 --- a/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go +++ b/go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go @@ -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) diff --git a/go/test/endtoend/onlineddl/vtgate_util.go b/go/test/endtoend/onlineddl/vtgate_util.go index 2cbdbebc2f3..7252edb8096 100644 --- a/go/test/endtoend/onlineddl/vtgate_util.go +++ b/go/test/endtoend/onlineddl/vtgate_util.go @@ -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() diff --git a/go/vt/vttablet/tabletserver/query_executor.go b/go/vt/vttablet/tabletserver/query_executor.go index 86269050418..9422697f60c 100644 --- a/go/vt/vttablet/tabletserver/query_executor.go +++ b/go/vt/vttablet/tabletserver/query_executor.go @@ -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: @@ -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()) } @@ -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) }