vitessio/vitess · error

target shard %v is in serving state

Error message

target shard %v is in serving state

What it means

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.

Source

Thrown at go/vt/vtctl/workflow/resharder.go:115

			return nil, fmt.Errorf("source shard %v is not in serving state", shard)
		}
		rs.sourceShards = append(rs.sourceShards, si)
		primary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)
		if err != nil {
			return nil, vterrors.Wrapf(err, "GetTablet(%s) failed", si.PrimaryAlias)
		}
		rs.sourcePrimaries[si.ShardName()] = primary
	}
	for _, shard := range targets {
		si, err := s.ts.GetShard(ctx, keyspace, shard)
		if err != nil {
			return nil, vterrors.Wrapf(err, "GetShard(%s) failed", shard)
		}
		if si.PrimaryAlias == nil {
			return nil, fmt.Errorf("target shard %v has no primary tablet", shard)
		}
		if si.IsPrimaryServing {
			return nil, fmt.Errorf("target shard %v is in serving state", shard)
		}
		rs.targetShards = append(rs.targetShards, si)
		primary, err := s.ts.GetTablet(ctx, si.PrimaryAlias)
		if err != nil {
			return nil, vterrors.Wrapf(err, "GetTablet(%s) failed", si.PrimaryAlias)
		}
		rs.targetPrimaries[si.ShardName()] = primary
	}
	if err := topotools.ValidateForReshard(rs.sourceShards, rs.targetShards); err != nil {
		return nil, vterrors.Wrap(err, "ValidateForReshard")
	}
	if err := rs.validateTargets(ctx); err != nil {
		return nil, vterrors.Wrap(err, "validateTargets")
	}

	vschema, err := s.ts.GetVSchema(ctx, keyspace)
	if err != nil {
		return nil, vterrors.Wrap(err, "GetVSchema")

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Remove serving state from the target shards (`vtctl SetShardIsPrimaryServing <keyspace>/<shard> false` or TabletReserveForReshard flow)
  2. Choose correct, non-serving target shards for the reshard
  3. If a previous reshard completed, do not reuse its target shards; create new empty target shards

Example fix

// before (shard 40- already serving)
Reshard --source-shards=0- --target-shards=0-40,40-
// after
vtctl SetShardIsPrimaryServing ks/40- false
Reshard --source-shards=0- --target-shards=0-40,40-
Defensive patterns

Strategy: validation

Validate before calling

for _, shard := range targetShards {
    si, err := ts.GetShard(ctx, ks, shard)
    if err != nil { return err }
    if si.IsPrimaryServing {
        return fmt.Errorf("pre-check: target shard %s is serving; unset serving before Reshard", shard)
    }
}

Try / catch

if _, err := reshardCreate(ctx, req); err != nil {
    if strings.Contains(err.Error(), "is in serving state") {
        // disable serving on target shards or pick fresh targets, then retry
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/36482bdb72502e94. Report an issue: GitHub.