Skip to content

Commit

Permalink
Merge pull request #36577 from tbg/backport19.1-36569
Browse files Browse the repository at this point in the history
backport-19.1: storage: avoid deadlock due to reentrant RLock
  • Loading branch information
petermattis authored Apr 5, 2019
2 parents 873fe38 + d74f8c8 commit 6da68d7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,15 @@ func (r *Replica) raftStatusRLocked() *raft.Status {
// State returns a copy of the internal state of the Replica, along with some
// auxiliary information.
func (r *Replica) State() storagepb.RangeInfo {
var ri storagepb.RangeInfo

// NB: this acquires an RLock(). Reentrant RLocks are deadlock prone, so do
// this first before RLocking below. Performance of this extra lock
// acquisition is not a concern.
ri.ActiveClosedTimestamp = r.maxClosed(context.Background())

r.mu.RLock()
defer r.mu.RUnlock()
var ri storagepb.RangeInfo
ri.ReplicaState = *(protoutil.Clone(&r.mu.state)).(*storagepb.ReplicaState)
ri.LastIndex = r.mu.lastIndex
ri.NumPending = uint64(len(r.mu.proposals))
Expand All @@ -893,7 +899,6 @@ func (r *Replica) State() storagepb.RangeInfo {
})
}
}
ri.ActiveClosedTimestamp = r.maxClosed(context.Background())
return ri
}

Expand Down

0 comments on commit 6da68d7

Please sign in to comment.