{"record":{"id":"5280dfeae9653127","repo":"vitessio/vitess","slug":"w-uid-v-is-already-in-use","errorCode":null,"errorMessage":"%w: uid %v is already in use","messagePattern":"%w: uid (.+?) is already in use","errorType":"exception","errorClass":"topo.NewError(topo.NoUpdateNeeded)","httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":4357,"sourceCode":"\tspan.Annotate(\"uid\", req.Uid)\n\tspan.Annotate(\"source_keyspace\", req.SourceKeyspace)\n\tspan.Annotate(\"source_shard\", req.SourceShard)\n\tspan.Annotate(\"keyrange\", key.KeyRangeString(req.KeyRange))\n\tspan.Annotate(\"tables\", strings.Join(req.Tables, \",\"))\n\n\tvar si *topo.ShardInfo\n\n\tctx, unlock, lockErr := s.ts.LockKeyspace(ctx, req.Keyspace, fmt.Sprintf(\"SourceShardAdd(%v)\", req.Uid))\n\tif lockErr != nil {\n\t\terr = lockErr\n\t\treturn nil, err\n\t}\n\tdefer unlock(&err)\n\n\tsi, err = s.ts.UpdateShardFields(ctx, req.Keyspace, req.Shard, func(si *topo.ShardInfo) error {\n\t\tfor _, ss := range si.SourceShards {\n\t\t\tif ss.Uid == req.Uid {\n\t\t\t\treturn fmt.Errorf(\"%w: uid %v is already in use\", topo.NewError(topo.NoUpdateNeeded, fmt.Sprintf(\"%s/%s\", req.Keyspace, req.Shard)), req.Uid)\n\t\t\t}\n\t\t}\n\n\t\tsi.SourceShards = append(si.SourceShards, &topodatapb.Shard_SourceShard{\n\t\t\tKeyspace: req.SourceKeyspace,\n\t\t\tShard:    req.SourceShard,\n\t\t\tUid:      req.Uid,\n\t\t\tKeyRange: req.KeyRange,\n\t\t\tTables:   req.Tables,\n\t\t})\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresp = &vtctldatapb.SourceShardAddResponse{}\n\tswitch si {","sourceCodeStart":4339,"sourceCodeEnd":4375,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L4339-L4375","documentation":"Returned by AddShardSourceShard (vreplication source registration) when the requested UID already exists among the shard's SourceShards. It is wrapped in a topo.NoUpdateNeeded error so the shard's version is not bumped. Each SourceShard entry needs a unique UID for the filtered replication pipeline.","triggerScenarios":"Calling `vtctldclient AddShardSourceShard` with a `--uid` value that collides with an existing SourceShard on the target shard.","commonSituations":"Re-running a reshard/migration setup script without cleaning up previous SourceShards; picking UIDs manually instead of tracking existing ones; resharding workflow partially completed earlier.","solutions":["List existing SourceShards (`vtctldclient GetShard <keyspace/shard>`) and pick a free UID","Remove the stale SourceShard with RemoveShardSourceShard before re-adding","Re-use the existing SourceShard if it already has the desired configuration instead of adding a duplicate"],"exampleFix":"// before\nvtctldclient AddShardSourceShard merchant/0 --uid 1 --source merchantcopy/0  # uid 1 already in use\n// after\nvtctldclient AddShardSourceShard merchant/0 --uid 2 --source merchantcopy/0  # free uid","handlingStrategy":"validation","validationCode":"shard, _ := topoServer.GetShard(ctx, keyspace, shardName)\nuids := map[uint32]bool{}\nfor _, ss := range shard.SourceShards { uids[ss.Uid] = true }\nif uids[requestedUID] { /* pick another uid or remove existing first */ }","typeGuard":null,"tryCatchPattern":"try {\n  client.addShardSourceShard(keyspace, shard, sourceKeyspace, sourceShard, uid)\n} catch (e) {\n  if (String(e).includes('is already in use')) {\n    existing = getExistingSourceShard(uid) // reuse or remove first\n  } else { throw e }\n}","preventionTips":["Track SourceShard UIDs centrally in migration tooling instead of hardcoding","Read the shard's existing SourceShards before choosing a UID","Make reshard setup scripts idempotent — check before add","Use distinct UID ranges per migration to avoid collisions"],"tags":["vreplication","shard","resharding","topo"],"backgroundTag":"duplicate-identifier","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}