22#include "data/LedgerCacheInterface.hpp"
23#include "data/Types.hpp"
24#include "etlng/Models.hpp"
25#include "util/prometheus/Bool.hpp"
26#include "util/prometheus/Counter.hpp"
27#include "util/prometheus/Label.hpp"
28#include "util/prometheus/Prometheus.hpp"
30#include <xrpl/basics/base_uint.h>
31#include <xrpl/basics/hardened_hash.h>
33#include <condition_variable>
39#include <shared_mutex>
40#include <unordered_set>
56 "ledger_cache_counter_total_number",
58 "LedgerCache statistics"
61 "ledger_cache_counter_total_number",
67 "ledger_cache_counter_total_number",
72 "ledger_cache_counter_total_number",
76 std::map<ripple::uint256, CacheEntry> map_;
77 std::map<ripple::uint256, CacheEntry> deleted_;
79 mutable std::shared_mutex mtx_;
80 std::condition_variable_any cv_;
81 uint32_t latestSeq_ = 0;
85 "Whether ledger cache full or not"
88 "ledger_cache_disabled",
90 "Whether ledger cache is disabled or not"
94 std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_;
98 update(std::vector<LedgerObject>
const& objs, uint32_t seq,
bool isBackground)
override;
101 update(std::vector<etlng::model::Object>
const& objs, uint32_t seq)
override;
104 get(ripple::uint256
const& key, uint32_t seq)
const override;
107 getDeleted(ripple::uint256
const& key, uint32_t seq)
const override;
109 std::optional<LedgerObject>
110 getSuccessor(ripple::uint256
const& key, uint32_t seq)
const override;
112 std::optional<LedgerObject>
113 getPredecessor(ripple::uint256
const& key, uint32_t seq)
const override;
131 size()
const override;
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
static util::prometheus::Bool boolMetric(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:188
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:38
Cache for an entire ledger.
Definition LedgerCache.hpp:48
std::optional< Blob > get(ripple::uint256 const &key, uint32_t seq) const override
Fetch a cached object by its key and sequence number.
Definition LedgerCache.cpp:161
bool isDisabled() const override
Definition LedgerCache.cpp:209
void setDisabled() override
Disables the cache.
Definition LedgerCache.cpp:203
std::optional< Blob > getDeleted(ripple::uint256 const &key, uint32_t seq) const override
Fetch a recently deleted object by its key and sequence number.
Definition LedgerCache.cpp:180
uint32_t latestLedgerSequence() const override
Definition LedgerCache.cpp:38
std::optional< LedgerObject > getPredecessor(ripple::uint256 const &key, uint32_t seq) const override
Gets a cached predcessor.
Definition LedgerCache.cpp:145
std::optional< LedgerObject > getSuccessor(ripple::uint256 const &key, uint32_t seq) const override
Gets a cached successor.
Definition LedgerCache.cpp:128
float getSuccessorHitRate() const override
Definition LedgerCache.cpp:247
void update(std::vector< LedgerObject > const &objs, uint32_t seq, bool isBackground) override
Update the cache with new ledger objects.
Definition LedgerCache.cpp:56
void waitUntilCacheContainsSeq(uint32_t seq) override
Waits until the cache contains a specific sequence.
Definition LedgerCache.cpp:45
bool isFull() const override
Definition LedgerCache.cpp:226
float getObjectHitRate() const override
Definition LedgerCache.cpp:239
void setFull() override
Sets the full flag to true.
Definition LedgerCache.cpp:215
size_t size() const override
Definition LedgerCache.cpp:232
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