Skip to content

Commit

Permalink
Advance ripple.app.rdb
Browse files Browse the repository at this point in the history
  • Loading branch information
undertome committed Dec 21, 2021
1 parent 89766c5 commit edc0572
Show file tree
Hide file tree
Showing 70 changed files with 3,654 additions and 3,867 deletions.
19 changes: 12 additions & 7 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,18 @@ target_sources (rippled PRIVATE
src/ripple/app/paths/impl/DirectStep.cpp
src/ripple/app/paths/impl/PaySteps.cpp
src/ripple/app/paths/impl/XRPEndpointStep.cpp
src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.cpp
src/ripple/app/rdb/backend/RelationalDBInterfaceSqlite.cpp
src/ripple/app/rdb/impl/RelationalDBInterface.cpp
src/ripple/app/rdb/impl/RelationalDBInterface_global.cpp
src/ripple/app/rdb/impl/RelationalDBInterface_nodes.cpp
src/ripple/app/rdb/impl/RelationalDBInterface_postgres.cpp
src/ripple/app/rdb/impl/RelationalDBInterface_shards.cpp
src/ripple/app/rdb/backend/detail/impl/Node.cpp
src/ripple/app/rdb/backend/detail/impl/Shard.cpp
src/ripple/app/rdb/backend/impl/PostgresDatabase.cpp
src/ripple/app/rdb/backend/impl/SQLiteDatabase.cpp
src/ripple/app/rdb/impl/Download.cpp
src/ripple/app/rdb/impl/PeerFinder.cpp
src/ripple/app/rdb/impl/RelationalDatabase.cpp
src/ripple/app/rdb/impl/ShardArchive.cpp
src/ripple/app/rdb/impl/State.cpp
src/ripple/app/rdb/impl/UnitaryShard.cpp
src/ripple/app/rdb/impl/Vacuum.cpp
src/ripple/app/rdb/impl/Wallet.cpp
src/ripple/app/tx/impl/ApplyContext.cpp
src/ripple/app/tx/impl/BookTip.cpp
src/ripple/app/tx/impl/CancelCheck.cpp
Expand Down
4 changes: 2 additions & 2 deletions Builds/levelization/results/loops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Loop: ripple.app ripple.net
ripple.app > ripple.net

Loop: ripple.app ripple.nodestore
ripple.nodestore ~= ripple.app
ripple.app > ripple.nodestore

Loop: ripple.app ripple.overlay
ripple.overlay ~= ripple.app

Loop: ripple.app ripple.peerfinder
ripple.peerfinder ~= ripple.app
ripple.app > ripple.peerfinder

Loop: ripple.app ripple.rpc
ripple.rpc > ripple.app
Expand Down
27 changes: 16 additions & 11 deletions src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include <ripple/app/misc/HashRouter.h>
#include <ripple/app/misc/LoadFeeTrack.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
#include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.h>
#include <ripple/app/rdb/backend/PostgresDatabase.h>
#include <ripple/app/rdb/backend/SQLiteDatabase.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/basics/contract.h>
Expand Down Expand Up @@ -927,9 +927,11 @@ saveValidatedLedger(
return true;
}

auto res = dynamic_cast<RelationalDBInterfaceSqlite*>(
&app.getRelationalDBInterface())
->saveValidatedLedger(ledger, current);
auto const res = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase())
->saveValidatedLedger(ledger, current);

if (!res)
Throw<std::runtime_error>("Failed to get relational database");

