Skip to content

Commit a93efa2

Browse files
committed
++ cache row span
1 parent 8aa57bb commit a93efa2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

storage/cacheRowSpan.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <algorithm>
2828

29+
#include "fragmentationCache/timevalUtils.hpp"
30+
2931
namespace ipxp {
3032

3133
CacheRowSpan::CacheRowSpan(FlowRecord** begin, size_t count) noexcept
@@ -45,6 +47,10 @@ std::optional<size_t> CacheRowSpan::find_by_hash(uint64_t hash) const noexcept
4547

4648
void CacheRowSpan::advance_flow_to(size_t from, size_t to) noexcept
4749
{
50+
if (from < to) {
51+
std::rotate(m_begin + from, m_begin + from + 1, m_begin + to + 1);
52+
return;
53+
}
4854
std::rotate(m_begin + to, m_begin + from, m_begin + from + 1);
4955
}
5056

@@ -75,6 +81,22 @@ std::optional<size_t> CacheRowSpan::find_if_export_timeout_expired(const timeval
7581
}
7682
return it - m_begin;
7783
}
84+
85+
size_t CacheRowSpan::find_victim(const timeval& now) const noexcept
86+
{
87+
const FlowRecord** victim = const_cast<const FlowRecord**>(m_begin) + m_count - 1;
88+
auto it = std::find_if(m_begin, m_begin + m_count, [&](const FlowRecord* flow) {
89+
if (!flow->is_in_ctt) {
90+
victim = &flow;
91+
}
92+
return flow->is_waiting_for_export && now > flow->export_time;
93+
});
94+
if (it == m_begin + m_count) {
95+
return victim - const_cast<const FlowRecord**>(m_begin);
96+
}
97+
return it - m_begin;
98+
}
99+
78100
#endif /* WITH_CTT */
79101

80102
} // ipxp

storage/cacheRowSpan.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class CacheRowSpan {
7272
* \return Index of the flow record with an expired export timeout if found, std::nullopt otherwise.
7373
*/
7474
std::optional<size_t> find_if_export_timeout_expired(const timeval& now) const noexcept;
75+
76+
size_t find_victim(const timeval& now) const noexcept;
7577
#endif /* WITH_CTT */
7678
private:
7779
FlowRecord** m_begin;

0 commit comments

Comments
 (0)