Skip to content

Commit

Permalink
r/consensus: add election lock
Browse files Browse the repository at this point in the history
will be used later to guard from concurrent elections
  • Loading branch information
bashtanov committed Jul 22, 2024
1 parent f8f7561 commit a7f1d75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ ss::future<xshard_transfer_state> consensus::stop() {
co_await _append_requests_buffer.stop();
co_await _batcher.stop();

_election_lock.broken();
_op_lock.broken();
_deferred_flusher.cancel();
co_await _bg.close();
Expand Down
13 changes: 10 additions & 3 deletions src/v/raft/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,22 @@ class consensus {
/// used to wait for background ops before shutting down
ss::gate _bg;

/**
* Locks listed in the order of nestedness, election being the outermost
* and snapshot the innermost. I.e. if any of these locks are used at the
* same time, they should be acquired in the listed order and released in
* reverse order.
*/
/// guards from concurrent election where this instance is a candidate
mutex _election_lock{"consensus::election_lock"};
/// all raft operations must happen exclusively since the common case
/// is for the operation to touch the disk
mutex _op_lock{"consensus::op_lock"};
/// since snapshot state is orthogonal to raft state when writing snapshot
/// it is enough to grab the snapshot mutex, there is no need to keep
/// oplock, if the two locks are expected to be acquired at the same time
/// the snapshot lock should always be an internal (taken after the
/// _op_lock)
/// oplock
mutex _snapshot_lock{"consensus::snapshot_lock"};

/// used for notifying when commits happened to log
event_manager _event_manager;
std::unique_ptr<probe> _probe;
Expand Down

0 comments on commit a7f1d75

Please sign in to comment.