{"record":{"id":"f95c0f49d55458a3","repo":"vitessio/vitess","slug":"cannot-migrate-while-vreplication-streams-in-sourc","errorCode":null,"errorMessage":"cannot migrate while vreplication streams in source shards are still copying: %s","messagePattern":"cannot migrate while vreplication streams in source shards are still copying: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/stream_migrator.go","lineNumber":480,"sourceCode":"\t\t}\n\n\t\ttabletStreams, err := sm.legacyReadTabletStreams(ctx, source.GetPrimary(), \"\")\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(tabletStreams) == 0 {\n\t\t\t// No VReplication is running. So, we have no work to do.\n\t\t\treturn nil\n\t\t}\n\n\t\tquery := \"select distinct vrepl_id from _vt.copy_state where vrepl_id in \" + VReplicationStreams(tabletStreams).Values()\n\t\tp3qr, err := sm.ts.TabletManagerClient().VReplicationExec(ctx, source.GetPrimary().Tablet, query)\n\t\tswitch {\n\t\tcase err != nil:\n\t\t\treturn err\n\t\tcase len(p3qr.Rows) != 0:\n\t\t\treturn fmt.Errorf(\"cannot migrate while vreplication streams in source shards are still copying: %s\", source.GetShard().ShardName())\n\t\t}\n\n\t\tmu.Lock()\n\t\tdefer mu.Unlock()\n\t\tstreams[source.GetShard().ShardName()] = tabletStreams\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Validate that streams match across source shards.\n\tvar (\n\t\treference []*VReplicationStream\n\t\trefshard  string\n\t\tstreams2  = make(map[string][]*VReplicationStream)\n\t)\n","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/stream_migrator.go#L462-L498","documentation":"After collecting all tablet streams on a source shard, the migrator checks _vt.copy_state for rows belonging to those streams. If any stream still has copy-state entries it is still in the bulk-copy phase and its position is not stable; migrating a copying stream would lose data, so the migration aborts naming the source shard.","triggerScenarios":"Calling MigrateStreams / workflow stream migration while a stream on the source shard is actively copying tables — i.e. `select distinct vrepl_id from _vt.copy_state where vrepl_id in (...)` returns rows for any of the shard's streams.","commonSituations":"Newly created streams still bulk-copying large tables; copy phase stalled or very slow due to large tables/network; operator attempted migration too soon after starting streams.","solutions":["Wait until all streams finish copying: monitor `select count(*) from _vt.copy_state` / vtctldclient Workflow status until copy phase completes.","If a copy is stalled or unwanted, remove that stream and restart it before migrating.","Throttle/backfill large tables or use faster copy settings so the copy phase finishes, then retry the migration.","Only run stream migration once every source-shard stream reports Running (not Copying) with empty copy_state."],"exampleFix":"// before: migrate attempted while stream is copying\n$ vtctldclient Workflow --keyspace customer Migrate ...\nERROR: cannot migrate while vreplication streams in source shards are still copying: -40\n// after: wait for copy to finish\n$ watch 'mysql -S ... -e \"select count(*) from _vt.copy_state\"' # wait for 0\n$ vtctldclient Workflow --keyspace customer Migrate ...","handlingStrategy":"validation","validationCode":"qr, _ := tmclient.VReplicationExec(ctx, tablet, \"select distinct vrepl_id from _vt.copy_state\")\nif len(qr.Rows) != 0 {\n    return fmt.Errorf(\"wait for copy phase on %d stream(s) before migrating\", len(qr.Rows))\n}","typeGuard":null,"tryCatchPattern":"err := migrateStreams(ctx, cfg)\nif err != nil && strings.Contains(err.Error(), \"still copying\") {\n    // poll _vt.copy_state until empty on the named shard, then retry\n}","preventionTips":["Wait for Workflow status to show copy complete before migrating","Monitor _vt.copy_state row counts as a pre-flight check","Schedule migrations after large table backfills finish"],"tags":["vitess","vreplication","workflow-migration","copy-phase"],"backgroundTag":"vreplication-still-copying","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}