From 443385160cbcc1e112e0d4ea64fd6c8c94827538 Mon Sep 17 00:00:00 2001 From: Michal Maslanka Date: Thu, 4 Jan 2024 09:52:11 +0100 Subject: [PATCH] c/log_eviction_stm: do not request snapshot if already progressed It is perfectly possible that the install snapshot request will reach the follower right before the `log_eviction_stm` asks for the snapshot creation. In this case an `stm_manager` would do the check and throw an exception informing that the snapshot can not be taken. In order to handle the situation gracefully added a check in log eviction stm to skip taking snapshot if start offset already progressed. Fixes: #14220 Signed-off-by: Michal Maslanka --- src/v/cluster/log_eviction_stm.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/v/cluster/log_eviction_stm.cc b/src/v/cluster/log_eviction_stm.cc index 969d5baf1f915..779463a94ccc3 100644 --- a/src/v/cluster/log_eviction_stm.cc +++ b/src/v/cluster/log_eviction_stm.cc @@ -184,13 +184,24 @@ log_eviction_stm::do_write_raft_snapshot(model::offset truncation_point) { max_collectible_offset, truncation_point); } + if (truncation_point <= _raft->last_snapshot_index()) { + vlog( + _log.trace, + "Skipping writing snapshot as Raft already progressed with the new " + "snapshot. Current raft snapshot index: {}, requested truncation " + "point: {}", + _raft->last_snapshot_index(), + truncation_point); + co_return; + } vlog( _log.debug, "Requesting raft snapshot with final offset: {}", truncation_point); auto snapshot_data = co_await _raft->stm_manager()->take_snapshot( truncation_point); - + // we need to check snapshot index again as it may already progressed after + // snapshot is taken by stm_manager if (truncation_point <= _raft->last_snapshot_index()) { vlog( _log.trace,