{"record":{"id":"b1cca7823ef2ee5a","repo":"vitessio/vitess","slug":"shard-v-v-already-has-sourceshards-not-overwrit","errorCode":null,"errorMessage":"shard %v/%v already has SourceShards, not overwriting them (full record: %v)","messagePattern":"shard (.+?)/(.+?) already has SourceShards, not overwriting them \\(full record: (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/split.go","lineNumber":70,"sourceCode":"\t// So iterating over the sourceTablets map would be a bad idea.\n\tsourceShards := make([]*topodatapb.Shard_SourceShard, len(sourceTablets))\n\tfor i, alias := range sources {\n\t\tti := sourceTablets[topoproto.TabletAliasString(alias)]\n\t\tsourceShards[i] = &topodatapb.Shard_SourceShard{\n\t\t\tUid:      int32(i),\n\t\t\tKeyspace: ti.Keyspace,\n\t\t\tShard:    ti.Shard,\n\t\t\tKeyRange: ti.KeyRange,\n\t\t\tTables:   tables,\n\t\t}\n\t}\n\n\t// Update the shard with the new source shards.\n\t_, err = wr.ts.UpdateShardFields(ctx, keyspace, shard, func(si *topo.ShardInfo) error {\n\t\t// If the shard already has sources, maybe it's already been restored,\n\t\t// so let's be safe and abort right here.\n\t\tif len(si.SourceShards) > 0 {\n\t\t\treturn fmt.Errorf(\"shard %v/%v already has SourceShards, not overwriting them (full record: %v)\", keyspace, shard, si.Shard)\n\t\t}\n\n\t\tsi.SourceShards = sourceShards\n\t\treturn nil\n\t})\n\treturn err\n}\n\n// WaitForFilteredReplication will wait until the Filtered Replication process has finished.\nfunc (wr *Wrangler) WaitForFilteredReplication(ctx context.Context, keyspace, shard string, maxDelay time.Duration) error {\n\tshardInfo, err := wr.TopoServer().GetShard(ctx, keyspace, shard)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(shardInfo.SourceShards) == 0 {\n\t\treturn fmt.Errorf(\"shard %v/%v has no source shard\", keyspace, shard)\n\t}\n\tif !shardInfo.HasPrimary() {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/split.go#L52-L88","documentation":"This guard in split.go (used by restore-style workflows such as InitShardPrimary flows in legacy ReshardRestoreData) refuses to overwrite existing SourceShards on a shard. If the shard already has SourceShards, it may already have been restored, so overwriting could corrupt the replication configuration.","triggerScenarios":"Running a legacy split/restore workflow (SplitClone restore path) against a shard that already has filtered replication sources configured — commonly because the restore was partially or fully run before.","commonSituations":"Re-running a failed reshard restore without cleaning the destination shard's SourceShards; pointing the restore at an already-served shard by mistake.","solutions":["Inspect the shard record (`vtctldclient GetShard`) to confirm the existing SourceShards are from a prior successful restore; if so, the restore already happened — skip it.","If the existing SourceShards are stale leftovers from a failed run, remove them (SourceShardDelete for each uid) and re-run the restore.","Verify you are targeting the correct destination keyspace/shard."],"exampleFix":"// before\nvtctldclient SourceShardDelete commerce/0 0   # remove stale entry\nvtctldclient GetShard commerce/0              # verify source_shards: []\n// then re-run the restore/split workflow","handlingStrategy":"validation","validationCode":"// Before running a restore/split workflow, verify destination has no SourceShards\nshardInfo, _ := vtctldclientGetShard(dstKeyspace, dstShard)\nif len(shardInfo.SourceShards) > 0 {\n    fmt.Printf(\"destination %s/%s already has %d SourceShards; restore likely already ran\\n\",\n        dstKeyspace, dstShard, len(shardInfo.SourceShards))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify destination shard record is clean before starting restores","Don't re-run failed restores without checking what state was left behind","Target the correct destination keyspace/shard — double-check CLI args"],"tags":["topo","resharding","source-shard","restore","safety-guard"],"backgroundTag":"shard-already-configured","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}