Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv: grab raftMu during no-op writes with local gossip triggers #68045

Merged
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
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_application_state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ func (sm *replicaStateMachine) ApplySideEffects(
if cmd.IsLocal() {
// Handle the LocalResult.
if cmd.localResult != nil {
sm.r.handleReadWriteLocalEvalResult(ctx, *cmd.localResult)
sm.r.handleReadWriteLocalEvalResult(ctx, *cmd.localResult, true /* raftMuHeld */)
}

rejected := cmd.Rejected()
Expand Down
18 changes: 17 additions & 1 deletion pkg/kv/kvserver/replica_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ func addSSTablePreApply(
return copied
}

func (r *Replica) handleReadWriteLocalEvalResult(ctx context.Context, lResult result.LocalResult) {
func (r *Replica) handleReadWriteLocalEvalResult(
ctx context.Context, lResult result.LocalResult, raftMuHeld bool,
) {
// Fields for which no action is taken in this method are zeroed so that
// they don't trigger an assertion at the end of the method (which checks
// that all fields were handled).
Expand Down Expand Up @@ -707,21 +709,35 @@ func (r *Replica) handleReadWriteLocalEvalResult(ctx context.Context, lResult re
lResult.MaybeAddToSplitQueue = false
}

// The following three triggers require the raftMu to be held. If a
// trigger is present, acquire the mutex if it is not held already.
maybeAcquireRaftMu := func() func() {
if raftMuHeld {
return func() {}
}
raftMuHeld = true
r.raftMu.Lock()
return r.raftMu.Unlock
}

if lResult.MaybeGossipSystemConfig {
defer maybeAcquireRaftMu()()
if err := r.MaybeGossipSystemConfigRaftMuLocked(ctx); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, sprinkle raftMu.AssertHeld() into the three methods with the RaftMuLocked suffix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already there. That's the cause of the test flakiness 😃

log.Errorf(ctx, "%v", err)
}
lResult.MaybeGossipSystemConfig = false
}

if lResult.MaybeGossipSystemConfigIfHaveFailure {
defer maybeAcquireRaftMu()()
if err := r.MaybeGossipSystemConfigIfHaveFailureRaftMuLocked(ctx); err != nil {
log.Errorf(ctx, "%v", err)
}
lResult.MaybeGossipSystemConfigIfHaveFailure = false
}

if lResult.MaybeGossipNodeLiveness != nil {
defer maybeAcquireRaftMu()()
if err := r.MaybeGossipNodeLivenessRaftMuLocked(ctx, *lResult.MaybeGossipNodeLiveness); err != nil {
log.Errorf(ctx, "%v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *Replica) evalAndPropose(
if proposal.command == nil {
intents := proposal.Local.DetachEncounteredIntents()
endTxns := proposal.Local.DetachEndTxns(pErr != nil /* alwaysOnly */)
r.handleReadWriteLocalEvalResult(ctx, *proposal.Local)
r.handleReadWriteLocalEvalResult(ctx, *proposal.Local, false /* raftMuHeld */)

pr := proposalResult{
Reply: proposal.Local.Reply,
Expand Down