vitessio/vitess · error
same keyrange is present in source and target: %v
Error message
same keyrange is present in source and target: %v
What it means
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.
Source
Thrown at go/vt/topotools/split.go:34
package topotools
import (
"errors"
"fmt"
"vitess.io/vitess/go/vt/key"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/topo"
)
// ValidateForReshard returns an error if sourceShards cannot reshard into
// targetShards.
func ValidateForReshard(sourceShards, targetShards []*topo.ShardInfo) error {
for _, source := range sourceShards {
for _, target := range targetShards {
if key.KeyRangeEqual(source.KeyRange, target.KeyRange) {
return fmt.Errorf("same keyrange is present in source and target: %v", key.KeyRangeString(source.KeyRange))
}
}
}
sourcekr, err := combineKeyRanges(sourceShards)
if err != nil {
return err
}
targetkr, err := combineKeyRanges(targetShards)
if err != nil {
return err
}
if !key.KeyRangeEqual(sourcekr, targetkr) {
return fmt.Errorf("source and target keyranges don't match: %v vs %v", key.KeyRangeString(sourcekr), key.KeyRangeString(targetkr))
}
return nil
}
func combineKeyRanges(shards []*topo.ShardInfo) (*topodatapb.KeyRange, error) {View on GitHub (pinned to 01a25a7d17)
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.
Example fix
// before: target includes the original shard
sourceShards := []string{"0-"}
targetShards := []string{"0-", "..."} // wrong
// after
targetShards := []string{"-80", "80-"} Defensive patterns
Strategy: validation
Validate before calling
for _, s := range sourceShards {
for _, t := range targetShards {
if key.KeyRangeEqual(s.KeyRange, t.KeyRange) {
return fmt.Errorf("shard %v appears in both source and target", s.ShardName())
}
}
} Type guard
func hasIdenticalKeyRange(source, target []*topo.ShardInfo) bool {
for _, s := range source {
for _, t := range target {
if key.KeyRangeEqual(s.KeyRange, t.KeyRange) {
return true
}
}
}
return false
} Try / catch
if err := topotools.ValidateForReshard(sourceShards, targetShards); err != nil {
if strings.Contains(err.Error(), "same keyrange is present") {
return fmt.Errorf("fix shard plan: remove unchanged shard from one side: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- source and target keyranges don't match: %v vs %v
- non-contiguous KeyRange values for %v in cell %v at shard %v
- shard %v/%v has a different KeyRange: %v != %v
- can't rebuild serving keyspace while a migration is on going
- %w: uid %v is already in use
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/08ce8f3d93f9a1a1.
Report an issue: GitHub.