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

kvserver: load committed entries after mu.Unlock() #143689

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pav-kv
Copy link
Collaborator

@pav-kv pav-kv commented Mar 29, 2025

This commit makes handleRaftReadyRaftMuLocked load the Ready.Committed entries after releasing Replica.mu, while still holding Replica.raftMu. This ensures that we don't have this IO under Replica.mu. Also, this storage interaction is placed after r.sendRaftMessages, which reduces messaging latency.

This also fixes two bugs.

  • Previously, detachRaftEntriesMonitorRaftMuLocked would be called too soon, after Ready has been generated. Instead, it should span the entire Ready handling scope, so that includes the scope of applying the entries to the state machine.
  • raftMu.bytesAccount was unsafe to refer under only Replica.mu.

Part of #140235
Related to #143652, #143615
Obsoletes #125842

@pav-kv pav-kv requested review from tbg and arulajmani March 29, 2025 13:53
@pav-kv pav-kv requested a review from a team as a code owner March 29, 2025 13:54
Copy link

blathers-crl bot commented Mar 29, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@pav-kv
Copy link
Collaborator Author

pav-kv commented Mar 29, 2025

@tbg Would you be interested in measuring the impact of this on #140235? Or give me a hint how to do it.

A conjecture is that it should have some impact because all these entries are not in unstable, so we are loading them from the entries cache best case, or from Pebble worst case. However, assuming that most of the time it's the cache, this shouldn't be much.

@pav-kv pav-kv force-pushed the load-committed-under-raft-mu branch from 64759f3 to 79a69b5 Compare March 29, 2025 14:11
@pav-kv pav-kv force-pushed the load-committed-under-raft-mu branch from 79a69b5 to 60dc887 Compare March 31, 2025 15:30
This commit makes handleRaftReadyRaftMuLocked load the Ready.Committed
entries after releasing Replica.mu, while still holding Replica.raftMu.
This ensures that we don't have this IO under Replica.mu.

This also fixes a bug. Previously, detachRaftEntriesMonitorRaftMuLocked
would be called too soon, after Ready has been generated. Instead, it
should span the entire Ready handling scope, so that includes the scope
of applying the entries to the state machine.

Epic: none
Release note: none
@pav-kv pav-kv force-pushed the load-committed-under-raft-mu branch from 60dc887 to a630095 Compare March 31, 2025 16:11

logRaftReady(ctx, rd)
outboundMsgs, msgStorageAppend = splitLocalStorageMsgs(rd.Messages)
ready = raftGroup.Ready()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are a bunch of redundant checks between HasReady() and Ready() calls. We could further squash this in the future as:

ready, hasReady = raftGroup.Ready()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants