kv: protect Replica's lastToReplica and lastFromReplica fields with raftMu#74355
Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom Jan 10, 2022
Merged
Conversation
Member
tbg
approved these changes
Jan 3, 2022
Member
tbg
left a comment
There was a problem hiding this comment.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)
pkg/kv/kvserver/replica_raft.go, line 1286 at r1 (raw file):
// sendRaftMessage sends a Raft message. func (r *Replica) sendRaftMessage(ctx context.Context, msg raftpb.Message) {
sendRaftMessageRaftMuLocked?
pkg/kv/kvserver/replica_raft_quiesce.go, line 401 at r1 (raw file):
} func (r *Replica) quiesceAndNotifyLocked(
RaftMuLocked?
…aftMu This commit moves the Replica's lastToReplica and lastFromReplica from under the `Replica.mu` mutex to the `Replica.raftMu` mutex. These are strictly Raft-specific pieces of state, so we don't need fine-grained locking around them. As a reward, we don't need to grab the `Replica.mu` exclusively (or at all) when setting the fields in `Store.withReplicaForRequest`. The locking in `setLastReplicaDescriptors` showed up in a mutex profile under a write-heavy workload. It was responsible for **3.44%** of mutex wait time. Grabbing the mutex was probably also slowing down request processing, as the exclusive lock acquisition had to wait for read locks to be dropped.
0e3538a to
410ef29
Compare
nvb
commented
Jan 10, 2022
Contributor
Author
nvb
left a comment
There was a problem hiding this comment.
TFTR!
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @tbg)
pkg/kv/kvserver/replica_raft.go, line 1286 at r1 (raw file):
Previously, tbg (Tobias Grieger) wrote…
sendRaftMessageRaftMuLocked?
Done.
pkg/kv/kvserver/replica_raft_quiesce.go, line 401 at r1 (raw file):
Previously, tbg (Tobias Grieger) wrote…
RaftMuLocked?
Done.
Contributor
Author
|
bors r+ |
Contributor
|
Build succeeded: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit moves the Replica's lastToReplica and lastFromReplica from
under the
Replica.mumutex to theReplica.raftMumutex. These arestrictly Raft-specific pieces of state, so we don't need fine-grained
locking around them. As a reward, we don't need to grab the
Replica.muexclusively (or at all) when setting the fields in
Store.withReplicaForRequest.The locking in
setLastReplicaDescriptorsshowed up in a mutex profileunder a write-heavy workload. It was responsible for 3.44% of mutex
wait time. Grabbing the mutex was probably also slowing down request
processing, as the exclusive lock acquisition had to wait for read locks
to be dropped.