Compare commits

...

2 Commits

Author SHA1 Message Date
Valentin Balaschenko
ecbd48a228 Merge branch 'develop' into vlntb/RIPD-2446-getNodeFat-error 2025-03-25 14:24:58 +00:00
Valentin Balaschenko
0299fdba45 change to warning + cosmetic changes 2025-03-20 18:18:00 +00:00
2 changed files with 18 additions and 13 deletions

View File

@@ -210,7 +210,7 @@ public:
std::vector<SweptPointersVector> allStuffToSweep(m_cache.partitions()); std::vector<SweptPointersVector> allStuffToSweep(m_cache.partitions());
clock_type::time_point const now(m_clock.now()); clock_type::time_point const now(m_clock.now());
clock_type::time_point when_expire; clock_type::time_point expire_before_this;
auto const start = std::chrono::steady_clock::now(); auto const start = std::chrono::steady_clock::now();
{ {
@@ -219,21 +219,21 @@ public:
if (m_target_size == 0 || if (m_target_size == 0 ||
(static_cast<int>(m_cache.size()) <= m_target_size)) (static_cast<int>(m_cache.size()) <= m_target_size))
{ {
when_expire = now - m_target_age; expire_before_this = now - m_target_age;
} }
else else
{ {
when_expire = expire_before_this =
now - m_target_age * m_target_size / m_cache.size(); now - m_target_age * m_target_size / m_cache.size();
clock_type::duration const minimumAge(std::chrono::seconds(1)); clock_type::duration const minimumAge(std::chrono::seconds(1));
if (when_expire > (now - minimumAge)) if (expire_before_this > (now - minimumAge))
when_expire = now - minimumAge; expire_before_this = now - minimumAge;
JLOG(m_journal.trace()) JLOG(m_journal.trace())
<< m_name << " is growing fast " << m_cache.size() << " of " << m_name << " is growing fast " << m_cache.size() << " of "
<< m_target_size << " aging at " << m_target_size << " aging at "
<< (now - when_expire).count() << " of " << (now - expire_before_this).count() << " of "
<< m_target_age.count(); << m_target_age.count();
} }
@@ -244,7 +244,7 @@ public:
for (std::size_t p = 0; p < m_cache.partitions(); ++p) for (std::size_t p = 0; p < m_cache.partitions(); ++p)
{ {
workers.push_back(sweepHelper( workers.push_back(sweepHelper(
when_expire, expire_before_this,
now, now,
m_cache.map()[p], m_cache.map()[p],
allStuffToSweep[p], allStuffToSweep[p],
@@ -653,7 +653,7 @@ private:
[[nodiscard]] std::thread [[nodiscard]] std::thread
sweepHelper( sweepHelper(
clock_type::time_point const& when_expire, clock_type::time_point const& expire_before_this,
[[maybe_unused]] clock_type::time_point const& now, [[maybe_unused]] clock_type::time_point const& now,
typename KeyValueCacheType::map_type& partition, typename KeyValueCacheType::map_type& partition,
SweptPointersVector& stuffToSweep, SweptPointersVector& stuffToSweep,
@@ -677,6 +677,8 @@ private:
// weak // weak
if (cit->second.isExpired()) if (cit->second.isExpired())
{ {
// No strong references remain, and it has expired →
// remove it
stuffToSweep.second.push_back( stuffToSweep.second.push_back(
std::move(cit->second.weak_ptr)); std::move(cit->second.weak_ptr));
++mapRemovals; ++mapRemovals;
@@ -684,15 +686,17 @@ private:
} }
else else
{ {
// Still weakly referenced but not expired → keep it
++cit; ++cit;
} }
} }
else if (cit->second.last_access <= when_expire) else if (cit->second.last_access <= expire_before_this)
{ {
// strong, expired // strong, expired
++cacheRemovals; ++cacheRemovals;
if (cit->second.ptr.use_count() == 1) if (cit->second.ptr.use_count() == 1)
{ {
// No external references exist → remove from cache
stuffToSweep.first.push_back( stuffToSweep.first.push_back(
std::move(cit->second.ptr)); std::move(cit->second.ptr));
++mapRemovals; ++mapRemovals;
@@ -700,7 +704,8 @@ private:
} }
else else
{ {
// remains weakly cached // Still in use elsewhere → demote to weak reference
// for future cleanup
cit->second.ptr.reset(); cit->second.ptr.reset();
++cit; ++cit;
} }
@@ -727,7 +732,7 @@ private:
[[nodiscard]] std::thread [[nodiscard]] std::thread
sweepHelper( sweepHelper(
clock_type::time_point const& when_expire, clock_type::time_point const& expire_before_this,
clock_type::time_point const& now, clock_type::time_point const& now,
typename KeyOnlyCacheType::map_type& partition, typename KeyOnlyCacheType::map_type& partition,
SweptPointersVector&, SweptPointersVector&,
@@ -749,7 +754,7 @@ private:
cit->second.last_access = now; cit->second.last_access = now;
++cit; ++cit;
} }
else if (cit->second.last_access <= when_expire) else if (cit->second.last_access <= expire_before_this)
{ {
cit = partition.erase(cit); cit = partition.erase(cit);
} }

View File

@@ -3377,7 +3377,7 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
if (!m->has_ledgerhash()) if (!m->has_ledgerhash())
info += ", no hash specified"; info += ", no hash specified";
JLOG(p_journal_.error()) JLOG(p_journal_.warn())
<< "processLedgerRequest: getNodeFat with nodeId " << "processLedgerRequest: getNodeFat with nodeId "
<< *shaMapNodeId << " and ledger info type " << info << *shaMapNodeId << " and ledger info type " << info
<< " throws exception: " << e.what(); << " throws exception: " << e.what();