{"record":{"id":"7053052d672e6017","repo":"vitessio/vitess","slug":"topo-shards-not-in-switch-command-v","errorCode":null,"errorMessage":"topo shards not in switch command: %v","messagePattern":"topo shards not in switch command: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/utils.go","lineNumber":519,"sourceCode":"\ttopoShards, err := ts.GetShardNames(ctx, keyspace)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttopoShardSet := sets.New[string](topoShards...)\n\tif !shardSet.Equal(topoShardSet) {\n\t\twfExtra := shardSet.Difference(topoShardSet)\n\t\ttopoExtra := topoShardSet.Difference(shardSet)\n\n\t\tvar rec concurrency.AllErrorRecorder\n\t\tif wfExtra.Len() > 0 {\n\t\t\twfExtraSorted := sets.List(wfExtra)\n\t\t\trec.RecordError(fmt.Errorf(\"switch command shards not in topo: %v\", wfExtraSorted))\n\t\t}\n\n\t\tif topoExtra.Len() > 0 {\n\t\t\ttopoExtraSorted := sets.List(topoExtra)\n\t\t\trec.RecordError(fmt.Errorf(\"topo shards not in switch command: %v\", topoExtraSorted))\n\t\t}\n\n\t\treturn fmt.Errorf(\"mismatched shards for keyspace %s: %s\", keyspace, strings.Join(rec.ErrorStrings(), \"; \"))\n\t}\n\n\treturn nil\n}\n\n// HashStreams produces a stable hash based on the target keyspace and migration\n// targets.\nfunc HashStreams(targetKeyspace string, targets map[string]*MigrationTarget) int64 {\n\tvar expanded []string\n\tfor shard, target := range targets {\n\t\tfor uid := range target.Sources {\n\t\t\texpanded = append(expanded, fmt.Sprintf(\"%s:%d\", shard, uid))\n\t\t}\n\t}\n","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/utils.go#L501-L537","documentation":"The mirror-image of the previous check: CompareShards found shards present in the topology but not included in the switch command's shard list (topoExtra). A partial shard list would leave some shards un-switched, so validation fails with this recorded error aggregated into the shard-mismatch message.","triggerScenarios":"Running SwitchTraffic/validate with a -shards subset that omits one or more shards that exist in the keyspace's topo — e.g. switching only `-80` while `80-` still exists.","commonSituations":"Partial cutover attempts during Reshard; scripted commands written when the keyspace had fewer shards; forgetting to include newly created shards.","solutions":["Include every topo shard in the -shards list, or verify that a partial switch is actually intended and use the appropriate per-shard workflow commands.","Enumerate shards from the topo (GetTablets / topo shards for the keyspace) and reconcile against the command.","After a reshard, switch all new shards together in one command."],"exampleFix":"// before\nvtctldclient Reshard --shards=0-80 SwitchTraffic // topo also has 80-\n// error: topo shards not in switch command: [80-]\n// after\nvtctldclient Reshard --shards=0-80,80- SwitchTraffic","handlingStrategy":"validation","validationCode":"// ensure the switch covers every topo shard\nhave := sets.New[string](topoShardsForKeyspace(ks)...)\nwant := sets.New[string](shards...)\nif missing := have.Difference(want); missing.Len() > 0 {\n    return fmt.Errorf(\"missing shards in command: %v\", sets.List(missing))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always switch all shards of the keyspace together unless intentionally partial.","Regenerate shard lists after resharding operations.","Diff your command's shard list against GetTablets output before running."],"tags":["go","topology","sharding","validation"],"backgroundTag":"shards-not-in-switch-command","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}