Skip to content

Commit

Permalink
add shard lock check
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjinx committed Oct 17, 2023
1 parent b94f9b7 commit 0a34bf7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions go/vt/vttablet/tabletmanager/rpc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/topo"

"context"

Expand Down Expand Up @@ -703,13 +704,17 @@ 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 {
log.Warningf("slack: failed to lock the shard with the error: %v", lockErr)
return lockErr
}
if err = topo.CheckShardLocked(ctx, parent.Tablet.GetKeyspace(), parent.Tablet.GetShard()); err != nil {
var unlock func(*error)
ctx, unlock, err = tm.TopoServer.LockShard(ctx, parent.Tablet.GetKeyspace(), parent.Tablet.GetShard(), fmt.Sprintf("repairReplication to %v as parent)", topoproto.TabletAliasString(parentAlias)))

if err != nil {
log.Warningf("slack: failed to lock the shard with the error: %v", err)
return err
}

defer unlock(&err)
defer unlock(&err)
}

return tm.setReplicationSourceLocked(ctx, parentAlias, timeCreatedNS, waitPosition, forceStartReplication, SemiSyncActionNone)
}
Expand Down

0 comments on commit 0a34bf7

Please sign in to comment.