{"record":{"id":"add54c8cf514a3d9","repo":"vitessio/vitess","slug":"target-shard-v-is-in-serving-state-add54c","errorCode":null,"errorMessage":"target shard %v is in serving state","messagePattern":"target shard (.+?) is in serving state","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/resharder.go","lineNumber":139,"sourceCode":"\t\t\treturn nil, vterrors.Wrapf(err, \"GetShard(%s) failed\", shard)\n\t\t}\n\t\tif !si.IsPrimaryServing {\n\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 := wr.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 := wr.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.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 := wr.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 := wr.ts.GetVSchema(ctx, keyspace)\n\tif err != nil {\n\t\treturn nil, vterrors.Wrap(err, \"GetVSchema\")","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/resharder.go#L121-L157","documentation":"Mirror of the source-shard check: reshard requires target shards to NOT be primary-serving, because a serving target would take live traffic and accept writes while VReplication is still copying data. If any target shard has IsPrimaryServing=true, Reshard fails with this error.","triggerScenarios":"Calling Reshard when a target shard (e.g. the new -80 or 80- shards in a split) already has IsPrimaryServing=true — typically because a previous reshard attempt was rolled back incorrectly, or the target shards were pre-created and accidentally enabled for serving.","commonSituations":"Re-running a reshard into shards left serving from an aborted attempt; someone toggled serving on target shards to test; automated tooling created target shards with serving enabled by default in a custom setup.","solutions":["Identify the offending target shard(s) from the error and check `vtctlclient GetShard <keyspace>/<shard>`.","Disable serving: `vtctlclient SetShardIsPrimaryServing <keyspace>/<target_shard> false`.","If the target shards hold stale state from a failed prior reshard, consider cleaning them (delete tablets/shard records) and recreating before re-running Reshard.","Re-run the Reshard command after all targets report serving=false."],"exampleFix":"// before\n$ vtctlclient GetShard commerce/-80  # IsPrimaryServing: true\n// after\n$ vtctlclient SetShardIsPrimaryServing commerce/-80 false\n$ vtctlclient Reshard commerce.reshard - -80,80-","handlingStrategy":"validation","validationCode":"for _, shard := range targetShards {\n    si, err := ts.GetShard(ctx, keyspace, shard)\n    if err != nil { return err }\n    if si.IsPrimaryServing {\n        return fmt.Errorf(\"pre-flight: target shard %s must not be serving\", shard)\n    }\n}","typeGuard":"func targetIsNotServing(si *topo.ShardInfo) bool { return !si.IsPrimaryServing }","tryCatchPattern":"err := wr.Reshard(ctx, keyspace, workflow, sources, targets, opts...)\nif err != nil && strings.Contains(err.Error(), \"is in serving state\") {\n    // disable serving on target shards, clean stale state, then retry\n    return disableTargetServingThenRetry(ctx, keyspace, targets)\n}","preventionTips":["Never enable serving on target shards until VReplication catch-up and SwitchReads/SwitchWrites","Clean up shards from aborted reshard attempts before re-running","Automate preflight checks of target shard state"],"tags":["reshard","vreplication","serving","target-shard"],"backgroundTag":"shard-not-serving","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}