Skip to content

Add --move-tables mode - #1755

Open
ericyan wants to merge 23 commits into
masterfrom
feature/move-tables
Open

Add --move-tables mode#1755
ericyan wants to merge 23 commits into
masterfrom
feature/move-tables

Conversation

@ericyan

@ericyan ericyan commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds support for a new move table mode, in which one or more tables are copied from a source MySQL cluster to a target MySQL cluster.

Related issue: #1681

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

Component PRs

Most of the PRs for this feature were created before Stacked PR were available. In addition to the PR stack, this feature branch also consolidates the following move-tables PRs:

Core migration flow

  • #1702 Add CLI parameters for move-tables
  • #1703 Applier logic and range-bounded copy support
  • #1705 Overall move-tables migration flow
  • #1710 Create and validate target tables
  • #1712 Configuration initialization fixes
  • #1718 Source-primary connections for primary-only operations
  • #1726 Coordinated multi-table migration
  • #1746 Support generated, JSON, unsigned, and typed-column handling in move-tables

Cutover and recovery

  • #1704 Cooperative cutover orchestration
  • #1708 Crash-safe resume
  • #1720 Restore drain GTID on resume
  • #1723 Cutover and recovery integration coverage

Throttling, hooks, and cleanup

  • #1709 Target-credential throttling
  • #1711 Move-tables hook environment variables
  • #1713 Enable throttling in move-tables mode
  • #1717 Post-migration cleanup
  • #1721 Move-tables lag measurement

Integration coverage and follow-up

  • #1714 Single-table integration test support
  • #1754 Drop target tables in noop mode

danieljoos and others added 23 commits August 18, 2026 13:49
Add move-table command parsing and validate the table list input.
Initialize migration context from the CLI configuration.

Refs: #1702
Build range-bounded copy queries and prepare target-table DML queries.
Apply copy batches through the applier and invoke them from the migrator.

Refs: #1703
Enable end-to-end target-table copying, route DML events to the target, and harden move-table initialization and table selection.

Refs: #1705

Co-authored-by: Chris Kirkland <chriskirkland@github.com>
Co-authored-by: Daniel Joos <danieljoos@github.com>
Co-authored-by: womoruyi <womoruyi@github.com>
Implement the T0-T6 cooperative cutover workflow and cover atomic target-table cutover behavior.

Refs: #1704

Co-authored-by: Zach Sierakowski <zacharysierakowski@github.com>
Create target tables in the destination database and abort safely when target tables already exist.

Refs: #1710
Use target-cluster credentials and replica status for control-replica throttling during move-table migrations.

Refs: #1709
Expose move-table source, target, and migration details to lifecycle hooks.

Refs: #1711
Initialize move-table configuration consistently before migration setup.

Refs: #1712
Enable the throttler in move-table mode with the move-table-specific configuration.

Refs: #1713
Persist per-table checkpoints and drain GTIDs so copying and cutover can resume safely after interruption.

Refs: #1708
Remove target artifacts and migration state after successful or failed move-table operations.

Refs: #1717
Add local integration scenarios for single-table copying and concurrent writes.

Refs: #1714
Restore the move-table drain GTID when resuming an interrupted migration.

Refs: #1720
Introduce source-primary connection configuration and guard primary-required move-table operations.

Refs: #1718
Update status reporting and lag measurement for move-table migrations.

Refs: #1721
Add failpoint-driven integration coverage for copy, drain, hook, and cutover recovery.

Refs: #1723
Extend migration state, copying, checkpointing, draining, and atomic rename to ordered sets of tables.

Refs: #1726
Exclude generated columns from move-tables writable column lists during
initial setup and resume. Use the filtered columns for row-copy queries
while preserving the complete column layout for binlog event ordinals.
Populate writable column metadata for fresh and resumed move-table
migrations so JSON, unsigned, and binary values are encoded correctly.
Exercise row copy and concurrent DML with signed, unsigned, and maximum
BIGINT UNSIGNED values.
@ericyan
ericyan force-pushed the feature/move-tables branch from 5acafd2 to f830fe0 Compare August 18, 2026 15:36
@ericyan ericyan added feature/move-tables PRs that are associated with the new move-tables feature feature labels Aug 19, 2026
@ericyan
ericyan marked this pull request as ready for review August 20, 2026 07:29
Copilot AI balanced review requested due to automatic review settings August 20, 2026 07:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds multi-table, GTID-based migration between MySQL clusters, including target-side copying, cooperative cutover, recovery, throttling, hooks, and integration coverage.

Changes:

  • Adds move-table configuration, copy/application flow, and atomic cutover.
  • Adds checkpoint-based recovery and multi-table runtime state.
  • Adds dual-cluster integration tooling and failpoint tests.