// Clients can now trust the database for
// information about this ledger sequence.
Expand Down Expand Up @@ -1051,7 +1053,7 @@ std::tuple<std::shared_ptr<Ledger>, std::uint32_t, uint256>
getLatestLedger(Application& app)
{
const std::optional<LedgerInfo> info =
app.getRelationalDBInterface().getNewestLedgerInfo();
app.getRelationalDatabase().getNewestLedgerInfo();
if (!info)
return {std::shared_ptr<Ledger>(), {}, {}};
return {loadLedgerHelper(*info, app, true), info->seq, info->hash};
Expand All @@ -1061,7 +1063,7 @@ std::shared_ptr<Ledger>
loadByIndex(std::uint32_t ledgerIndex, Application& app, bool acquire)
{
if (std::optional<LedgerInfo> info =
app.getRelationalDBInterface().getLedgerInfoByIndex(ledgerIndex))
app.getRelationalDatabase().getLedgerInfoByIndex(ledgerIndex))
{
std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
Expand All @@ -1074,7 +1076,7 @@ std::shared_ptr<Ledger>
loadByHash(uint256 const& ledgerHash, Application& app, bool acquire)
{
if (std::optional<LedgerInfo> info =
app.getRelationalDBInterface().getLedgerInfoByHash(ledgerHash))
app.getRelationalDatabase().getLedgerInfoByHash(ledgerHash))
{
std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
Expand Down Expand Up @@ -1163,9 +1165,12 @@ flatFetchTransactions(ReadView const& ledger, Application& app)
return {};
}

auto nodestoreHashes = dynamic_cast<RelationalDBInterfacePostgres*>(
&app.getRelationalDBInterface())
->getTxHashes(ledger.info().seq);
auto const db =
dynamic_cast<PostgresDatabase*>(&app.getRelationalDatabase());
if (!db)
Throw<std::runtime_error>("Failed to get relational database");

auto nodestoreHashes = db->getTxHashes(ledger.info().seq);

return flatFetchTransactions(app, nodestoreHashes);
}
Expand Down
27 changes: 12 additions & 15 deletions src/ripple/app/ledger/impl/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
#include <ripple/app/misc/TxQ.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/app/paths/PathRequests.h>
#include <ripple/app/rdb/RelationalDBInterface_postgres.h>
#include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
#include <ripple/app/rdb/backend/PostgresDatabase.h>
#include <ripple/app/tx/apply.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/MathUtilities.h>
Expand Down Expand Up @@ -273,10 +272,10 @@ LedgerMaster::getValidatedLedgerAge()

#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
return static_cast<PostgresDatabase*>(&app_.getRelationalDatabase())
->getValidatedLedgerAge();
#endif

std::chrono::seconds valClose{mValidLedgerSign.load()};
if (valClose == 0s)
{
Expand All @@ -299,8 +298,7 @@ LedgerMaster::isCaughtUp(std::string& reason)

#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
return static_cast<PostgresDatabase*>(&app_.getRelationalDatabase())
->isCaughtUp(reason);
#endif

Expand Down Expand Up @@ -733,7 +731,7 @@ LedgerMaster::tryFill(Job& job, std::shared_ptr<Ledger const> ledger)
mCompleteLedgers.insert(range(minHas, maxHas));
}
maxHas = minHas;
ledgerHashes = app_.getRelationalDBInterface().getHashesByIndex(
ledgerHashes = app_.getRelationalDatabase().getHashesByIndex(
(seq < 500) ? 0 : (seq - 499), seq);
it = ledgerHashes.find(seq);

Expand Down Expand Up @@ -917,8 +915,8 @@ LedgerMaster::setFullLedger(
{
// Check the SQL database's entry for the sequence before this
// ledger, if it's not this ledger's parent, invalidate it
uint256 prevHash = app_.getRelationalDBInterface().getHashByIndex(
ledger->info().seq - 1);
uint256 prevHash =
app_.getRelationalDatabase().getHashByIndex(ledger->info().seq - 1);
if (prevHash.isNonZero() && prevHash != ledger->info().parentHash)
clearLedger(ledger->info().seq - 1);
}
Expand Down Expand Up @@ -1624,7 +1622,7 @@ LedgerMaster::getValidatedLedger()
#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
{
auto seq = app_.getRelationalDBInterface().getMaxLedgerSeq();
auto seq = app_.getRelationalDatabase().getMaxLedgerSeq();
if (!seq)
return {};
return getLedgerBySeq(*seq);
Expand Down Expand Up @@ -1660,8 +1658,7 @@ LedgerMaster::getCompleteLedgers()
{
#ifdef RIPPLED_REPORTING
if (app_.config().reporting())
return static_cast<RelationalDBInterfacePostgres*>(
&app_.getRelationalDBInterface())
return static_cast<PostgresDatabase*>(&app_.getRelationalDatabase())
->getCompleteLedgers();
#endif
std::lock_guard sl(mCompleteLock);
Expand Down Expand Up @@ -1706,7 +1703,7 @@ LedgerMaster::getHashBySeq(std::uint32_t index)
if (hash.isNonZero())
return hash;

return app_.getRelationalDBInterface().getHashByIndex(index);
return app_.getRelationalDatabase().getHashByIndex(index);
}

std::optional<LedgerHash>
Expand Down Expand Up @@ -1933,7 +1930,7 @@ LedgerMaster::fetchForHistory(
fillInProgress = mFillInProgress;
}
if (fillInProgress == 0 &&
app_.getRelationalDBInterface().getHashByIndex(seq - 1) ==
app_.getRelationalDatabase().getHashByIndex(seq - 1) ==
ledger->info().parentHash)
{
{
Expand Down Expand Up @@ -2329,7 +2326,7 @@ LedgerMaster::getFetchPackCacheSize() const
std::optional<LedgerIndex>
LedgerMaster::minSqlSeq()
{
return app_.getRelationalDBInterface().getMinLedgerSeq();
return app_.getRelationalDatabase().getMinLedgerSeq();
}

} // namespace ripple
32 changes: 15 additions & 17 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include <ripple/app/misc/ValidatorKeys.h>
#include <ripple/app/misc/ValidatorSite.h>
#include <ripple/app/paths/PathRequests.h>
#include <ripple/app/rdb/RelationalDBInterface_global.h>
#include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
#include <ripple/app/rdb/Wallet.h>
#include <ripple/app/rdb/backend/PostgresDatabase.h>
#include <ripple/app/reporting/ReportingETL.h>
#include <ripple/app/tx/apply.h>
#include <ripple/basics/ByteUtilities.h>
Expand Down Expand Up @@ -219,7 +219,7 @@ class ApplicationImp : public Application, public BasicApp
boost::asio::steady_timer sweepTimer_;
boost::asio::steady_timer entropyTimer_;

std::unique_ptr<RelationalDBInterface> mRelationalDBInterface;
std::unique_ptr<RelationalDatabase> mRelationalDatabase;
std::unique_ptr<DatabaseCon> mWalletDB;
std::unique_ptr<Overlay> overlay_;

Expand Down Expand Up @@ -874,11 +874,11 @@ class ApplicationImp : public Application, public BasicApp
return *txQ_;
}

RelationalDBInterface&
getRelationalDBInterface() override
RelationalDatabase&
getRelationalDatabase() override
{
assert(mRelationalDBInterface.get() != nullptr);
return *mRelationalDBInterface;
assert(mRelationalDatabase.get() != nullptr);
return *mRelationalDatabase;
}

DatabaseCon&
Expand All @@ -904,14 +904,14 @@ class ApplicationImp : public Application, public BasicApp
//--------------------------------------------------------------------------

bool
initRDBMS()
initRelationalDatabase()
{
assert(mWalletDB.get() == nullptr);

try
{
mRelationalDBInterface =
RelationalDBInterface::init(*this, *config_, *m_jobQueue);
mRelationalDatabase =
RelationalDatabase::init(*this, *config_, *m_jobQueue);

// wallet database
auto setup = setup_DatabaseCon(*config_, m_journal);
Expand Down Expand Up @@ -1056,8 +1056,7 @@ class ApplicationImp : public Application, public BasicApp
ledgerCleaner_->stop();
if (reportingETL_)
reportingETL_->stop();
if (auto pg = dynamic_cast<RelationalDBInterfacePostgres*>(
&*mRelationalDBInterface))
if (auto pg = dynamic_cast<PostgresDatabase*>(&*mRelationalDatabase))
pg->stop();
m_nodeStore->stop();
perfLog_->stop();
Expand Down Expand Up @@ -1139,7 +1138,7 @@ class ApplicationImp : public Application, public BasicApp
doSweep()
{
if (!config_->standalone() &&
!getRelationalDBInterface().transactionDbHasSpace(*config_))
!getRelationalDatabase().transactionDbHasSpace(*config_))
{
signalStop();
}
Expand All @@ -1164,8 +1163,7 @@ class ApplicationImp : public Application, public BasicApp
cachedSLEs_.sweep();

#ifdef RIPPLED_REPORTING
if (auto pg = dynamic_cast<RelationalDBInterfacePostgres*>(
&*mRelationalDBInterface))
if (auto pg = dynamic_cast<PostgresDatabase*>(&*mRelationalDatabase))
pg->sweep();
#endif

Expand Down Expand Up @@ -1260,7 +1258,7 @@ ApplicationImp::setup()
if (!config_->standalone())
timeKeeper_->run(config_->SNTP_SERVERS);

if (!initRDBMS() || !initNodeStore())
if (!initRelationalDatabase() || !initNodeStore())
return false;

if (shardStore_)
Expand Down Expand Up @@ -2151,7 +2149,7 @@ ApplicationImp::nodeToShards()
void
ApplicationImp::setMaxDisallowedLedger()
{
auto seq = getRelationalDBInterface().getMaxLedgerSeq();
auto seq = getRelationalDatabase().getMaxLedgerSeq();
if (seq)
maxDisallowedLedger_ = *seq;

Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ValidatorList;
class ValidatorSite;
class Cluster;

class RelationalDBInterface;
class RelationalDatabase;
class DatabaseCon;
class SHAMapStore;

Expand Down Expand Up @@ -251,8 +251,8 @@ class Application : public beast::PropertyStream::Source
openLedger() = 0;
virtual OpenLedger const&
openLedger() const = 0;
virtual RelationalDBInterface&
getRelationalDBInterface() = 0;
virtual RelationalDatabase&
getRelationalDatabase() = 0;

virtual std::chrono::milliseconds
getIOLatency() = 0;
Expand Down
Loading

0 comments on commit edc0572

Please sign in to comment.