Skip to content

Commit

Permalink
r/consensus: do not hold an oplock when prefix truncating managers
Browse files Browse the repository at this point in the history
When prefix truncating configuration manager and offset translator the
main raft operation mutex doesn't have to be held. Prefix truncation
only mutates the state that is no longer changed by any other operation
than persisting a snapshot. It is enough to make the operation mutually
exclusive with other snapshot related operations.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed May 22, 2023
1 parent 8b21874 commit 54fc7cd
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2258,16 +2258,18 @@ ss::future<> consensus::write_snapshot(write_snapshot_cfg cfg) {
co_await _log.truncate_prefix(storage::truncate_prefix_config(
model::next_offset(last_included_index), _scheduling.default_iopc));

co_await _op_lock.with([this, last_included_index] {
return _configuration_manager.prefix_truncate(last_included_index)
.then([this, last_included_index] {
return _offset_translator.prefix_truncate(last_included_index);
})
.then([this, last_included_index] {
// when log was prefix truncate flushed offset should be
// equal to at least last snapshot index
_flushed_offset = std::max(last_included_index, _flushed_offset);
});
/*
* We do not need to keep an oplock when updating the flushed offset here as
* it is only moved forward so there is no risk of moving the flushed offset
* back, also there is no risk incorrectly marking dirty batches flushed as
* the offset will be at most equal to log start offset
*/
_flushed_offset = std::max(last_included_index, _flushed_offset);

co_await _snapshot_lock.with([this, last_included_index]() mutable {
return ss::when_all_succeed(
_configuration_manager.prefix_truncate(last_included_index),
_offset_translator.prefix_truncate(last_included_index));
});
}

Expand Down

0 comments on commit 54fc7cd

Please sign in to comment.