Show a summary per file
File Description
.github/workflows/move-tables-tests.yml Runs move-table integration tests.
.gitignore Ignores generated test artifacts.
doc/hooks.md Documents move-table hook variables.
go.mod Adds failpoint dependency.
go.sum Records dependency checksums.
go/base/context.go Defines move-table configuration and state.
go/base/context_test.go Tests move-table context behavior.
go/binlog/binlog_entry.go Extends binlog event handling.
go/binlog/gomysql_reader.go Supports move-table GTID streaming.
go/cmd/gh-ost/main.go Adds and validates CLI options.
go/logic/applier.go Implements target writes, locking, and checkpoints.
go/logic/applier_test.go Tests target-side application behavior.
go/logic/checkpoint.go Adds multi-table checkpoint state.
go/logic/checkpoint_test.go Tests checkpoint serialization.
go/logic/hooks.go Exposes move-table hook context.
go/logic/hooks_test.go Tests hook variables.
go/logic/inspect.go Inspects each source table.
go/logic/migrator.go Orchestrates copy, recovery, and cutover.
go/logic/migrator_move_tables_cleanup_test.go Tests post-migration cleanup.
go/logic/migrator_move_tables_cutover_test.go Tests cooperative cutover.
go/logic/migrator_test.go Extends migrator coverage.
go/logic/progress_snapshot.go Reports multi-table progress.
go/logic/server.go Exposes move-table status.
go/logic/test_utils_test.go Adds move-table test utilities.
go/logic/throttler.go Adds target-cluster throttling.
go/logic/throttler_test.go Tests target throttling.
go/mysql/utils.go Adds MySQL connection support.
go/sql/builder.go Builds split copy and checkpoint queries.
go/sql/builder_test.go Tests new query builders.
localtests/docker-compose-move-tables.yml Defines dual-cluster test topology.
localtests/move-tables-test.sh Implements integration-test harness.
localtests/move-tables/atomic-multi-table-cutover/create.sql Creates atomic-cutover fixtures.
localtests/move-tables/atomic-multi-table-cutover/tables.txt Lists atomic-cutover tables.
localtests/move-tables/atomic-multi-table-cutover/test.sh Exercises atomic cutover.
localtests/move-tables/generated-columns/create.sql Creates generated-column fixtures.
localtests/move-tables/generated-columns/tables.txt Lists generated-column tables.
localtests/move-tables/json/create.sql Creates JSON fixtures.
localtests/move-tables/json/tables.txt Lists JSON tables.
localtests/move-tables/multiple-three-concurrent-writes/create.sql Creates concurrent multi-table fixtures.
localtests/move-tables/multiple-three-concurrent-writes/on_test.sh Generates concurrent writes.
localtests/move-tables/multiple-three-concurrent-writes/tables.txt Lists concurrent test tables.
localtests/move-tables/multiple-three/create.sql Creates three-table fixtures.
localtests/move-tables/multiple-three/tables.txt Lists three-table fixtures.
localtests/move-tables/multiple-two/create.sql Creates two-table fixtures.
localtests/move-tables/multiple-two/tables.txt Lists two-table fixtures.
localtests/move-tables/resume-panic-before-drain-complete/create.sql Creates drain-recovery fixtures.
localtests/move-tables/resume-panic-before-drain-complete/tables.txt Lists drain-recovery tables.
localtests/move-tables/resume-panic-before-drain-complete/test.sh Tests recovery during drain.
localtests/move-tables/resume-panic-before-on-success-hook/create.sql Creates hook-recovery fixtures.
localtests/move-tables/resume-panic-before-on-success-hook/hooks/gh-ost-on-success Provides success hook fixture.
localtests/move-tables/resume-panic-before-on-success-hook/tables.txt Lists hook-recovery tables.
localtests/move-tables/resume-panic-before-on-success-hook/test.sh Tests recovery before success hook.
localtests/move-tables/resume-panic-on-row-copy/create.sql Creates row-copy recovery fixtures.
localtests/move-tables/resume-panic-on-row-copy/tables.txt Lists row-copy recovery tables.
localtests/move-tables/resume-panic-on-row-copy/test.sh Tests row-copy recovery.
localtests/move-tables/single-concurrent-writes/create.sql Creates concurrent single-table fixture.
localtests/move-tables/single-concurrent-writes/on_test.sh Generates concurrent writes.
localtests/move-tables/single-concurrent-writes/tables.txt Lists the concurrent table.
localtests/move-tables/single-with-hooks/create.sql Creates hook test fixture.
localtests/move-tables/single-with-hooks/hooks/gh-ost-on-before-cut-over Provides pre-cutover hook.
localtests/move-tables/single-with-hooks/hooks/gh-ost-on-row-copy-complete Provides row-copy hook.
localtests/move-tables/single-with-hooks/hooks/gh-ost-on-success Provides success hook.
localtests/move-tables/single-with-hooks/hooks/util.sh Shares hook utilities.
localtests/move-tables/single-with-hooks/tables.txt Lists hook test table.
localtests/move-tables/single-with-hooks/test.sh Tests hook execution.
localtests/move-tables/single/create.sql Creates basic fixture.
localtests/move-tables/single/tables.txt Lists basic fixture table.
localtests/move-tables/unsigned/create.sql Creates unsigned-column fixtures.
localtests/move-tables/unsigned/tables.txt Lists unsigned-column tables.
localtests/test.sh Integrates move-table tests.
script/docker-gh-ost-move-tables-tests Manages CI test containers.
script/move-tables/README.md Documents local test tooling.
script/move-tables/insert-source-primary-loop Generates source writes.
script/move-tables/mysql-source-primary Connects to source primary.
script/move-tables/mysql-source-replica Connects to source replica.
script/move-tables/mysql-target-primary Connects to target primary.
script/move-tables/mysql-target-replica Connects to target replica.
script/move-tables/reset Resets test clusters.
script/move-tables/setup Creates local test environment.
script/move-tables/teardown Removes local test environment.
vendor/github.com/pingcap/failpoint/.codecov.yml Vendors failpoint coverage configuration.
vendor/github.com/pingcap/failpoint/.gitignore Vendors failpoint ignore rules.
vendor/github.com/pingcap/failpoint/CONTRIBUTING.md Vendors contribution guidance.
vendor/github.com/pingcap/failpoint/LICENSE Vendors dependency license.
vendor/github.com/pingcap/failpoint/MAINTAINERS.md Vendors maintainer metadata.
vendor/github.com/pingcap/failpoint/Makefile Vendors failpoint build targets.
vendor/github.com/pingcap/failpoint/README.md Vendors failpoint documentation.
vendor/github.com/pingcap/failpoint/failpoint.go Vendors core failpoint implementation.
vendor/github.com/pingcap/failpoint/failpoints.go Vendors failpoint registry.
vendor/github.com/pingcap/failpoint/http.go Vendors failpoint HTTP support.
vendor/github.com/pingcap/failpoint/marker.go Vendors failpoint markers.
vendor/github.com/pingcap/failpoint/terms.go Vendors failpoint expression terms.
vendor/modules.txt Registers vendored dependency.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 78/93 changed files
  • Comments generated: 4
  • Review effort level: Balanced

