Skip to content

Commit

Permalink
kvserver: create method createRaftState
Browse files Browse the repository at this point in the history
Defer the release of the lock.

Part of: 105366

Release note: None
  • Loading branch information
andrewbaptist committed May 14, 2024
1 parent 0714361 commit 7c956de
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/kv/kvserver/replica_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,7 @@ func (r *Replica) handleRaftReadyRaftMuLocked(
// r.mu.lastIndexNotDurable, r.mu.lastTermNotDurable and r.mu.raftLogSize
// were updated in applySnapshot, but we also want to make sure we reflect
// these changes in the local variables we're tracking here.
r.mu.RLock()
state = logstore.RaftState{
LastIndex: r.mu.lastIndexNotDurable,
LastTerm: r.mu.lastTermNotDurable,
ByteSize: r.mu.raftLogSize,
}
r.mu.RUnlock()
state = r.createRaftState()

// We refresh pending commands after applying a snapshot because this
// replica may have been temporarily partitioned from the Raft group and
Expand Down Expand Up @@ -1179,6 +1173,16 @@ func (r *Replica) handleRaftReadyRaftMuLocked(
return stats, nil
}

func (r *Replica) createRaftState() logstore.RaftState {
r.mu.RLock()
defer r.mu.RUnlock()
return logstore.RaftState{
LastIndex: r.mu.lastIndexNotDurable,
LastTerm: r.mu.lastTermNotDurable,
ByteSize: r.mu.raftLogSize,
}
}

func (r *Replica) maybeRefreshProposals(ctx context.Context, refreshReason refreshRaftReason) {
if refreshReason != noReason {
r.mu.Lock()
Expand Down

0 comments on commit 7c956de

Please sign in to comment.