22#include "data/LedgerCacheInterface.hpp"
23#include "data/Types.hpp"
24#include "etl/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>
41#include <unordered_set>
57 using CacheMap = std::map<ripple::uint256, CacheEntry>;
62 "ledger_cache_counter_total_number",
64 "LedgerCache statistics"
67 "ledger_cache_counter_total_number",
68 util::prometheus::Labels({{
"type",
"cache_hit"}, {
"fetch",
"ledger_objects"}})
73 "ledger_cache_counter_total_number",
74 util::prometheus::Labels({{
"type",
"request"}, {
"fetch",
"successor_key"}}),
78 "ledger_cache_counter_total_number",
79 util::prometheus::Labels({{
"type",
"cache_hit"}, {
"fetch",
"successor_key"}})
85 mutable std::shared_mutex mtx_;
86 std::condition_variable_any cv_;
87 uint32_t latestSeq_ = 0;
90 util::prometheus::Labels{},
91 "Whether ledger cache full or not"
94 "ledger_cache_disabled",
95 util::prometheus::Labels{},
96 "Whether ledger cache is disabled or not"
100 std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_;
104 update(std::vector<LedgerObject>
const& objs, uint32_t seq,
bool isBackground)
override;
107 update(std::vector<etl::model::Object>
const& objs, uint32_t seq)
override;
110 get(ripple::uint256
const& key, uint32_t seq)
const override;
113 getDeleted(ripple::uint256
const& key, uint32_t seq)
const override;
115 std::optional<LedgerObject>
116 getSuccessor(ripple::uint256
const& key, uint32_t seq)
const override;
118 std::optional<LedgerObject>
119 getPredecessor(ripple::uint256
const& key, uint32_t seq)
const override;
137 size()
const override;
148 std::expected<void, std::string>
149 saveToFile(std::string
const& path)
const override;
151 std::expected<void, std::string>
152 loadFromFile(std::string
const& path, uint32_t minLatestSequence)
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:200
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:194
Cache for an entire ledger.
Definition LedgerCache.hpp:49
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:167
bool isDisabled() const override
Definition LedgerCache.cpp:215
void setDisabled() override
Disables the cache.
Definition LedgerCache.cpp:209
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:186
uint32_t latestLedgerSequence() const override
Definition LedgerCache.cpp:44
std::optional< LedgerObject > getPredecessor(ripple::uint256 const &key, uint32_t seq) const override
Gets a cached predcessor.
Definition LedgerCache.cpp:151
std::expected< void, std::string > saveToFile(std::string const &path) const override
Save the cache to file.
Definition LedgerCache.cpp:261
std::optional< LedgerObject > getSuccessor(ripple::uint256 const &key, uint32_t seq) const override
Gets a cached successor.
Definition LedgerCache.cpp:134
float getSuccessorHitRate() const override
Definition LedgerCache.cpp:253
void update(std::vector< LedgerObject > const &objs, uint32_t seq, bool isBackground) override
Update the cache with new ledger objects.
Definition LedgerCache.cpp:62
void waitUntilCacheContainsSeq(uint32_t seq) override
Waits until the cache contains a specific sequence.
Definition LedgerCache.cpp:51
std::expected< void, std::string > loadFromFile(std::string const &path, uint32_t minLatestSequence) override
Load the cache from file.
Definition LedgerCache.cpp:274
bool isFull() const override
Definition LedgerCache.cpp:232
float getObjectHitRate() const override
Definition LedgerCache.cpp:245
void setFull() override
Sets the full flag to true.
Definition LedgerCache.cpp:221
size_t size() const override
Definition LedgerCache.cpp:238
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
An entry of the cache.
Definition LedgerCache.hpp:52