Comment thread go/logic/applier.go
Comment on lines +287 to +294
if apl.migrationContext.IsMoveTablesMode() {
lockTable = "movetables." + apl.migrationContext.MoveTablesRunToken()
lockSubject = fmt.Sprintf("tables %v", apl.migrationContext.MoveTables.TableNames)
} else {
lockTable = apl.originalTableName()
lockSubject = fmt.Sprintf("`%s`.`%s`", apl.migrationContext.DatabaseName, apl.originalTableName())
}
lockName := buildMigrationLockName(apl.migrationContext.GetTargetDatabaseName(), lockTable)
Comment thread go/logic/migrator.go
Comment on lines +3072 to +3077
applied := coords.SmallerThanOrEquals(mgtr.applier.CurrentCoordinates)
idle := len(mgtr.applyEventsQueue) == 0 && (mgtr.eventsStreamer == nil || len(mgtr.eventsStreamer.eventsChannel) == 0)
if applied || idle {
if !applied {
mgtr.applier.CurrentCoordinates = coords.Clone()
}
Comment thread go/logic/migrator.go
Comment on lines +1506 to +1509
if mgtr.migrationContext.Checkpoint {
if err := mgtr.persistMoveTablesCutOverCheckpoint(drainGTID, false); err != nil {
return fmt.Errorf("failed to persist move-tables cutover checkpoint: %w", err)
}
Comment thread go/logic/migrator.go
Comment on lines +1284 to +1286
if err := mgtr.applier.CreateCheckpointTable(); err != nil {
mgtr.migrationContext.Log.Errorf("unable to create checkpoint table, see further error details")
}
Comment thread go/logic/migrator.go

// moveTablesCutOver orchestrates the cooperative cutover protocol for move-tables
// mode. It implements the T0-T6 transitions described in
// docs/learning/design-refs/coop_cutover.md §1.3.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are still some references to our internal poc docs in here. e.g. all the § refs.
Maybe it would also make sense to add a condensed version of the design document to the docs folder to describe what the move-tables mode actually does and how the cutover process is supposed to work.

@ggilder

ggilder commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This is intriguing; can you perhaps elaborate on how this compares to ghostferry and the rationale for building this into gh-ost rather than as a standalone tool?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/move-tables PRs that are associated with the new move-tables feature feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants