From 27e282119b97b2bfa4240d28251cab60fb9a2fab Mon Sep 17 00:00:00 2001 From: Xiaoxi Chen Date: Mon, 4 Nov 2024 16:02:58 +0800 Subject: [PATCH] use erase_if_equal Signed-off-by: Xiaoxi Chen --- src/lib/replication/repl_dev/raft_state_machine.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lib/replication/repl_dev/raft_state_machine.cpp b/src/lib/replication/repl_dev/raft_state_machine.cpp index f4c038a17..6541c6508 100644 --- a/src/lib/replication/repl_dev/raft_state_machine.cpp +++ b/src/lib/replication/repl_dev/raft_state_machine.cpp @@ -222,17 +222,11 @@ uint64_t RaftStateMachine::last_commit_index() { void RaftStateMachine::become_ready() { m_rd.become_ready(); } void RaftStateMachine::unlink_lsn_to_req(int64_t lsn, repl_req_ptr_t rreq) { - auto const it = m_lsn_req_map.find(lsn); // it is possible a LSN mapped to different rreq in history // due to log overwritten. Verify the rreq before removing - if (it != m_lsn_req_map.cend()) { - if (it->second == rreq) { - RD_LOG(DEBUG, "Raft channel: erase lsn {}, rreq {}", lsn, it->second->to_string()); - m_lsn_req_map.erase(lsn); - } else { - RD_LOGC("Erasing lsn {} pointing to rreq{} differnt with providing rreq {}", lsn, it->second->to_string(), - rreq->to_string()); - } + auto deleted = m_lsn_req_map.erase_if_equal(lsn, rreq); + if (deleted) { + RD_LOG(DEBUG, "Raft channel: erase lsn {}, rreq {}", lsn, it->second->to_string()); } }