{"record":{"id":"692a185672c767bb","repo":"vitessio/vitess","slug":"switch-command-shards-not-in-topo-v","errorCode":null,"errorMessage":"switch command shards not in topo: %v","messagePattern":"switch command shards not in topo: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/utils.go","lineNumber":514,"sourceCode":"\tshardSet := sets.New[string]()\n\tfor _, si := range shards {\n\t\tshardSet.Insert(si.ShardName())\n\t}\n\n\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 {","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/utils.go#L496-L532","documentation":"CompareShards validates that the shards specified on a switch-traffic/reshard command exactly match the shards recorded in the topology for the keyspace. When the command lists shards that do not exist in the topo (wfExtra), this error is recorded and surfaced as part of a shard-mismatch error. It prevents switching traffic for shards that the topology doesn't know about.","triggerScenarios":"Running SwitchTraffic (via validate) with -shards containing shard names absent from the target keyspace's topo — e.g. shard names from a different keyspace, typo'd shard ranges, or shards removed by a prior merge/reshard.","commonSituations":"Stale command-line scripts referencing pre-reshard shard names; copying shard lists between keyspaces; typos like `-80` vs `-80-` formatting differences.","solutions":["List actual shards with `vtctldclient GetTablets` or topo browse and correct the -shards argument to match exactly.","If shard names changed after a reshard, re-run the switch with the new shard ranges.","Check for formatting differences (leading/trailing hyphens, e.g. `-` vs `0-80`)."],"exampleFix":"// before\nvtctldclient Reshard --shards=0-c0,d0- SwitchTraffic\n// error: switch command shards not in topo: [d0-]\n// after\nvtctldclient Reshard --shards=0-c0,c0- SwitchTraffic","handlingStrategy":"validation","validationCode":"// reconcile your -shards list against the topo before switching\nwant := sets.New[string](shards...)\nhave := sets.New[string](topoShardsForKeyspace(ks)...)\nif extra := want.Difference(have); extra.Len() > 0 {\n    return fmt.Errorf(\"unknown shards: %v\", sets.List(extra))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive shard lists from the topo at runtime instead of hardcoding them.","Update scripts after any Reshard/MergeShards operation.","Normalize shard-name formatting (leading hyphen ranges like `-80`)."],"tags":["go","topology","sharding","validation"],"backgroundTag":"shards-not-in-topology","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}