22#include "data/Types.hpp"
23#include "util/prometheus/Counter.hpp"
24#include "util/prometheus/Label.hpp"
25#include "util/prometheus/Prometheus.hpp"
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/basics/hardened_hash.h>
31#include <condition_variable>
37#include <shared_mutex>
38#include <unordered_set>
54 "ledger_cache_counter_total_number",
56 "LedgerCache statistics"
59 "ledger_cache_counter_total_number",
65 "ledger_cache_counter_total_number",
70 "ledger_cache_counter_total_number",
74 std::map<ripple::uint256, CacheEntry> map_;
76 mutable std::shared_mutex mtx_;
77 std::condition_variable_any cv_;
78 uint32_t latestSeq_ = 0;
79 std::atomic_bool full_ =
false;
80 std::atomic_bool disabled_ =
false;
83 std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_;
94 update(std::vector<LedgerObject>
const& objs, uint32_t seq,
bool isBackground =
false);
104 get(ripple::uint256
const& key, uint32_t seq)
const;
115 std::optional<LedgerObject>
116 getSuccessor(ripple::uint256
const& key, uint32_t seq)
const;
127 std::optional<LedgerObject>
static util::prometheus::CounterInt & counterInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based counter metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:194
Cache for an entire ledger.
Definition LedgerCache.hpp:46
float getObjectHitRate() const
Definition LedgerCache.cpp:179
bool isDisabled() const
Definition LedgerCache.cpp:149
bool isFull() const
Definition LedgerCache.cpp:166
void update(std::vector< LedgerObject > const &objs, uint32_t seq, bool isBackground=false)
Update the cache with new ledger objects.
Definition LedgerCache.cpp:55
std::optional< LedgerObject > getSuccessor(ripple::uint256 const &key, uint32_t seq) const
Gets a cached successor.
Definition LedgerCache.cpp:91
void setDisabled()
Disables the cache.
Definition LedgerCache.cpp:143
std::optional< Blob > get(ripple::uint256 const &key, uint32_t seq) const
Fetch a cached object by its key and sequence number.
Definition LedgerCache.cpp:124
uint32_t latestLedgerSequence() const
Definition LedgerCache.cpp:37
size_t size() const
Definition LedgerCache.cpp:172
float getSuccessorHitRate() const
Definition LedgerCache.cpp:187
void waitUntilCacheContainsSeq(uint32_t seq)
Waits until the cache contains a specific sequence.
Definition LedgerCache.cpp:44
void setFull()
Sets the full flag to true.
Definition LedgerCache.cpp:155
std::optional< LedgerObject > getPredecessor(ripple::uint256 const &key, uint32_t seq) const
Gets a cached predcessor.
Definition LedgerCache.cpp:108
Class representing a collection of Prometheus labels.
Definition Label.hpp:59
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70