Skip to content

Commit

Permalink
feat: support 'schema_migration' command (#379)
Browse files Browse the repository at this point in the history
* feat: support 'schema_migration' command

Signed-off-by: earayu <[email protected]>

* feat: support 'schema_migration' command

Signed-off-by: earayu <[email protected]>

* feat: support 'schema_migration' command

Signed-off-by: earayu <[email protected]>

---------

Signed-off-by: earayu <[email protected]>
  • Loading branch information
earayu authored Dec 5, 2023
1 parent 4db7f4e commit 74fe562
Show file tree
Hide file tree
Showing 8 changed files with 7,591 additions and 7,191 deletions.
2 changes: 1 addition & 1 deletion doc/design/20231113_OnlineDDLScheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The states of online DDL include **`queued`**, **`ready`**, **`running`**, **`co
- **`running`**: Online DDL in progress, including the creation of shadow tables, generation of select and insert statements, and initiation of Vreplication tasks.
- **`complete`**: Online DDL execution finished, entering this state after the cutover is complete.
- **`fail`**: Execution fails due to internal errors. Error details can be diagnosed using the **`message`** field with the corresponding uuid.
- **`cancel`**: WeSQL provides **`alter vitess_migration`** to cancel an online DDL task. Tasks in this state can be re-executed using the **`retry`** command.
- **`cancel`**: WeSQL provides **`alter schema_migration`** to cancel an online DDL task. Tasks in this state can be re-executed using the **`retry`** command.
- **`pause`**: Currently under development, this feature can pause online DDL tasks in **`queue`**, **`ready`**, or **`running`** states.

State transition diagram (needs to be updated with the addition of **`pause`**):
Expand Down
2 changes: 1 addition & 1 deletion doc/design/20231113_TheLifecycleofAlterTableStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- **`running`**: Online DDL in progress, including the creation of shadow tables, generation of select and insert statements, and initiation of Vreplication tasks.
- **`complete`**: Online DDL execution finished, entering this state after cutover completion.
- **`fail`**: Execution fails due to internal errors. Error details can be diagnosed using the **`message`** field with the corresponding uuid.
- **`cancel`**: WeSQL provides **`alter vitess_migration`** to cancel an online DDL task. Tasks in this state can be re-executed using the **`retry`** command.
- **`cancel`**: WeSQL provides **`alter schema_migration`** to cancel an online DDL task. Tasks in this state can be re-executed using the **`retry`** command.
- **`pause`**: Currently under development, this feature can pause online DDL tasks in **`queue`**, **`ready`**, or **`running`** states.

For state transitions, refer to the article [OnlineDDLScheduler](20231113_OnlineDDLScheduler.md)
Expand Down
22 changes: 11 additions & 11 deletions doc/toturial/07-OnlineDDL-User-Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set @@ddl_strategy='online';
- postpone-completion: Only transitions state under user command, not automatically completed, allowing better control over the timing of schema changes.
- prefer-instant-ddl: Prioritize using the instant-ddl function of mysql. [instant-ddl](https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl-operations.html)

If a migration is both **`--declarative`** and **`--postpone-completion`**, it will remain in **`queued`** status until the user executes the **`alter vitess_migration ... complete`** command.
If a migration is both **`--declarative`** and **`--postpone-completion`**, it will remain in **`queued`** status until the user executes the **`alter schema_migration ... complete`** command.

- postpone-launch: Initializes a queue in **`queued`** status, set to transition state only on user command.
- singleton: Allows only one migration in pending status to be submitted at a time. From the point a migration enters **`queued`** status, until it reaches **`completion`**, **`failure`**, or **`cancellation`**, no other migrations can be submitted. New migrations will be rejected. This can be seen as a mutex lock for migrations, affecting only those with the **`singleton`** flag, others are not impacted.
Expand All @@ -52,61 +52,61 @@ set @@ddl_strategy='online --allow-concurrent';

## **Monitoring DDL Progress**

After executing onlineDDL, a uuid is returned. You can use this uuid and the **`show vitess_migrations`** command to:
After executing onlineDDL, a uuid is returned. You can use this uuid and the **`show schema_migration`** command to:

- View the ddl status

```sql
show vitess_migrations like 'uuid' \G;
show schema_migration like 'uuid' \G;
```

## ****Controlling**** ddl

- Cancel a ddl

```sql
alter vitess_migration 'uuid' cancel;
alter schema_migration 'uuid' cancel;
```

- Cancel all ddl

```sql
alter vitess_migration cancel all;
alter schema_migration cancel all;
```

This command will cancel all ddl in pending (queued, ready, running) status.

- Pause a ddl
```sql
alter vitess_migration 'uuid' pause;
alter schema_migration 'uuid' pause;
```

This command will pause a ddl in pending (queued, ready, running) status. To guarantee correctness, the subsequent ddls which have the same table with the paused one will be blocked.

- Unpause a ddl
```sql
alter vitess_migration 'uuid' resume;
alter schema_migration 'uuid' resume;
```

- Pause all ddl

```sql
alter vitess_migration pause all;
alter schema_migration pause all;
```

- Unpause all ddl

```sql
alter vitess_migration resume all;
alter schema_migration resume all;
```

- Advancing ddl in postpone status

```sql
-- queued -> running
alter vitess_migration 'uuid' running;
alter schema_migration 'uuid' running;
-- running -> complete
alter vitess_migration 'uuid' complete;
alter schema_migration 'uuid' complete;
```

Under the effect of **`--postpone`**, transitioning from **`running -> complete`** is actually the process of manually performing a cutover.
1 change: 1 addition & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ const (
Workload
LastSeenGTID
FailPoints
SchemaMigration
)

// DropKeyType constants
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 @@ -390,6 +390,7 @@ var keywords = []keyword{
{"keyspaces", KEYSPACES},
{"lastseengtid", LASTSEENGTID},
{"failpoints", FAILPOINTS},
{"schema_migration", SCHEMA_MIGRATION},
{"key_block_size", KEY_BLOCK_SIZE},
{"kill", KILL},
{"lag", LAG},
Expand Down
Loading

0 comments on commit 74fe562

Please sign in to comment.