Skip to content

Commit

Permalink
Online DDL: better support for subsecond --force-cut-over-after DDL…
Browse files Browse the repository at this point in the history
… strategy flag value. (#16635)

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Aug 23, 2024
1 parent 3f87ca2 commit 1db282a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
7 changes: 7 additions & 0 deletions go/vt/schema/ddl_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ func TestParseDDLStrategy(t *testing.T) {
runtimeOptions: "",
forceCutOverAfter: 3 * time.Minute,
},
{
strategyVariable: "vitess --force-cut-over-after=-1ms",
strategy: DDLStrategyVitess,
options: "--force-cut-over-after=-1ms",
runtimeOptions: "",
forceCutOverAfter: -1 * time.Millisecond,
},
{
strategyVariable: "vitess --force-cut-over-after=r3m",
strategy: DDLStrategyVitess,
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3845,7 +3845,7 @@ func (e *Executor) reviewRunningMigrations(ctx context.Context) (countRunnning i
uuid := row["migration_uuid"].ToString()
cutoverAttempts := row.AsInt64("cutover_attempts", 0)
sinceLastCutoverAttempt := time.Second * time.Duration(row.AsInt64("seconds_since_last_cutover_attempt", 0))
sinceReadyToComplete := time.Second * time.Duration(row.AsInt64("seconds_since_ready_to_complete", 0))
sinceReadyToComplete := time.Microsecond * time.Duration(row.AsInt64("microseconds_since_ready_to_complete", 0))
onlineDDL, migrationRow, err := e.readMigration(ctx, uuid)
if err != nil {
return countRunnning, cancellable, err
Expand Down
32 changes: 32 additions & 0 deletions go/vt/vttablet/onlineddl/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,38 @@ func TestShouldCutOverAccordingToBackoff(t *testing.T) {
expectShouldCutOver: false,
expectShouldForceCutOver: false,
},
{
name: "zero since ready",
cutoverAttempts: 3,
forceCutOverAfter: time.Second,
sinceReadyToComplete: 0,
expectShouldCutOver: false,
expectShouldForceCutOver: false,
},
{
name: "zero since read, zero cut-over-after",
cutoverAttempts: 3,
forceCutOverAfter: 0,
sinceReadyToComplete: 0,
expectShouldCutOver: false,
expectShouldForceCutOver: false,
},
{
name: "microsecond",
cutoverAttempts: 3,
forceCutOverAfter: time.Microsecond,
sinceReadyToComplete: time.Millisecond,
expectShouldCutOver: true,
expectShouldForceCutOver: true,
},
{
name: "microsecond, not ready",
cutoverAttempts: 3,
forceCutOverAfter: time.Millisecond,
sinceReadyToComplete: time.Microsecond,
expectShouldCutOver: false,
expectShouldForceCutOver: false,
},
{
name: "cutover-after overrides backoff",
cutoverAttempts: 3,
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/onlineddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ const (
postpone_completion,
force_cutover,
cutover_attempts,
ifnull(timestampdiff(second, ready_to_complete_timestamp, now()), 0) as seconds_since_ready_to_complete,
ifnull(timestampdiff(microsecond, ready_to_complete_timestamp, now(6)), 0) as microseconds_since_ready_to_complete,
ifnull(timestampdiff(second, last_cutover_attempt_timestamp, now()), 0) as seconds_since_last_cutover_attempt,
timestampdiff(second, started_timestamp, now()) as elapsed_seconds
FROM _vt.schema_migrations
Expand Down

0 comments on commit 1db282a

Please sign in to comment.