mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-25 14:15:53 +00:00
@@ -83,33 +83,44 @@ LoadBalancer::LoadBalancer(
|
||||
downloadRanges_ = 4;
|
||||
}
|
||||
|
||||
auto const allowNoEtl = config.valueOr("allow_no_etl", false);
|
||||
|
||||
auto const checkOnETLFailure = [this, allowNoEtl](std::string const& log) {
|
||||
LOG(log_.error()) << log;
|
||||
|
||||
if (!allowNoEtl) {
|
||||
LOG(log_.error()) << "Set allow_no_etl as true in config to allow clio run without valid ETL sources.";
|
||||
throw std::logic_error("ETL configuration error.");
|
||||
}
|
||||
};
|
||||
|
||||
for (auto const& entry : config.array("etl_sources")) {
|
||||
std::unique_ptr<Source> source = make_Source(entry, ioc, backend, subscriptions, validatedLedgers, *this);
|
||||
|
||||
// checking etl node validity
|
||||
auto const state = ETLState::fetchETLStateFromSource(*source);
|
||||
auto const stateOpt = ETLState::fetchETLStateFromSource(*source);
|
||||
|
||||
if (!state.networkID) {
|
||||
LOG(log_.error()) << "Failed to fetch ETL state from source = " << source->toString()
|
||||
<< " Please check the configuration and network";
|
||||
throw std::logic_error("ETL node not available");
|
||||
if (!stateOpt) {
|
||||
checkOnETLFailure(fmt::format(
|
||||
"Failed to fetch ETL state from source = {} Please check the configuration and network",
|
||||
source->toString()
|
||||
));
|
||||
} else if (etlState_ && etlState_->networkID && stateOpt->networkID && etlState_->networkID != stateOpt->networkID) {
|
||||
checkOnETLFailure(fmt::format(
|
||||
"ETL sources must be on the same network. Source network id = {} does not match others network id = {}",
|
||||
*(stateOpt->networkID),
|
||||
*(etlState_->networkID)
|
||||
));
|
||||
} else {
|
||||
etlState_ = stateOpt;
|
||||
}
|
||||
|
||||
if (etlState_ && etlState_->networkID != state.networkID) {
|
||||
LOG(log_.error()) << "ETL sources must be on the same network. "
|
||||
<< "Source network id = " << *(state.networkID)
|
||||
<< " does not match others network id = " << *(etlState_->networkID);
|
||||
throw std::logic_error("ETL nodes are not in the same network");
|
||||
}
|
||||
etlState_ = state;
|
||||
sources_.push_back(std::move(source));
|
||||
LOG(log_.info()) << "Added etl source - " << sources_.back()->toString();
|
||||
}
|
||||
|
||||
if (sources_.empty()) {
|
||||
LOG(log_.error()) << "No ETL sources configured. Please check the configuration";
|
||||
throw std::logic_error("No ETL sources configured");
|
||||
}
|
||||
if (sources_.empty())
|
||||
checkOnETLFailure("No ETL sources configured. Please check the configuration");
|
||||
}
|
||||
|
||||
LoadBalancer::~LoadBalancer()
|
||||
@@ -256,11 +267,14 @@ LoadBalancer::execute(Func f, uint32_t ledgerSequence)
|
||||
return true;
|
||||
}
|
||||
|
||||
ETLState
|
||||
LoadBalancer::getETLState() const noexcept
|
||||
std::optional<ETLState>
|
||||
LoadBalancer::getETLState() noexcept
|
||||
{
|
||||
assert(etlState_); // etlState_ is set in the constructor
|
||||
return *etlState_;
|
||||
if (!etlState_) {
|
||||
// retry ETLState fetch
|
||||
etlState_ = ETLState::fetchETLStateFromSource(*this);
|
||||
}
|
||||
return etlState_;
|
||||
}
|
||||
|
||||
} // namespace etl
|
||||
|
||||
Reference in New Issue
Block a user