Skip to content

Commit 1bbbcda

Browse files
Online DDL: support alter vitess_migration ... postpone complete syntax (vitessio#18118)
Signed-off-by: Shlomi Noach <[email protected]> Co-authored-by: Deepthi Sigireddi <[email protected]>
1 parent 03a9bfe commit 1bbbcda

File tree

12 files changed

+9044
-8991
lines changed

12 files changed

+9044
-8991
lines changed

go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,60 @@ func testScheduler(t *testing.T) {
603603
}
604604
})
605605
})
606+
607+
t.Run("Delayed postpone completion ALTER", func(t *testing.T) {
608+
onlineddl.ThrottleAllMigrations(t, &vtParams)
609+
defer onlineddl.UnthrottleAllMigrations(t, &vtParams)
610+
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, true)
611+
612+
t1uuid = testOnlineDDLStatement(t, createParams(trivialAlterT1Statement, ddlStrategy, "vtgate", "", "", true)) // skip wait
613+
614+
t.Run("wait for t1 running", func(t *testing.T) {
615+
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusRunning)
616+
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
617+
})
618+
619+
t.Run("check postpone_completion", func(t *testing.T) {
620+
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
621+
require.NotNil(t, rs)
622+
for _, row := range rs.Named().Rows {
623+
postponeCompletion := row.AsInt64("postpone_completion", 0)
624+
assert.EqualValues(t, 0, postponeCompletion)
625+
}
626+
})
627+
t.Run("postpone", func(t *testing.T) {
628+
onlineddl.CheckPostponeCompleteMigration(t, &vtParams, shards, t1uuid, true)
629+
})
630+
t.Run("check postpone_completion set", func(t *testing.T) {
631+
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
632+
require.NotNil(t, rs)
633+
for _, row := range rs.Named().Rows {
634+
postponeCompletion := row.AsInt64("postpone_completion", 0)
635+
assert.EqualValues(t, 1, postponeCompletion)
636+
}
637+
})
638+
onlineddl.UnthrottleAllMigrations(t, &vtParams)
639+
onlineddl.CheckThrottledApps(t, &vtParams, throttlerapp.OnlineDDLName, false)
640+
641+
t.Run("wait for ready_to_complete", func(t *testing.T) {
642+
waitForReadyToComplete(t, t1uuid, true)
643+
})
644+
t.Run("complete", func(t *testing.T) {
645+
onlineddl.CheckCompleteMigration(t, &vtParams, shards, t1uuid, true)
646+
status := onlineddl.WaitForMigrationStatus(t, &vtParams, shards, t1uuid, normalWaitTime, schema.OnlineDDLStatusComplete, schema.OnlineDDLStatusFailed)
647+
fmt.Printf("# Migration status (for debug purposes): <%s>\n", status)
648+
onlineddl.CheckMigrationStatus(t, &vtParams, shards, t1uuid, schema.OnlineDDLStatusComplete)
649+
})
650+
t.Run("check no postpone_completion", func(t *testing.T) {
651+
rs := onlineddl.ReadMigrations(t, &vtParams, t1uuid)
652+
require.NotNil(t, rs)
653+
for _, row := range rs.Named().Rows {
654+
postponeCompletion := row.AsInt64("postpone_completion", 0)
655+
assert.EqualValues(t, 0, postponeCompletion)
656+
}
657+
})
658+
})
659+
606660
t.Run("show vitess_migrations in transaction", func(t *testing.T) {
607661
// The function validates there is no error
608662
rs := onlineddl.VtgateExecQueryInTransaction(t, &vtParams, "show vitess_migrations", "")

go/test/endtoend/onlineddl/vtgate_util.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ func CheckCompleteMigration(t *testing.T, vtParams *mysql.ConnParams, shards []c
179179
}
180180
}
181181

182+
// CheckPostponeCompleteMigration attempts to postpone an existing migration, and expects success by counting affected rows
183+
func CheckPostponeCompleteMigration(t *testing.T, vtParams *mysql.ConnParams, shards []cluster.Shard, uuid string, expectPotponePossible bool) {
184+
query, err := sqlparser.ParseAndBind("alter vitess_migration %a postpone complete",
185+
sqltypes.StringBindVariable(uuid),
186+
)
187+
require.NoError(t, err)
188+
r := VtgateExecQuery(t, vtParams, query, "")
189+
190+
if expectPotponePossible {
191+
assert.Equal(t, len(shards), int(r.RowsAffected))
192+
} else {
193+
assert.Equal(t, int(0), int(r.RowsAffected))
194+
}
195+
}
196+
182197
// CheckLaunchMigration attempts to launch a migration, and expects success by counting affected rows
183198
func CheckLaunchMigration(t *testing.T, vtParams *mysql.ConnParams, shards []cluster.Shard, uuid string, launchShards string, expectLaunchPossible bool) {
184199
query, err := sqlparser.ParseAndBind("alter vitess_migration %a launch vitess_shards %a",
@@ -206,6 +221,17 @@ func CheckCompleteAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expect
206221
}
207222
}
208223

224+
// CheckPostponeCompleteAllMigrations postpones all pending migrations and expect number of affected rows
225+
// A negative value for expectCount indicates "don't care, no need to check"
226+
func CheckPostponeCompleteAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expectCount int) {
227+
completeQuery := "alter vitess_migration postpone complete all"
228+
r := VtgateExecQuery(t, vtParams, completeQuery, "")
229+
230+
if expectCount >= 0 {
231+
assert.Equal(t, expectCount, int(r.RowsAffected))
232+
}
233+
}
234+
209235
// CheckCancelAllMigrations cancels all pending migrations and expect number of affected rows
210236
// A negative value for expectCount indicates "don't care, no need to check"
211237
func CheckCancelAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expectCount int) {

go/vt/sqlparser/ast_format.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ func (node *AlterMigration) Format(buf *TrackedBuffer) {
326326
alterType = "complete"
327327
case CompleteAllMigrationType:
328328
alterType = "complete all"
329+
case PostponeCompleteMigrationType:
330+
alterType = "postpone complete"
331+
case PostponeCompleteAllMigrationType:
332+
alterType = "postpone complete all"
329333
case CancelMigrationType:
330334
alterType = "cancel"
331335
case CancelAllMigrationType:

go/vt/sqlparser/ast_format_fast.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/sqlparser/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,8 @@ const (
960960
LaunchAllMigrationType
961961
CompleteMigrationType
962962
CompleteAllMigrationType
963+
PostponeCompleteMigrationType
964+
PostponeCompleteAllMigrationType
963965
CancelMigrationType
964966
CancelAllMigrationType
965967
CleanupMigrationType

go/vt/sqlparser/keywords.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ var keywords = []keyword{
518518
{"pointn", ST_PointN},
519519
{"polygon", POLYGON},
520520
{"position", POSITION},
521+
{"postpone", POSTPONE},
521522
{"preceding", PRECEDING},
522523
{"precision", UNUSED},
523524
{"prepare", PREPARE},

go/vt/sqlparser/parse_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,10 @@ var (
25812581
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' complete",
25822582
}, {
25832583
input: "alter vitess_migration complete all",
2584+
}, {
2585+
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' postpone complete",
2586+
}, {
2587+
input: "alter vitess_migration postpone complete all",
25842588
}, {
25852589
input: "alter vitess_migration '9748c3b7_7fdb_11eb_ac2c_f875a4d24e90' cancel",
25862590
}, {

0 commit comments

Comments
 (0)