22#include "data/BackendInterface.hpp"
23#include "data/LedgerCacheInterface.hpp"
24#include "etl/CacheLoaderSettings.hpp"
25#include "etl/impl/CacheLoader.hpp"
26#include "etl/impl/CursorFromAccountProvider.hpp"
27#include "etl/impl/CursorFromDiffProvider.hpp"
28#include "etl/impl/CursorFromFixDiffNumProvider.hpp"
29#include "etlng/CacheLoaderInterface.hpp"
30#include "util/Assert.hpp"
31#include "util/async/context/BasicExecutionContext.hpp"
32#include "util/log/Logger.hpp"
50template <
typename ExecutionContextType = util::async::CoroExecutionContext>
55 std::shared_ptr<BackendInterface> backend_;
56 std::reference_wrapper<data::LedgerCacheInterface> cache_;
59 ExecutionContextType ctx_;
60 std::unique_ptr<CacheLoaderType> loader_;
72 std::shared_ptr<BackendInterface> backend,
75 : backend_{std::move(backend)}
78 , ctx_{settings_.numThreads}
91 load(uint32_t
const seq)
override
93 ASSERT(not cache_.get().isFull(),
"Cache must not be full. seq = {}", seq);
95 if (settings_.isDisabled()) {
96 cache_.get().setDisabled();
97 LOG(log_.warn()) <<
"Cache is disabled. Not loading";
101 std::shared_ptr<impl::BaseCursorProvider> provider;
102 if (settings_.numCacheCursorsFromDiff != 0) {
103 LOG(log_.info()) <<
"Loading cache with cursor from num_cursors_from_diff="
104 << settings_.numCacheCursorsFromDiff;
105 provider = std::make_shared<impl::CursorFromDiffProvider>(backend_, settings_.numCacheCursorsFromDiff);
106 }
else if (settings_.numCacheCursorsFromAccount != 0) {
107 LOG(log_.info()) <<
"Loading cache with cursor from num_cursors_from_account="
108 << settings_.numCacheCursorsFromAccount;
109 provider = std::make_shared<impl::CursorFromAccountProvider>(
110 backend_, settings_.numCacheCursorsFromAccount, settings_.cachePageFetchSize
113 LOG(log_.info()) <<
"Loading cache with cursor from num_diffs=" << settings_.numCacheDiffs;
114 provider = std::make_shared<impl::CursorFromFixDiffNumProvider>(backend_, settings_.numCacheDiffs);
117 loader_ = std::make_unique<CacheLoaderType>(
122 settings_.numCacheMarkers,
123 settings_.cachePageFetchSize,
124 provider->getCursors(seq)
127 if (settings_.isSync()) {
129 ASSERT(cache_.get().isFull(),
"Cache must be full after sync load. seq = {}", seq);
139 if (loader_ !=
nullptr)
149 if (loader_ !=
nullptr)
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:38
void load(uint32_t const seq) override
Load the cache for the given sequence number.
Definition CacheLoader.hpp:91
void stop() noexcept override
Requests the loader to stop asap.
Definition CacheLoader.hpp:137
void wait() noexcept override
Waits for the loader to finish background work.
Definition CacheLoader.hpp:147
CacheLoader(util::config::ClioConfigDefinition const &config, std::shared_ptr< BackendInterface > backend, data::LedgerCacheInterface &cache)
Construct a new Cache Loader object.
Definition CacheLoader.hpp:70
Definition CacheLoader.hpp:49
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:94
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:39
CacheLoaderSettings makeCacheLoaderSettings(util::config::ClioConfigDefinition const &config)
Create a CacheLoaderSettings object from a Config object.
Definition CacheLoaderSettings.cpp:51
Settings for the cache loader.
Definition CacheLoaderSettings.hpp:31
An interface for the Cache Loader.
Definition CacheLoaderInterface.hpp:29