Move tables n:m support#693
Merged
Merged
Conversation
Replace individual SourceDB/SourceConfig/SourceDSN/TargetDSN fields
with Sources []SourceResource slice in the Resources struct. This
prepares the check package for N:M move operations where multiple
source databases need to be validated.
All checks updated to iterate over Sources:
- configuration: validates MySQL config on all sources
- privileges: checks privileges on all sources via checkSourcePrivileges helper
- resume_state: uses Sources[0] for checkpoint validation
- target_state/table_compatibility: unchanged (use SourceTables only)
The runner wraps its single source into []SourceResource{...} for
backward compatibility. No behavioral change for 1:1 moves.
Refactor CutOver to accept []CutOverSource instead of a single
db/feed pair. This prepares the cutover for N:M move operations
where multiple source databases need to be locked, flushed, and
renamed atomically.
Key changes:
- New CutOverSource struct with DB, ReplClient, Tables
- NewCutOver accepts []CutOverSource
- algorithmCutover locks all sources, flushes all feeds, checks
all changes flushed, then renames per source
- On partial rename failure, completed renames are rolled back
by reversing the RENAME TABLE statements
The runner wraps its single source into []CutOverSource{...} for
backward compatibility. No behavioral change for 1:1 moves.
Support multiple source databases in move operations, enabling N:M resharding where data from N source shards is redistributed across M target shards. Depends on: - check-resources-refactor (Sources []SourceResource) - cutover-multi-source ([]CutOverSource with rollback) Key changes: Runner struct: - New sourceInfo struct holds per-source db, config, dsn, replClient, tables - Runner.sources []sourceInfo replaces singular source/sourceConfig/replClient - Helper methods: flushAllReplClients, setWatermarkOptimizationAll, getDeltaLenAll, stopPeriodicFlushAll Move struct: - New SourceDSNs []string field for programmatic N:M configuration - SourceDSN remains as CLI convenience for 1:1 case Checkpoint: - New binlog_positions TEXT column (JSON) replaces binlog_name/binlog_pos - Per-source binlog positions serialized as JSON keyed by DB name - Stored on sources[0] by convention Foundation: - TableInfo.DB() accessor for per-chunk source routing - Buffered copier uses chunk.Table.DB() instead of single c.db Tests: - New TestNtoMShardedMove: 2 sources x 2 targets, 100 rows redistributed - Existing tests updated for new struct layout
# Conflicts: # pkg/move/cutover.go # pkg/move/runner.go
# Conflicts: # pkg/move/check/configuration.go # pkg/move/check/resume_state.go # pkg/move/runner.go
…h configuration check
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the move/reshard runner to support N:M moves (multiple source shards to multiple target shards), addressing Issue #690.
Changes:
- Add multi-source support in
move.Runnerby managing per-source DB/config/repl-client state and subscribing chunkers per source. - Update checkpointing to persist per-source binlog positions (as JSON) and restore them on resume.
- Adjust the buffered copier to read chunk data from the correct per-chunk source DB, and add E2E tests for N:M sharded moves and determinism.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/testutils/testing.go | Ensures unique test DB names within a single test via an atomic counter. |
| pkg/table/tableinfo.go | Exposes TableInfo.DB() so downstream components can read from the correct source DB. |
| pkg/move/runner.go | Core N:M runner changes: multiple sources, multiple repl clients, per-source checkpoint binlog positions, multi-source locks/flush/status. |
| pkg/move/move.go | Adds Move.SourceDSNs to represent multiple sources for N:M moves. |
| pkg/copier/buffered.go | Reads chunk rows using the chunk’s source table DB connection (required for N:M). |
| pkg/move/move_test.go | Updates resume E2E test wiring for the new multi-source runner structure. |
| pkg/move/move_sharded_test.go | Adds E2E tests for N:M sharded moves and checkpoint determinism. |
| pkg/move/check/target_state.go | Minor formatting cleanup. |
| pkg/move/check/resume_state.go | Minor error message tweak/formatting cleanup. |
| pkg/move/check/privileges_test.go | Adds coverage that privileges checks iterate across all sources. |
| pkg/move/check/configuration_test.go | Adds coverage that configuration checks handle multiple sources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review feedback: - Add sourceKey() helper (addr/dbname) for stable source identification - Sort sources by sourceKey instead of raw DSN to survive credential rotations - Use sourceKey as checkpoint map key to avoid collisions when sources share DBName - Avoid mutating caller's Move.SourceDSNs slice by sorting parsed sources instead - Update determinism test to match new sort behavior
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
aparajon
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Pull Request should be associated with an Issue.
Fixes #690