-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'XRPLF:develop' into 1219-split-metric-and-stat-analysis…
…-docs
- Loading branch information
Showing
53 changed files
with
1,041 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(clang) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=address\" linkflags=\"-fsanitize=address\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=address" | ||
CXXFLAGS="-fsanitize=address" | ||
LDFLAGS="-fsanitize=address" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(clang) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=thread\" linkflags=\"-fsanitize=thread\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=thread" | ||
CXXFLAGS="-fsanitize=thread" | ||
LDFLAGS="-fsanitize=thread" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(clang) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=undefined\" linkflags=\"-fsanitize=undefined\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=undefined" | ||
CXXFLAGS="-fsanitize=undefined" | ||
LDFLAGS="-fsanitize=undefined" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(gcc) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=address\" linkflags=\"-fsanitize=address\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=address" | ||
CXXFLAGS="-fsanitize=address" | ||
LDFLAGS="-fsanitize=address" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(gcc) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=thread\" linkflags=\"-fsanitize=thread\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=thread" | ||
CXXFLAGS="-fsanitize=thread" | ||
LDFLAGS="-fsanitize=thread" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include(gcc) | ||
|
||
[options] | ||
boost:extra_b2_flags="cxxflags=\"-fsanitize=undefined\" linkflags=\"-fsanitize=undefined\"" | ||
boost:without_stacktrace=True | ||
[env] | ||
CFLAGS="-fsanitize=undefined" | ||
CXXFLAGS="-fsanitize=undefined" | ||
LDFLAGS="-fsanitize=undefined" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of clio: https://github.com/XRPLF/clio | ||
Copyright (c) 2025, the clio developers. | ||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <optional> | ||
|
||
namespace etlng { | ||
|
||
/** | ||
* @brief The interface of a scheduler for the extraction proccess | ||
*/ | ||
struct LedgerPublisherInterface { | ||
virtual ~LedgerPublisherInterface() = default; | ||
|
||
/** | ||
* @brief Publish the ledger by its sequence number | ||
* | ||
* @param seq The sequence number of the ledger | ||
* @param maxAttempts The maximum number of attempts to publish the ledger; no limit if nullopt | ||
* @param attemptsDelay The delay between attempts | ||
*/ | ||
virtual void | ||
publish( | ||
uint32_t seq, | ||
std::optional<uint32_t> maxAttempts, | ||
std::chrono::steady_clock::duration attemptsDelay = std::chrono::seconds{1} | ||
) = 0; | ||
}; | ||
|
||
} // namespace etlng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of clio: https://github.com/XRPLF/clio | ||
Copyright (c) 2025, the clio developers. | ||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#include "etlng/impl/TaskManager.hpp" | ||
|
||
#include "etlng/ExtractorInterface.hpp" | ||
#include "etlng/LoaderInterface.hpp" | ||
#include "etlng/Models.hpp" | ||
#include "etlng/SchedulerInterface.hpp" | ||
#include "util/async/AnyExecutionContext.hpp" | ||
#include "util/async/AnyOperation.hpp" | ||
#include "util/async/AnyStrand.hpp" | ||
#include "util/log/Logger.hpp" | ||
|
||
|
||
#include <chrono> | ||
#include <cstddef> | ||
#include <functional> | ||
#include <ranges> | ||
#include <thread> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace etlng::impl { | ||
|
||
TaskManager::TaskManager( | ||
util::async::AnyExecutionContext&& ctx, | ||
std::reference_wrapper<SchedulerInterface> scheduler, | ||
std::reference_wrapper<ExtractorInterface> extractor, | ||
std::reference_wrapper<LoaderInterface> loader | ||
) | ||
: ctx_(std::move(ctx)), schedulers_(scheduler), extractor_(extractor), loader_(loader) | ||
{ | ||
} | ||
|
||
TaskManager::~TaskManager() | ||
{ | ||
stop(); | ||
} | ||
|
||
void | ||
TaskManager::run(Settings settings) | ||
{ | ||
static constexpr auto kQUEUE_SIZE_LIMIT = 2048uz; | ||
|
||
auto schedulingStrand = ctx_.makeStrand(); | ||
PriorityQueue queue(ctx_.makeStrand(), kQUEUE_SIZE_LIMIT); | ||
|
||
LOG(log_.debug()) << "Starting task manager...\n"; | ||
|
||
extractors_.reserve(settings.numExtractors); | ||
for ([[maybe_unused]] auto _ : std::views::iota(0uz, settings.numExtractors)) | ||
extractors_.push_back(spawnExtractor(schedulingStrand, queue)); | ||
|
||
loaders_.reserve(settings.numLoaders); | ||
for ([[maybe_unused]] auto _ : std::views::iota(0uz, settings.numLoaders)) | ||
loaders_.push_back(spawnLoader(queue)); | ||
|
||
wait(); | ||
LOG(log_.debug()) << "All finished in task manager..\n"; | ||
} | ||
|
||
util::async::AnyOperation<void> | ||
TaskManager::spawnExtractor(util::async::AnyStrand& strand, PriorityQueue& queue) | ||
{ | ||
// TODO: these values may be extracted to config later and/or need to be fine-tuned on a realistic system | ||
static constexpr auto kDELAY_BETWEEN_ATTEMPTS = std::chrono::milliseconds{100u}; | ||
static constexpr auto kDELAY_BETWEEN_ENQUEUE_ATTEMPTS = std::chrono::milliseconds{1u}; | ||
|
||
return strand.execute([this, &queue](auto stopRequested) { | ||
while (not stopRequested) { | ||
if (auto task = schedulers_.get().next(); task.has_value()) { | ||
if (auto maybeBatch = extractor_.get().extractLedgerWithDiff(task->seq); maybeBatch.has_value()) { | ||
LOG(log_.debug()) << "Adding data after extracting diff"; | ||
while (not queue.enqueue(*maybeBatch)) { | ||
// TODO (https://github.com/XRPLF/clio/issues/1852) | ||
std::this_thread::sleep_for(kDELAY_BETWEEN_ENQUEUE_ATTEMPTS); | ||
|
||
if (stopRequested) | ||
break; | ||
} | ||
} else { | ||
// TODO: how do we signal to the loaders that it's time to shutdown? some special task? | ||
break; // TODO: handle server shutdown or other node took over ETL | ||
} | ||
} else { | ||
// TODO (https://github.com/XRPLF/clio/issues/1852) | ||
std::this_thread::sleep_for(kDELAY_BETWEEN_ATTEMPTS); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
util::async::AnyOperation<void> | ||
TaskManager::spawnLoader(PriorityQueue& queue) | ||
{ | ||
return ctx_.execute([this, &queue](auto stopRequested) { | ||
while (not stopRequested) { | ||
// TODO (https://github.com/XRPLF/clio/issues/66): does not tell the loader whether it's out of order or not | ||
if (auto data = queue.dequeue(); data.has_value()) | ||
loader_.get().load(*data); | ||
} | ||
}); | ||
} | ||
|
||
void | ||
TaskManager::wait() | ||
{ | ||
for (auto& extractor : extractors_) | ||
extractor.wait(); | ||
for (auto& loader : loaders_) | ||
loader.wait(); | ||
} | ||
|
||
void | ||
TaskManager::stop() | ||
{ | ||
for (auto& extractor : extractors_) | ||
extractor.abort(); | ||
for (auto& loader : loaders_) | ||
loader.abort(); | ||
|
||
wait(); | ||
} | ||
|
||
} // namespace etlng::impl |
Oops, something went wrong.