{"record":{"id":"b42a3d4a90fbee74","repo":"vitessio/vitess","slug":"uid-v-is-already-in-use","errorCode":null,"errorMessage":"uid %v is already in use","messagePattern":"uid (.+?) is already in use","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/shard.go","lineNumber":203,"sourceCode":"}\n\n// SourceShardAdd will add a new SourceShard inside a shard.\nfunc (wr *Wrangler) SourceShardAdd(ctx context.Context, keyspace, shard string, uid int32, skeyspace, sshard string, keyRange *topodatapb.KeyRange, tables []string) (err error) {\n\tresp, err := wr.VtctldServer().SourceShardAdd(ctx, &vtctldatapb.SourceShardAddRequest{\n\t\tKeyspace:       keyspace,\n\t\tShard:          shard,\n\t\tUid:            uid,\n\t\tSourceKeyspace: skeyspace,\n\t\tSourceShard:    sshard,\n\t\tKeyRange:       keyRange,\n\t\tTables:         tables,\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif resp.Shard == nil {\n\t\treturn fmt.Errorf(\"uid %v is already in use\", uid)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":185,"sourceCodeEnd":208,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/shard.go#L185-L208","documentation":"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.","triggerScenarios":"Calling SourceShardAdd (via `vtctldclient SourceShardAdd <keyspace/shard> <uid> <source keyspace/shard>`) with a uid already used by another SourceShard on the target shard.","commonSituations":"Scripting a MoveTables/Reshard workflow manually and reusing uid 0 twice; retrying a partially-failed command that already added the source shard.","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)."],"exampleFix":"// before\nvtctldclient SourceShardAdd commerce/0 0 customer/0\n// error: uid 0 is already in use\n// after\nvtctldclient GetShard commerce/0       # existing uid 0\nvtctldclient SourceShardAdd commerce/0 1 customer/0","handlingStrategy":"validation","validationCode":"// Before SourceShardAdd, pick an unused uid\nshardInfo, _ := vtctldclientGetShard(keyspace, shard)\nused := map[int64]bool{}\nfor _, ss := range shardInfo.SourceShards { used[ss.Uid] = true }\nif used[uid] {\n    var maxUid int64\n    for u := range used { if u > maxUid { maxUid = u } }\n    uid = maxUid + 1\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["topo","resharding","source-shard","filtered-replication"],"backgroundTag":"duplicate-identifier","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}