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

  1. Check existing uids with `vtctldclient GetShard <keyspace>/<shard>` and pick a free uid.
  2. If the previous add already succeeded, skip the call — the desired state is already in place.
  3. 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

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


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/b42a3d4a90fbee74. Report an issue: GitHub.