{"record":{"id":"c96cba7d3f3de607","repo":"vitessio/vitess","slug":"could-not-delete-target-streams-v","errorCode":null,"errorMessage":"could not delete target streams: %v","messagePattern":"could not delete target streams: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/stream_migrator.go","lineNumber":212,"sourceCode":"\t}\n\n\treturn streams\n}\n\n// Templates returns a copy of the StreamMigrator's template streams.\nfunc (sm *StreamMigrator) Templates() []*VReplicationStream {\n\treturn VReplicationStreams(sm.templates).Copy().ToSlice()\n}\n\n// CancelStreamMigrations cancels the stream migrations.\nfunc (sm *StreamMigrator) CancelStreamMigrations(ctx context.Context) error {\n\tif sm.streams == nil {\n\t\treturn nil\n\t}\n\terrs := &concurrency.AllErrorRecorder{}\n\n\tif err := sm.deleteTargetStreams(ctx); err != nil {\n\t\terrs.RecordError(fmt.Errorf(\"could not delete target streams: %v\", err))\n\t}\n\n\t// Restart the source streams, but leave the Reshard workflow's reverse\n\t// variant stopped.\n\terr := sm.ts.ForAllSources(func(source *MigrationSource) error {\n\t\t// We intend to update all but our workflow's reverse streams, so we\n\t\t// indicate that it's safe in this case using the comment diretive.\n\t\tquery := fmt.Sprintf(\"update /*vt+ %s */ _vt.vreplication set state='Running', stop_pos=null, message='' where db_name=%s and workflow != %s\",\n\t\t\tvreplication.AllowUnsafeWriteCommentDirective, encodeString(source.GetPrimary().DbName()), encodeString(sm.ts.ReverseWorkflowName()))\n\t\t_, err := sm.ts.VReplicationExec(ctx, source.GetPrimary().Alias, query)\n\t\treturn err\n\t})\n\tif err != nil {\n\t\terrs.RecordError(fmt.Errorf(\"could not restart source streams: %v\", err))\n\t\tsm.logger.Errorf(\"Cancel stream migrations failed: could not restart source streams: %v\", err)\n\t}\n\tif errs.HasErrors() {\n\t\treturn errs.AggrError(vterrors.Aggregate)","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/stream_migrator.go#L194-L230","documentation":"CancelStreamMigrations rolls back a stream migration. The first rollback step deletes the VReplication streams that were created on the target shards. If deleteTargetStreams fails, the error is wrapped and recorded, and cancellation continues with restarting source streams; all collected errors are aggregated and returned at the end.","triggerScenarios":"Calling CancelStreamMigration (via vtctld/workflow API) when target-shard vreplication deletion fails — e.g. a target primary tablet is unreachable, VReplicationExec errors, or the target shards have no healthy primary.","commonSituations":"Target primary tablet down or in a bad state during cancel; network partition between vtctld and target tablets; target keyspace already partially cleaned by a previous failed attempt.","solutions":["Check target shard primary tablet health and retry CancelStreamMigration.","Fix tablet connectivity (vtctld to tablet gRPC) and re-run the cancel.","Manually delete the leftover _vt.vreplication rows on the target shards if automated cancel keeps failing.","Re-run the full cancel flow; it is idempotent for already-deleted streams."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check target primaries are reachable before cancelling\nfor _, shard := range targetShards {\n    if !tabletHealthy(shard.Primary) { return fmt.Errorf(\"target primary %v unhealthy\", shard) }\n}","typeGuard":null,"tryCatchPattern":"err := client.CancelStreamMigration(ctx, keyspace, workflow)\nif err != nil && strings.Contains(err.Error(), \"could not delete target streams\") {\n    // fix target tablet health, then retry the cancel (idempotent)\n}","preventionTips":["Confirm all target shard primaries are healthy before cancelling","Monitor aggregated error output for the underlying per-shard cause","Clean leftover target streams after repeated failed cancels"],"tags":["vreplication","cancel","cleanup","tablet"],"backgroundTag":"vreplication-cancel-cleanup-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}