diff --git a/src/lib/replication/log_store/home_raft_log_store.cpp b/src/lib/replication/log_store/home_raft_log_store.cpp index 144f2c01b..293494274 100644 --- a/src/lib/replication/log_store/home_raft_log_store.cpp +++ b/src/lib/replication/log_store/home_raft_log_store.cpp @@ -189,6 +189,13 @@ void HomeRaftLogStore::write_at(ulong index, nuraft::ptr< nuraft::log_entry >& e { std::unique_lock lk(m_mutex); m_log_entry_cache[position_in_cache] = std::make_pair(index, entry); + + // remove all cached entries after this index + for (size_t i{0}; i < m_log_entry_cache.size(); ++i) { + if (m_log_entry_cache[i].first > index) { + m_log_entry_cache[i] = std::make_pair(0, nullptr); + } + } } // flushing the log before returning to ensure new(over-written) log is persisted to disk.