Skip to content

Commit

Permalink
remove outdated log entry cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yawzhang committed Nov 11, 2024
1 parent eaaa5dc commit d10b519
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/replication/log_store/home_raft_log_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d10b519

Please sign in to comment.