Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions go/vt/vtorc/logic/tablet_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,20 @@ func getLockAction(analysedInstance string, code inst.AnalysisCode) string {
}

// LockShard locks the keyspace-shard preventing others from performing conflicting actions.
func LockShard(ctx context.Context, tabletAlias string, lockAction string) (context.Context, func(*error), error) {
if tabletAlias == "" {
return nil, nil, errors.New("can't lock shard: instance is unspecified")
func LockShard(ctx context.Context, keyspace, shard, lockAction string) (context.Context, func(*error), error) {
if keyspace == "" {
return nil, nil, errors.New("can't lock shard: keyspace is unspecified")
}
if shard == "" {
return nil, nil, errors.New("can't lock shard: shard name is unspecified")
}
val := atomic.LoadInt32(&hasReceivedSIGTERM)
if val > 0 {
return nil, nil, errors.New("can't lock shard: SIGTERM received")
}

tablet, err := inst.ReadTablet(tabletAlias)
if err != nil {
return nil, nil, err
}

atomic.AddInt32(&shardsLockCounter, 1)
ctx, unlock, err := ts.TryLockShard(ctx, tablet.Keyspace, tablet.Shard, lockAction)
ctx, unlock, err := ts.TryLockShard(ctx, keyspace, shard, lockAction)
if err != nil {
atomic.AddInt32(&shardsLockCounter, -1)
return nil, nil, err
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtorc/logic/topology_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ func executeCheckAndRecoverFunction(analysisEntry *inst.ReplicationAnalysis) (er
}

// We lock the shard here and then refresh the tablets information
ctx, unlock, err := LockShard(context.Background(), analysisEntry.AnalyzedInstanceAlias, getLockAction(analysisEntry.AnalyzedInstanceAlias, analysisEntry.Analysis))
ctx, unlock, err := LockShard(context.Background(), analysisEntry.AnalyzedKeyspace, analysisEntry.AnalyzedShard,
getLockAction(analysisEntry.AnalyzedInstanceAlias, analysisEntry.Analysis),
)
if err != nil {
logger.Errorf("Failed to lock shard, aborting recovery: %v", err)
return err
Expand Down
Loading