diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index 3aed26a5d16..953651f69a8 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -707,13 +707,6 @@ func (tm *TabletManager) setReplicationSourceRepairReplication(ctx context.Conte return err } - ctx, unlock, lockErr := tm.TopoServer.LockShard(ctx, parent.Tablet.GetKeyspace(), parent.Tablet.GetShard(), fmt.Sprintf("repairReplication to %v as parent)", topoproto.TabletAliasString(parentAlias))) - if lockErr != nil { - return lockErr - } - - defer unlock(&err) - currentPrimary, err := tm.TopoServer.GetTablet(ctx, parentAlias) if err != nil { return vterrors.Wrapf(err, "cannot read primary tablet %v", parentAlias) @@ -736,6 +729,13 @@ func (tm *TabletManager) setReplicationSourceRepairReplication(ctx context.Conte return err } + ctx, unlock, lockErr := tm.TopoServer.LockShard(ctx, parent.Tablet.GetKeyspace(), parent.Tablet.GetShard(), fmt.Sprintf("repairReplication to %v as parent)", topoproto.TabletAliasString(parentAlias))) + if lockErr != nil { + return lockErr + } + + defer unlock(&err) + return tm.setReplicationSourceLocked(ctx, parentAlias, timeCreatedNS, waitPosition, forceStartReplication, semiSyncAction) }