disable cache when CacheLoadStyle::NONE (#152)

This commit is contained in:
Nathan Nichols
2022-05-15 19:29:05 -05:00
committed by GitHub
parent e7204a513a
commit 3f47b85e3b
3 changed files with 18 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
#include <backend/SimpleCache.h> #include <backend/SimpleCache.h>
namespace Backend { namespace Backend {
uint32_t uint32_t
SimpleCache::latestLedgerSequence() const SimpleCache::latestLedgerSequence() const
{ {
@@ -13,6 +14,9 @@ SimpleCache::update(
uint32_t seq, uint32_t seq,
bool isBackground) bool isBackground)
{ {
if (disabled_)
return;
{ {
std::unique_lock lck{mtx_}; std::unique_lock lck{mtx_};
if (seq > latestSeq_) if (seq > latestSeq_)
@@ -82,9 +86,18 @@ SimpleCache::get(ripple::uint256 const& key, uint32_t seq) const
return {e->second.blob}; return {e->second.blob};
} }
void
SimpleCache::setDisabled()
{
disabled_ = true;
}
void void
SimpleCache::setFull() SimpleCache::setFull()
{ {
if (disabled_)
return;
full_ = true; full_ = true;
std::unique_lock lck{mtx_}; std::unique_lock lck{mtx_};
deletes_.clear(); deletes_.clear();

View File

@@ -21,6 +21,7 @@ class SimpleCache
mutable std::shared_mutex mtx_; mutable std::shared_mutex mtx_;
uint32_t latestSeq_ = 0; uint32_t latestSeq_ = 0;
std::atomic_bool full_ = false; std::atomic_bool full_ = false;
std::atomic_bool disabled_ = false;
// temporary set to prevent background thread from writing already deleted // temporary set to prevent background thread from writing already deleted
// data. not used when cache is full // data. not used when cache is full
std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_; std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_;
@@ -45,6 +46,9 @@ public:
std::optional<LedgerObject> std::optional<LedgerObject>
getPredecessor(ripple::uint256 const& key, uint32_t seq) const; getPredecessor(ripple::uint256 const& key, uint32_t seq) const;
void
setDisabled();
void void
setFull(); setFull();

View File

@@ -894,6 +894,7 @@ ReportingETL::loadCache(uint32_t seq)
{ {
if (cacheLoadStyle_ == CacheLoadStyle::NOT_AT_ALL) if (cacheLoadStyle_ == CacheLoadStyle::NOT_AT_ALL)
{ {
backend_->cache().setDisabled();
BOOST_LOG_TRIVIAL(warning) << "Cache is disabled. Not loading"; BOOST_LOG_TRIVIAL(warning) << "Cache is disabled. Not loading";
return; return;
} }