{"record":{"id":"f7957f0ede466dbe","repo":"vitessio/vitess","slug":"some-streams-already-exist-in-the-target-shards-p","errorCode":null,"errorMessage":"some streams already exist in the target shards, please clean them up and retry the command","messagePattern":"some streams already exist in the target shards, please clean them up and retry the command","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/resharder.go","lineNumber":179,"sourceCode":"\tif err := rs.readRefStreams(ctx); err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"readRefStreams\")\n\t}\n\treturn rs, nil\n}\n\n// validateTargets ensures that the target shards have no existing\n// VReplication workflow streams as that is an invalid starting\n// state for the non-serving shards involved in a Reshard.\nfunc (rs *resharder) validateTargets(ctx context.Context) error {\n\terr := rs.forAll(rs.targetShards, func(target *topo.ShardInfo) error {\n\t\ttargetPrimary := rs.targetPrimaries[target.ShardName()]\n\t\tquery := \"select 1 from _vt.vreplication where db_name=\" + encodeString(targetPrimary.DbName())\n\t\tp3qr, err := rs.wr.tmc.VReplicationExec(ctx, targetPrimary.Tablet, query)\n\t\tif err != nil {\n\t\t\treturn vterrors.Wrapf(err, \"VReplicationExec(%v, %s)\", targetPrimary.Tablet, query)\n\t\t}\n\t\tif len(p3qr.Rows) != 0 {\n\t\t\treturn errors.New(\"some streams already exist in the target shards, please clean them up and retry the command\")\n\t\t}\n\t\treturn nil\n\t})\n\treturn err\n}\n\nfunc (rs *resharder) readRefStreams(ctx context.Context) error {\n\tvar mu sync.Mutex\n\terr := rs.forAll(rs.sourceShards, func(source *topo.ShardInfo) error {\n\t\tsourcePrimary := rs.sourcePrimaries[source.ShardName()]\n\n\t\tquery := fmt.Sprintf(\"select workflow, source, cell, tablet_types from _vt.vreplication where db_name=%s and message != 'FROZEN'\", encodeString(sourcePrimary.DbName()))\n\t\tp3qr, err := rs.wr.tmc.VReplicationExec(ctx, sourcePrimary.Tablet, query)\n\t\tif err != nil {\n\t\t\treturn vterrors.Wrapf(err, \"VReplicationExec(%v, %s)\", sourcePrimary.Tablet, query)\n\t\t}\n\t\tqr := sqltypes.Proto3ToResult(p3qr)\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/resharder.go#L161-L197","documentation":"Before creating a Reshard workflow, wrangler checks each target shard's primary for existing rows in _vt.vreplication and fails if any exist. Pre-existing streams in the target shards would collide with the new reshard streams, so the command aborts and asks the operator to clean them up first. This prevents duplicated or conflicting vreplication state on the target.","triggerScenarios":"Running Reshard against target shards whose primary tablet already has _vt.vreplication rows — e.g. from a previously cancelled/failed reshard, MoveTables into the same keyspace, or manually created streams.","commonSituations":"Retrying a reshard after a failed first attempt without cleanup; reusing shards that hosted earlier workflows; orphaned vreplication rows left when a workflow was dropped without stream removal.","solutions":["List existing streams on the target primaries: SELECT id, workflow, workflow_type FROM _vt.vreplication","Remove stale streams with vtctldclient Workflow --keyspace <ks> <workflow> delete or DELETE FROM _vt.vreplication WHERE ...","Re-run the Reshard command after all target shards are clean"],"exampleFix":"-- on each target primary\nSELECT id, workflow FROM _vt.vreplication WHERE db_name='vt_ks';\nDELETE FROM _vt.vreplication WHERE id=<stale_id>;\n-- then retry the reshard","handlingStrategy":"validation","validationCode":"-- for each target shard primary, before Reshard\nSELECT COUNT(*) FROM _vt.vreplication WHERE db_name='vt_<ks>';\n-- must be 0","typeGuard":null,"tryCatchPattern":"if err := rs.createStreams(ctx); err != nil {\n\tif strings.Contains(err.Error(), \"streams already exist\") {\n\t\t// run cleanup of target shard vreplication rows, then retry\n\t}\n\treturn err\n}","preventionTips":["Delete workflows fully (vtctldclient Workflow delete) after failures","Audit target shards for leftover vreplication rows before resharding","Avoid sharing target keyspaces between concurrent workflows without partitioning"],"tags":["resharding","vreplication","wrangler"],"backgroundTag":"existing-vreplication-streams","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}