Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
TaskManager.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "etlng/ExtractorInterface.hpp"
23#include "etlng/LoaderInterface.hpp"
24#include "etlng/Models.hpp"
25#include "etlng/SchedulerInterface.hpp"
26#include "util/StrandedPriorityQueue.hpp"
27#include "util/async/AnyExecutionContext.hpp"
28#include "util/async/AnyOperation.hpp"
29#include "util/async/AnyStrand.hpp"
30#include "util/log/Logger.hpp"
31
32#include <xrpl/protocol/TxFormats.h>
33
34#include <cstddef>
35#include <functional>
36#include <vector>
37
38namespace etlng::impl {
39
42 std::reference_wrapper<SchedulerInterface> schedulers_;
43 std::reference_wrapper<ExtractorInterface> extractor_;
44 std::reference_wrapper<LoaderInterface> loader_;
45
46 std::vector<util::async::AnyOperation<void>> extractors_;
47 std::vector<util::async::AnyOperation<void>> loaders_;
48
49 util::Logger log_{"ETL"};
50
51 struct ReverseOrderComparator {
52 [[nodiscard]] bool
53 operator()(model::LedgerData const& lhs, model::LedgerData const& rhs) const noexcept
54 {
55 return lhs.seq > rhs.seq;
56 }
57 };
58
59public:
60 struct Settings {
62 size_t numLoaders;
63 };
64
65 // reverse order loading is needed (i.e. start with oldest seq in forward fill buffer)
67
70 std::reference_wrapper<SchedulerInterface> scheduler,
71 std::reference_wrapper<ExtractorInterface> extractor,
72 std::reference_wrapper<LoaderInterface> loader
73 );
74
76
77 void
78 run(Settings settings);
79
80 void
81 stop();
82
83private:
84 void
85 wait();
86
88 spawnExtractor(util::async::AnyStrand& strand, PriorityQueue& queue);
89
91 spawnLoader(PriorityQueue& queue);
92};
93
94} // namespace etlng::impl
Definition TaskManager.hpp:40
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
A wrapper for std::priority_queue that serialises operations using a strand.
Definition StrandedPriorityQueue.hpp:39
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
A type-erased operation that can be executed via AnyExecutionContext.
Definition AnyOperation.hpp:45
A type-erased execution context.
Definition AnyStrand.hpp:40
Definition TaskManager.hpp:60
size_t numLoaders
Definition TaskManager.hpp:62
size_t numExtractors
Definition TaskManager.hpp:61
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:143