vitessio/vitess · error
uid %v is already in use
Error message
uid %v is already in use
What it means
SourceShardAdd assigns a unique uid to each new SourceShard entry in the shard record. If a SourceShard with the requested uid already exists, the update is rejected to prevent silently overwriting an existing replication source.
Source
Thrown at go/vt/wrangler/shard.go:203
}
// SourceShardAdd will add a new SourceShard inside a shard.
func (wr *Wrangler) SourceShardAdd(ctx context.Context, keyspace, shard string, uid int32, skeyspace, sshard string, keyRange *topodatapb.KeyRange, tables []string) (err error) {
resp, err := wr.VtctldServer().SourceShardAdd(ctx, &vtctldatapb.SourceShardAddRequest{
Keyspace: keyspace,
Shard: shard,
Uid: uid,
SourceKeyspace: skeyspace,
SourceShard: sshard,
KeyRange: keyRange,
Tables: tables,
})
if err != nil {
return err
}
if resp.Shard == nil {
return fmt.Errorf("uid %v is already in use", uid)
}
return nil
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Check existing uids with `vtctldclient GetShard <keyspace>/<shard>` and pick a free uid.
- If the previous add already succeeded, skip the call — the desired state is already in place.
- In automated workflows, generate uids monotonically (e.g. max(existing)+1).
Example fix
// before vtctldclient SourceShardAdd commerce/0 0 customer/0 // error: uid 0 is already in use // after vtctldclient GetShard commerce/0 # existing uid 0 vtctldclient SourceShardAdd commerce/0 1 customer/0
Defensive patterns
Strategy: validation
Validate before calling
// Before SourceShardAdd, pick an unused uid
shardInfo, _ := vtctldclientGetShard(keyspace, shard)
used := map[int64]bool{}
for _, ss := range shardInfo.SourceShards { used[ss.Uid] = true }
if used[uid] {
var maxUid int64
for u := range used { if u > maxUid { maxUid = u } }
uid = maxUid + 1
} Prevention
- Always inspect existing source_shards before adding a new one
- Allocate uids as max(existing)+1 in automation
- Check shard record before retrying a failed SourceShardAdd — it may have succeeded
When it happens
Trigger: Calling SourceShardAdd (via `vtctldclient SourceShardAdd <keyspace/shard> <uid> <source keyspace/shard>`) with a uid already used by another SourceShard on the target shard.
Common situations: Scripting a MoveTables/Reshard workflow manually and reusing uid 0 twice; retrying a partially-failed command that already added the source shard.
Related errors
- no SourceShard with uid %v
- shard %v/%v already has SourceShards, not overwriting them (
- shard %v/%v has no source shard
- shard %v/%v has no primary
- can't rebuild serving keyspace while a migration is on going
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/b42a3d4a90fbee74.
Report an issue: GitHub.