vitessio/vitess · error

some streams already exist in the target shards, please clea

Error message

some streams already exist in the target shards, please clean them up and retry the command

What it means

Before creating a Reshard workflow, wrangler checks each target shard's primary for existing rows in _vt.vreplication and fails if any exist. Pre-existing streams in the target shards would collide with the new reshard streams, so the command aborts and asks the operator to clean them up first. This prevents duplicated or conflicting vreplication state on the target.

Source

Thrown at go/vt/wrangler/resharder.go:179

	if err := rs.readRefStreams(ctx); err != nil {
		return nil, vterrors.Wrap(err, "readRefStreams")
	}
	return rs, nil
}

// validateTargets ensures that the target shards have no existing
// VReplication workflow streams as that is an invalid starting
// state for the non-serving shards involved in a Reshard.
func (rs *resharder) validateTargets(ctx context.Context) error {
	err := rs.forAll(rs.targetShards, func(target *topo.ShardInfo) error {
		targetPrimary := rs.targetPrimaries[target.ShardName()]
		query := "select 1 from _vt.vreplication where db_name=" + encodeString(targetPrimary.DbName())
		p3qr, err := rs.wr.tmc.VReplicationExec(ctx, targetPrimary.Tablet, query)
		if err != nil {
			return vterrors.Wrapf(err, "VReplicationExec(%v, %s)", targetPrimary.Tablet, query)
		}
		if len(p3qr.Rows) != 0 {
			return errors.New("some streams already exist in the target shards, please clean them up and retry the command")
		}
		return nil
	})
	return err
}

func (rs *resharder) readRefStreams(ctx context.Context) error {
	var mu sync.Mutex
	err := rs.forAll(rs.sourceShards, func(source *topo.ShardInfo) error {
		sourcePrimary := rs.sourcePrimaries[source.ShardName()]

		query := fmt.Sprintf("select workflow, source, cell, tablet_types from _vt.vreplication where db_name=%s and message != 'FROZEN'", encodeString(sourcePrimary.DbName()))
		p3qr, err := rs.wr.tmc.VReplicationExec(ctx, sourcePrimary.Tablet, query)
		if err != nil {
			return vterrors.Wrapf(err, "VReplicationExec(%v, %s)", sourcePrimary.Tablet, query)
		}
		qr := sqltypes.Proto3ToResult(p3qr)

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. List existing streams on the target primaries: SELECT id, workflow, workflow_type FROM _vt.vreplication
  2. Remove stale streams with vtctldclient Workflow --keyspace <ks> <workflow> delete or DELETE FROM _vt.vreplication WHERE ...
  3. Re-run the Reshard command after all target shards are clean

Example fix

-- on each target primary
SELECT id, workflow FROM _vt.vreplication WHERE db_name='vt_ks';
DELETE FROM _vt.vreplication WHERE id=<stale_id>;
-- then retry the reshard
Defensive patterns

Strategy: validation

Validate before calling

-- for each target shard primary, before Reshard
SELECT COUNT(*) FROM _vt.vreplication WHERE db_name='vt_<ks>';
-- must be 0

Try / catch

if err := rs.createStreams(ctx); err != nil {
	if strings.Contains(err.Error(), "streams already exist") {
		// run cleanup of target shard vreplication rows, then retry
	}
	return err
}

Prevention

When it happens

Trigger: Running Reshard against target shards whose primary tablet already has _vt.vreplication rows — e.g. from a previously cancelled/failed reshard, MoveTables into the same keyspace, or manually created streams.

Common situations: Retrying a reshard after a failed first attempt without cleanup; reusing shards that hosted earlier workflows; orphaned vreplication rows left when a workflow was dropped without stream removal.

Related errors


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