{"record":{"id":"08ce8f3d93f9a1a1","repo":"vitessio/vitess","slug":"same-keyrange-is-present-in-source-and-target-v","errorCode":null,"errorMessage":"same keyrange is present in source and target: %v","messagePattern":"same keyrange is present in source and target: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/topotools/split.go","lineNumber":34,"sourceCode":"\npackage topotools\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\n\t\"vitess.io/vitess/go/vt/key\"\n\ttopodatapb \"vitess.io/vitess/go/vt/proto/topodata\"\n\t\"vitess.io/vitess/go/vt/topo\"\n)\n\n// ValidateForReshard returns an error if sourceShards cannot reshard into\n// targetShards.\nfunc ValidateForReshard(sourceShards, targetShards []*topo.ShardInfo) error {\n\tfor _, source := range sourceShards {\n\t\tfor _, target := range targetShards {\n\t\t\tif key.KeyRangeEqual(source.KeyRange, target.KeyRange) {\n\t\t\t\treturn fmt.Errorf(\"same keyrange is present in source and target: %v\", key.KeyRangeString(source.KeyRange))\n\t\t\t}\n\t\t}\n\t}\n\tsourcekr, err := combineKeyRanges(sourceShards)\n\tif err != nil {\n\t\treturn err\n\t}\n\ttargetkr, err := combineKeyRanges(targetShards)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !key.KeyRangeEqual(sourcekr, targetkr) {\n\t\treturn fmt.Errorf(\"source and target keyranges don't match: %v vs %v\", key.KeyRangeString(sourcekr), key.KeyRangeString(targetkr))\n\t}\n\treturn nil\n}\n\nfunc combineKeyRanges(shards []*topo.ShardInfo) (*topodatapb.KeyRange, error) {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/topotools/split.go#L16-L52","documentation":"ValidateForReshard verifies that a set of source shards can be resharded into a set of target shards. If any source shard has a KeyRange exactly equal to any target shard's KeyRange, resharding would be a no-op/dangerous overlap and this error is returned, naming the offending keyrange.","triggerScenarios":"Calling ValidateForReshard (via vtctld reshard setup / buildResharder) with target shard lists that still include an original source shard — e.g. resharding keyspace shard '0-' into targets where one target is '0-' unchanged, or passing the same ShardInfo list as both source and target.","commonSituations":"Specifying target shards by copying the source shard list and forgetting to remove the shard being split; planning a reshard where one of the new shards retains the identical keyrange of a source shard; copy-paste errors in shard name/keyrange definitions.","solutions":["Remove the identical keyrange from either the source or the target list — every target keyrange must differ from every source keyrange.","If splitting a shard, define non-overlapping new keyranges covering the full range of the removed source shards (e.g. split 0- into -80,80- and exclude 0- from sources).","Re-run ValidateForReshard after correcting the shard plan to confirm no overlaps remain."],"exampleFix":"// before: target includes the original shard\nsourceShards := []string{\"0-\"}\ntargetShards := []string{\"0-\", \"...\"} // wrong\n// after\ntargetShards := []string{\"-80\", \"80-\"}","handlingStrategy":"validation","validationCode":"for _, s := range sourceShards {\n    for _, t := range targetShards {\n        if key.KeyRangeEqual(s.KeyRange, t.KeyRange) {\n            return fmt.Errorf(\"shard %v appears in both source and target\", s.ShardName())\n        }\n    }\n}","typeGuard":"func hasIdenticalKeyRange(source, target []*topo.ShardInfo) bool {\n    for _, s := range source {\n        for _, t := range target {\n            if key.KeyRangeEqual(s.KeyRange, t.KeyRange) {\n                return true\n            }\n        }\n    }\n    return false\n}","tryCatchPattern":"if err := topotools.ValidateForReshard(sourceShards, targetShards); err != nil {\n    if strings.Contains(err.Error(), \"same keyrange is present\") {\n        return fmt.Errorf(\"fix shard plan: remove unchanged shard from one side: %w\", err)\n    }\n    return err\n}","preventionTips":["When planning a reshard, always exclude the original source shards from the target list","Generate target shard lists programmatically (e.g. split helper) instead of hand-writing them","Run ValidateForReshard in CI on every reshard plan before executing it"],"tags":["resharding","keyrange","validation","topo"],"backgroundTag":"keyrange-overlap","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}