Fix reporting mode build issue

* Add isCaughtUp() as a member function of RelationalDBInterfacePostgres
This commit is contained in:
CJ Cobb
2021-06-03 10:06:54 -04:00
committed by manojsdoshi
parent 6298daba1a
commit 9eb9b8f631
3 changed files with 39 additions and 16 deletions

View File

@@ -273,7 +273,7 @@ LedgerMaster::getValidatedLedgerAge()
#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
return dynamic_cast<RelationalDBInterfacePostgres*>(
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
->getValidatedLedgerAge();
#endif
@@ -299,20 +299,9 @@ LedgerMaster::isCaughtUp(std::string& reason)
#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
{
auto age = PgQuery(app_.getPgPool())("SELECT age()");
if (!age || age.isNull())
{
reason = "No ledgers in database";
return false;
}
if (std::chrono::seconds{age.asInt()} > 3min)
{
reason = "No recently-published ledger";
return false;
}
return true;
}
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
->isCaughtUp(reason);
#endif
if (getPublishedLedgerAge() > 3min)
@@ -1665,7 +1654,7 @@ LedgerMaster::getCompleteLedgers()
{
#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
return dynamic_cast<RelationalDBInterfacePostgres*>(
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
->getCompleteLedgers();
#endif

View File

@@ -128,6 +128,9 @@ public:
bool
transactionDbHasSpace(Config const& config) override;
bool
isCaughtUp(std::string& reason) override;
private:
Application& app_;
beast::Journal j_;
@@ -272,5 +275,24 @@ getRelationalDBInterfacePostgres(
return std::make_unique<RelationalDBInterfacePostgresImp>(
app, config, jobQueue);
}
bool
RelationalDBInterfacePostgresImp::isCaughtUp(std::string& reason)
{
#ifdef RIPPLED_REPORTING
using namespace std::chrono_literals;
auto age = PgQuery(pgPool_)("SELECT age()");
if (!age || age.isNull())
{
reason = "No ledgers in database";
return false;
}
if (std::chrono::seconds{age.asInt()} > 3min)
{
reason = "No recently-published ledger";
return false;
}
#endif
return true;
}
} // namespace ripple

View File

@@ -104,6 +104,18 @@ public:
*/
virtual Transaction::Locator
locateTransaction(uint256 const& id) = 0;
/**
* @brief isCaughtUp returns whether the database is caught up with the
* network
* @param[out] reason if the database is not caught up, reason contains a
* helpful message describing why
* @return false if the most recently written
* ledger has a close time over 3 minutes ago, or if there are
* no ledgers in the database. true otherwise
*/
virtual bool
isCaughtUp(std::string& reason) = 0;
};
} // namespace ripple