refactor: acquireAsync will dispatch the job, not the other way around

This commit is contained in:
Ed Hennis
2025-02-04 16:54:26 -05:00
parent 7b72b9cc82
commit 46a5bc74db
5 changed files with 41 additions and 33 deletions

View File

@@ -91,6 +91,8 @@ public:
virtual void virtual void
acquireAsync( acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash, uint256 const& hash,
std::uint32_t seq, std::uint32_t seq,
InboundLedger::Reason reason) override InboundLedger::Reason reason) override

View File

@@ -118,15 +118,12 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
// Tell the ledger acquire system that we need the consensus ledger // Tell the ledger acquire system that we need the consensus ledger
acquiringLedger_ = hash; acquiringLedger_ = hash;
app_.getJobQueue().addJob( app_.getInboundLedgers().acquireAsync(
jtADVANCE, jtADVANCE,
"getConsensusLedger1", "getConsensusLedger1",
[id = hash, &app = app_, this]() { hash,
JLOG(j_.debug()) 0,
<< "JOB advanceLedger getConsensusLedger1 started"; InboundLedger::Reason::CONSENSUS);
app.getInboundLedgers().acquireAsync(
id, 0, InboundLedger::Reason::CONSENSUS);
});
} }
return std::nullopt; return std::nullopt;
} }

View File

@@ -120,15 +120,12 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
JLOG(j_.warn()) JLOG(j_.warn())
<< "Need validated ledger for preferred ledger analysis " << hash; << "Need validated ledger for preferred ledger analysis " << hash;
Application* pApp = &app_; app_.getInboundLedgers().acquireAsync(
jtADVANCE,
app_.getJobQueue().addJob( "getConsensusLedger2",
jtADVANCE, "getConsensusLedger2", [pApp, hash, this]() { hash,
JLOG(j_.debug()) 0,
<< "JOB advanceLedger getConsensusLedger2 started"; InboundLedger::Reason::CONSENSUS);
pApp->getInboundLedgers().acquireAsync(
hash, 0, InboundLedger::Reason::CONSENSUS);
});
return std::nullopt; return std::nullopt;
} }

View File

@@ -28,6 +28,8 @@ public:
// instead. Inbound ledger acquisition is asynchronous anyway. // instead. Inbound ledger acquisition is asynchronous anyway.
virtual void virtual void
acquireAsync( acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash, uint256 const& hash,
std::uint32_t seq, std::uint32_t seq,
InboundLedger::Reason reason) = 0; InboundLedger::Reason reason) = 0;

View File

@@ -123,28 +123,38 @@ public:
void void
acquireAsync( acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash, uint256 const& hash,
std::uint32_t seq, std::uint32_t seq,
InboundLedger::Reason reason) override InboundLedger::Reason reason) override
{ {
if (CanProcess const check{acquiresMutex_, pendingAcquires_, hash}) if (auto check = std::make_shared<CanProcess const>(
acquiresMutex_, pendingAcquires_, hash);
*check)
{ {
try app_.getJobQueue().addJob(
{ type, name, [check, name, hash, seq, reason, this]() {
acquire(hash, seq, reason); JLOG(j_.debug())
} << "JOB acquireAsync " << name << " started ";
catch (std::exception const& e) try
{ {
JLOG(j_.warn()) acquire(hash, seq, reason);
<< "Exception thrown for acquiring new inbound ledger " }
<< hash << ": " << e.what(); catch (std::exception const& e)
} {
catch (...) JLOG(j_.warn()) << "Exception thrown for acquiring new "
{ "inbound ledger "
JLOG(j_.warn()) << "Unknown exception thrown for acquiring new " << hash << ": " << e.what();
"inbound ledger " }
<< hash; catch (...)
} {
JLOG(j_.warn())
<< "Unknown exception thrown for acquiring new "
"inbound ledger "
<< hash;
}
});
} }
} }