Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,60 @@ func testScheduler(t *testing.T) {
}
})
})

t.Run("Delayed postpone completion ALTER", func(t *testing.T) {
onlineddl.ThrottleAllMigrations(t, &vtParams)
defer onlineddl.UnthrottleAllMigrations(t, &vtParams)
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, true)

t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy, "vtgate", "", "", true)) // skip wait

t.Run("wait for t1 running", func(t *testing.T) {
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusRunning)
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
})

t.Run("check postpone_completion", func(t *testing.T) {
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
postponeCompletion := row.AsInt64("postpone_completion", 0)
assert.EqualValues(t, 0, postponeCompletion)
}
})
t.Run("postpone", func(t *testing.T) {
onlineddl.CheckPostponeCompleteMigration(t, &vtParams, shards, t1uuid, true)
})
t.Run("check postpone_completion set", func(t *testing.T) {
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
postponeCompletion := row.AsInt64("postpone_completion", 0)
assert.EqualValues(t, 1, postponeCompletion)
}
})
onlineddl.UnthrottleAllMigrations(t, &vtParams)
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, false)

t.Run("wait for ready_to_complete", func(t *testing.T) {
waitForReadyToComplete(t, t1uuid, true)
})
t.Run("complete", func(t *testing.T) {
onlineddl.CheckCompleteMigration(t, &vtParams, shards, t1uuid, true)
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed)
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusComplete)
})
t.Run("check no postpone_completion", func(t *testing.T) {
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
require.NotNil(t, rs)
for _, row := range rs.Named().Rows {
postponeCompletion := row.AsInt64("postpone_completion", 0)
assert.EqualValues(t, 0, postponeCompletion)
}
})
})

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", "")
Expand Down
26 changes: 26 additions & 0 deletions go/test/endtoend/onlineddl/vtgate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ func CheckCompleteMigration(t *testing.T, vtParams *mysql.ConnParams, shards []c
}
}

// CheckPostponeCompleteMigration attempts to postpone an existing migration, and expects success by counting affected rows
func CheckPostponeCompleteMigration(t *testing.T, vtParams *mysql.ConnParams, shards []cluster.Shard, uuid string, expectPotponePossible bool) {
query, err := sqlparser.ParseAndBind("alter vitess_migration %a postpone complete",
sqltypes.StringBindVariable(uuid),
)
require.NoError(t, err)
r := VtgateExecQuery(t, vtParams, query, "")

if expectPotponePossible {
assert.Equal(t, len(shards), int(r.RowsAffected))
} else {
assert.Equal(t, int(0), int(r.RowsAffected))
}
}

// CheckLaunchMigration attempts to launch a migration, and expects success by counting affected rows
func CheckLaunchMigration(t *testing.T, vtParams *mysql.ConnParams, shards []cluster.Shard, uuid string, launchShards string, expectLaunchPossible bool) {
query, err := sqlparser.ParseAndBind("alter vitess_migration %a launch vitess_shards %a",
Expand Down Expand Up @@ -206,6 +221,17 @@ func CheckCompleteAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expect
}
}

// CheckPostponeCompleteAllMigrations postpones all pending migrations and expect number of affected rows
// A negative value for expectCount indicates "don't care, no need to check"
func CheckPostponeCompleteAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expectCount int) {
completeQuery := "alter vitess_migration postpone complete all"
r := VtgateExecQuery(t, vtParams, completeQuery, "")

if expectCount >= 0 {
assert.Equal(t, expectCount, int(r.RowsAffected))
}
}

// CheckCancelAllMigrations cancels all pending migrations and expect number of affected rows
// A negative value for expectCount indicates "don't care, no need to check"
func CheckCancelAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expectCount int) {
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (node *AlterMigration) Format(buf *TrackedBuffer) {
alterType = "complete"
case CompleteAllMigrationType:
alterType = "complete all"
case PostponeCompleteMigrationType:
alterType = "postpone complete"
case PostponeCompleteAllMigrationType:
alterType = "postpone complete all"
case CancelMigrationType:
alterType = "cancel"
case CancelAllMigrationType:
Expand Down
4 changes: 4 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.

2 changes: 2 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ const (
LaunchAllMigrationType
CompleteMigrationType
CompleteAllMigrationType
PostponeCompleteMigrationType
PostponeCompleteAllMigrationType
CancelMigrationType
CancelAllMigrationType
CleanupMigrationType
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ var keywords = []keyword{
{"pointn", ST_PointN},
{"polygon", POLYGON},
{"position", POSITION},
{"postpone", POSTPONE},
{"preceding", PRECEDING},
{"precision", UNUSED},
{"prepare", PREPARE},
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,10 @@ var (
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' complete",
}, {
input: "alter vitess_migration complete all",
}, {
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' postpone complete",
}, {
input: "alter vitess_migration postpone complete all",
}, {
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' cancel",
}, {
Expand Down
Loading
Loading