Skip to content

Commit 4531aaf

Browse files
committed
Remove dead Applier.AttemptInstantDDL, update docs, add local test
Remove the now-unused AttemptInstantDDL() method from Applier since instant DDL is handled by attemptInstantDDLEarly() in the Migrator. Update command-line-flags.md to document the new early execution behavior of --attempt-instant-ddl and add documentation for --force-instant-ddl. Add localtests/force-instant-ddl with an instant-compatible ALTER to exercise the --force-instant-ddl success path.
1 parent b5353ac commit 4531aaf

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

doc/command-line-flags.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ MySQL 8.0 supports "instant DDL" for some operations. If an alter statement can
6262

6363
It is not reliable to parse the `ALTER` statement to determine if it is instant or not. This is because the table might be in an older row format, or have some other incompatibility that is difficult to identify.
6464

65+
When `--attempt-instant-ddl` is enabled, `gh-ost` will attempt `ALGORITHM=INSTANT` **early**, right after connecting to the inspector and before creating ghost tables or starting binlog streaming. If instant DDL succeeds, the migration completes immediately without any of the normal setup overhead. This is especially beneficial for large tables where the ghost table creation and binlog streaming setup would otherwise add significant time.
66+
6567
`--attempt-instant-ddl` is disabled by default, but the risks of enabling it are relatively minor: `gh-ost` may need to acquire a metadata lock at the start of the operation. This is not a problem for most scenarios, but it could be a problem for users that start the DDL during a period with long running transactions.
6668

6769
`gh-ost` will automatically fallback to the normal DDL process if the attempt to use instant DDL is unsuccessful.
6870

71+
### force-instant-ddl
72+
73+
`--force-instant-ddl` requires instant DDL to succeed. If `ALGORITHM=INSTANT` is not supported for the given operation, `gh-ost` will abort the migration immediately instead of falling back to a regular row-copy migration. This is useful when you intend an instant metadata-only change and want to prevent accidental multi-hour migrations on large tables.
74+
75+
Implies `--attempt-instant-ddl`. Ignored with `--revert`.
76+
6977
### binlogsyncer-max-reconnect-attempts
7078
`--binlogsyncer-max-reconnect-attempts=0`, the maximum number of attempts to re-establish a broken inspector connection for sync binlog. `0` or `negative number` means infinite retry, default `0`
7179

go/logic/applier.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -279,36 +279,6 @@ func (this *Applier) ValidateOrDropExistingTables() error {
279279
return nil
280280
}
281281

282-
// AttemptInstantDDL attempts to use instant DDL (from MySQL 8.0, and earlier in Aurora and some others).
283-
// If successful, the operation is only a meta-data change so a lot of time is saved!
284-
// The risk of attempting to instant DDL when not supported is that a metadata lock may be acquired.
285-
// This is minor, since gh-ost will eventually require a metadata lock anyway, but at the cut-over stage.
286-
// Instant operations include:
287-
// - Adding a column
288-
// - Dropping a column
289-
// - Dropping an index
290-
// - Extending a VARCHAR column
291-
// - Adding a virtual generated column
292-
// It is not reliable to parse the `alter` statement to determine if it is instant or not.
293-
// This is because the table might be in an older row format, or have some other incompatibility
294-
// that is difficult to identify.
295-
func (this *Applier) AttemptInstantDDL() error {
296-
query := this.generateInstantDDLQuery()
297-
this.migrationContext.Log.Infof("INSTANT DDL query is: %s", query)
298-
299-
// Reuse cut-over-lock-timeout from regular migration process to reduce risk
300-
// in situations where there may be long-running transactions.
301-
tableLockTimeoutSeconds := this.migrationContext.CutOverLockTimeoutSeconds * 2
302-
this.migrationContext.Log.Infof("Setting LOCK timeout as %d seconds", tableLockTimeoutSeconds)
303-
lockTimeoutQuery := fmt.Sprintf(`set /* gh-ost */ session lock_wait_timeout:=%d`, tableLockTimeoutSeconds)
304-
if _, err := this.db.Exec(lockTimeoutQuery); err != nil {
305-
return err
306-
}
307-
// We don't need a trx, because for instant DDL the SQL mode doesn't matter.
308-
_, err := this.db.Exec(query)
309-
return err
310-
}
311-
312282
// CreateGhostTable creates the ghost table on the applier host
313283
func (this *Applier) CreateGhostTable() error {
314284
query := fmt.Sprintf(`create /* gh-ost */ table %s.%s like %s.%s`,

go/logic/migrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func (this *Migrator) Migrate() (err error) {
442442
if err := this.attemptInstantDDLEarly(); err == nil {
443443
return nil
444444
} else if this.migrationContext.ForceInstantDDL {
445-
return fmt.Errorf("--force-instant-ddl enabled but ALGORITHM=INSTANT is not supported for this operation: %s", err)
445+
return fmt.Errorf("--force-instant-ddl enabled but ALGORITHM=INSTANT is not supported for this operation: %w", err)
446446
} else {
447447
this.migrationContext.Log.Infof("ALGORITHM=INSTANT not supported for this operation, proceeding with original algorithm")
448448
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
drop table if exists gh_ost_test;
2+
3+
create table gh_ost_test (
4+
id int auto_increment,
5+
i int not null,
6+
color varchar(32),
7+
primary key(id)
8+
) auto_increment = 1;
9+
10+
insert into
11+
gh_ost_test
12+
values
13+
(null, 11, 'red');
14+
15+
insert into
16+
gh_ost_test
17+
values
18+
(null, 13, 'green');
19+
20+
insert into
21+
gh_ost_test
22+
values
23+
(null, 17, 'blue');
24+
25+
drop event if exists gh_ost_test;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--force-instant-ddl --alter='ADD COLUMN extra_col VARCHAR(255)'

0 commit comments

Comments
 (0)