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 "util/Assert.hpp"
30#include "util/async/context/BasicExecutionContext.hpp"
31#include "util/log/Logger.hpp"
48template <
typename ExecutionContextType = util::async::CoroExecutionContext>
53 std::shared_ptr<BackendInterface> backend_;
54 std::reference_wrapper<data::LedgerCacheInterface> cache_;
57 ExecutionContextType ctx_;
58 std::unique_ptr<CacheLoaderType> loader_;
70 std::shared_ptr<BackendInterface>
const& backend,
88 ASSERT(not cache_.get().isFull(),
"Cache must not be full. seq = {}", seq);
91 cache_.get().setDisabled();
92 LOG(log_.
warn()) <<
"Cache is disabled. Not loading";
96 std::shared_ptr<impl::BaseCursorProvider> provider;
98 LOG(log_.
info()) <<
"Loading cache with cursor from num_cursors_from_diff="
102 LOG(log_.
info()) <<
"Loading cache with cursor from num_cursors_from_account="
104 provider = std::make_shared<impl::CursorFromAccountProvider>(
108 LOG(log_.
info()) <<
"Loading cache with cursor from num_diffs=" << settings_.
numCacheDiffs;
109 provider = std::make_shared<impl::CursorFromFixDiffNumProvider>(backend_, settings_.
numCacheDiffs);
112 loader_ = std::make_unique<CacheLoaderType>(
119 provider->getCursors(seq)
124 ASSERT(cache_.get().isFull(),
"Cache must be full after sync load. seq = {}", seq);
134 if (loader_ !=
nullptr)
144 if (loader_ !=
nullptr)
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:38
Cache loading interface.
Definition CacheLoader.hpp:49
void stop() noexcept
Requests the loader to stop asap.
Definition CacheLoader.hpp:132
void wait() noexcept
Waits for the loader to finish background work.
Definition CacheLoader.hpp:142
CacheLoader(util::config::ClioConfigDefinition const &config, std::shared_ptr< BackendInterface > const &backend, data::LedgerCacheInterface &cache)
Construct a new Cache Loader object.
Definition CacheLoader.hpp:68
void load(uint32_t const seq)
Load the cache for the given sequence number.
Definition CacheLoader.hpp:86
Definition CacheLoader.hpp:49
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
Pump warn(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::WRN severity.
Definition Logger.cpp:224
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:219
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:37
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
bool isDisabled() const
Definition CacheLoaderSettings.cpp:45
bool isSync() const
Definition CacheLoaderSettings.cpp:33
size_t numCacheMarkers
Definition CacheLoaderSettings.hpp:36
size_t numCacheCursorsFromAccount
Definition CacheLoaderSettings.hpp:40
size_t cachePageFetchSize
Definition CacheLoaderSettings.hpp:37
size_t numCacheDiffs
Definition CacheLoaderSettings.hpp:35
size_t numCacheCursorsFromDiff
Definition CacheLoaderSettings.hpp:39