{"record":{"id":"36482bdb72502e94","repo":"vitessio/vitess","slug":"target-shard-v-is-in-serving-state","errorCode":null,"errorMessage":"target shard %v is in serving state","messagePattern":"target shard (.+?) is in serving state","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/resharder.go","lineNumber":115,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"source shard %v is not in serving state\", shard)\n\t\t}\n\t\trs.sourceShards = append(rs.sourceShards, si)\n\t\tprimary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetTablet(%s) failed\", si.PrimaryAlias)\n\t\t}\n\t\trs.sourcePrimaries[si.ShardName()] = primary\n\t}\n\tfor _, shard := range targets {\n\t\tsi, err := s.ts.GetShard(ctx, keyspace, shard)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetShard(%s) failed\", shard)\n\t\t}\n\t\tif si.PrimaryAlias == nil {\n\t\t\treturn nil, fmt.Errorf(\"target shard %v has no primary tablet\", shard)\n\t\t}\n\t\tif si.IsPrimaryServing {\n\t\t\treturn nil, fmt.Errorf(\"target shard %v is in serving state\", shard)\n\t\t}\n\t\trs.targetShards = append(rs.targetShards, si)\n\t\tprimary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Wrapf(err, \"GetTablet(%s) failed\", si.PrimaryAlias)\n\t\t}\n\t\trs.targetPrimaries[si.ShardName()] = primary\n\t}\n\tif err := topotools.ValidateForReshard(rs.sourceShards, rs.targetShards); err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"ValidateForReshard\")\n\t}\n\tif err := rs.validateTargets(ctx); err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"validateTargets\")\n\t}\n\n\tvschema, err := s.ts.GetVSchema(ctx, keyspace)\n\tif err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"GetVSchema\")","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/resharder.go#L97-L133","documentation":"For resharding, target shards must be writable-only receivers: their primary must NOT be serving. If a target shard's primary is already serving, streams could receive conflicting writes, so buildResharder rejects it with this error naming the shard.","triggerScenarios":"ReshardCreate is called while a designated target shard has IsPrimaryServing=true — e.g. re-running a Reshard whose target shards were previously serving, or accidentally targeting shards of an already-serving keyspace.","commonSituations":"Retrying a completed/aborted reshard without cleaning up; resharding from a snapshot where target shards were pre-serving; serving state not cleared after a previous workflow was cancelled.","solutions":["Remove serving state from the target shards (`vtctl SetShardIsPrimaryServing <keyspace>/<shard> false` or TabletReserveForReshard flow)","Choose correct, non-serving target shards for the reshard","If a previous reshard completed, do not reuse its target shards; create new empty target shards"],"exampleFix":"// before (shard 40- already serving)\nReshard --source-shards=0- --target-shards=0-40,40-\n// after\nvtctl SetShardIsPrimaryServing ks/40- false\nReshard --source-shards=0- --target-shards=0-40,40-","handlingStrategy":"validation","validationCode":"for _, shard := range targetShards {\n    si, err := ts.GetShard(ctx, ks, shard)\n    if err != nil { return err }\n    if si.IsPrimaryServing {\n        return fmt.Errorf(\"pre-check: target shard %s is serving; unset serving before Reshard\", shard)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, err := reshardCreate(ctx, req); err != nil {\n    if strings.Contains(err.Error(), \"is in serving state\") {\n        // disable serving on target shards or pick fresh targets, then retry\n    }\n    return err\n}","preventionTips":["Never reuse serving shards as reshard targets; create fresh empty targets","Check IsPrimaryServing on targets in the pre-flight script","Follow the documented reserve-for-reshard flow to prepare target shards"],"tags":["vitess","resharding","vreplication","shard-serving","conflict"],"backgroundTag":"target-shard-already-serving","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}