Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Sep 24, 2024
1 parent 2ce12d4 commit e51bcb4
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 53 deletions.
14 changes: 14 additions & 0 deletions src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,20 @@ saveValidatedLedger(
return true;
}

if (app.config().RELATIONAL_DB == 0)
{
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
if (!db)
Throw<std::runtime_error>("Failed to get relational database");

auto const res = db->saveValidatedLedger(ledger, current);
// Clients can now trust the database for
// information about this ledger sequence.

app.pendingSaves().finishWork(seq);
return res;
}

auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());
if (!db)
Throw<std::runtime_error>("Failed to get relational database");
Expand Down
45 changes: 45 additions & 0 deletions src/ripple/app/misc/SHAMapStoreImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,51 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
if (healthWait() == stopping)
return;

if (app_.config().RELATIONAL_DB == 0)
{

SQLiteDatabase* const db =
dynamic_cast<SQLiteDatabase*>(&app_.getRelationalDatabase());

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

clearSql(
lastRotated,
"Ledgers",
[db]() -> std::optional<LedgerIndex> { return db->getMinLedgerSeq(); },
[db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); });
if (healthWait() == stopping)
return;

if (!app_.config().useTxTables())
return;

clearSql(
lastRotated,
"Transactions",
[&db]() -> std::optional<LedgerIndex> {
return db->getTransactionsMinLedgerSeq();
},
[&db](LedgerIndex min) -> void {
db->deleteTransactionsBeforeLedgerSeq(min);
});
if (healthWait() == stopping)
return;

clearSql(
lastRotated,
"AccountTransactions",
[&db]() -> std::optional<LedgerIndex> {
return db->getAccountTransactionsMinLedgerSeq();
},
[&db](LedgerIndex min) -> void {
db->deleteAccountTransactionsBeforeLedgerSeq(min);
});
if (healthWait() == stopping)
return;
}

LMDBDatabase* const db =
dynamic_cast<LMDBDatabase*>(&app_.getRelationalDatabase());

Expand Down
15 changes: 14 additions & 1 deletion src/ripple/app/misc/impl/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,20 @@ Transaction::load(
std::optional<ClosedInterval<uint32_t>> const& range,
error_code_i& ec)
{
auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());

if (app.config().RELATIONAL_DB == 0)
{
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());

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

return db->getTransaction(id, range, ec);
}

auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());

if (!db)
{
Expand Down
40 changes: 21 additions & 19 deletions src/ripple/app/rdb/backend/detail/impl/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ makeLedgerDBs(
DatabaseCon::CheckpointerSetup const& checkpointerSetup)
{
if (setup.sqlite3)
{
return makeSQLLedgerDBs(config, setup, checkpointerSetup);
}

return makeLMDBLedgerDBs(config, setup, checkpointerSetup);
}

std::optional<LedgerIndex>
getMinLedgerSeq(MDB_env* env, TableType type)
getMinLedgerSeq(MDB_env *env, TableType type)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand All @@ -182,7 +184,7 @@ getMinLedgerSeq(MDB_env* env, TableType type)
}

std::optional<LedgerIndex>
getMaxLedgerSeq(MDB_env* env, TableType type)
getMaxLedgerSeq(MDB_env *env, TableType type)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand All @@ -208,7 +210,7 @@ getMaxLedgerSeq(MDB_env* env, TableType type)
}

void
deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
deleteByLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand All @@ -227,7 +229,7 @@ deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
}

void
deleteBeforeLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
deleteBeforeLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand Down Expand Up @@ -294,7 +296,7 @@ deleteBeforeLedgerSeq(
}

std::size_t
getRows(MDB_env* env, TableType type)
getRows(MDB_env *env, TableType type)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand Down Expand Up @@ -323,7 +325,7 @@ getRows(MDB_env* env, TableType type)
}

RelationalDatabase::CountMinMax
getRowsMinMax(MDB_env* env, TableType type)
getRowsMinMax(MDB_env *env, TableType type)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand Down Expand Up @@ -455,7 +457,7 @@ saveLMDBValidatedLedger(
MDB_dbi dbi;
MDB_txn* txn;
auto db = ldgDB.checkoutLMDB();
MDB_env* env = db.get();
MDB_env *env = db.get();
mdb_txn_begin(env, nullptr, 0, &txn);
try
{
Expand Down Expand Up @@ -538,7 +540,7 @@ saveLMDBValidatedLedger(
MDB_dbi dbi;
MDB_txn* txn;
auto db = ldgDB.checkoutLMDB();
MDB_env* env = db.get();
MDB_env *env = db.get();
mdb_txn_begin(env, nullptr, 0, &txn);

try
Expand Down Expand Up @@ -797,7 +799,7 @@ saveValidatedLedger(

// Function to get the ledger info from the LMDB database
static std::optional<LedgerInfo>
getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j)
getLedgerInfo(MDB_env *env, std::string const& key, beast::Journal j)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand Down Expand Up @@ -842,15 +844,15 @@ getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j)
}

std::optional<LedgerInfo>
getLedgerInfoByIndex(MDB_env* env, LedgerIndex ledgerSeq, beast::Journal j)
getLedgerInfoByIndex(MDB_env *env, LedgerIndex ledgerSeq, beast::Journal j)
{
std::ostringstream s;
s << "LedgerSeq_" << ledgerSeq;
return getLedgerInfo(env, s.str(), j);
}

std::optional<LedgerInfo>
getNewestLedgerInfo(MDB_env* env, beast::Journal j)
getNewestLedgerInfo(MDB_env *env, beast::Journal j)
{
// LMDB does not support SQL-like queries directly
// You need to implement a way to find the newest ledger info
Expand All @@ -861,7 +863,7 @@ getNewestLedgerInfo(MDB_env* env, beast::Journal j)

std::optional<LedgerInfo>
getLimitedOldestLedgerInfo(
MDB_env* env,
MDB_env *env,
LedgerIndex ledgerFirstIndex,
beast::Journal j)
{
Expand All @@ -873,7 +875,7 @@ getLimitedOldestLedgerInfo(

std::optional<LedgerInfo>
getLimitedNewestLedgerInfo(
MDB_env* env,
MDB_env *env,
LedgerIndex ledgerFirstIndex,
beast::Journal j)
{
Expand All @@ -884,7 +886,7 @@ getLimitedNewestLedgerInfo(
}

std::optional<LedgerInfo>
getLedgerInfoByHash(MDB_env* env, uint256 const& ledgerHash, beast::Journal j)
getLedgerInfoByHash(MDB_env *env, uint256 const& ledgerHash, beast::Journal j)
{
std::ostringstream s;
s << "LedgerHash_" << ledgerHash;
Expand Down Expand Up @@ -1024,7 +1026,7 @@ getLedgerInfoByHash(
}

uint256
getHashByIndex(MDB_env* env, LedgerIndex ledgerIndex)
getHashByIndex(MDB_env *env, LedgerIndex ledgerIndex)
{
uint256 ret;
MDB_txn* txn;
Expand Down Expand Up @@ -1098,7 +1100,7 @@ getHashByIndex(soci::session& session, LedgerIndex ledgerIndex)
}

std::optional<LedgerHashPair>
getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j)
getHashesByIndex(MDB_env *env, LedgerIndex ledgerIndex, beast::Journal j)
{
MDB_txn* txn;
MDB_dbi dbi;
Expand Down Expand Up @@ -1158,7 +1160,7 @@ getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j)

std::map<LedgerIndex, LedgerHashPair>
getHashesByIndex(
MDB_env* env,
MDB_env *env,
LedgerIndex minSeq,
LedgerIndex maxSeq,
beast::Journal j)
Expand Down Expand Up @@ -1982,7 +1984,7 @@ newestAccountTxPage(

std::variant<RelationalDatabase::AccountTx, TxSearched>
getTransaction(
MDB_env* env,
MDB_env *env,
Application& app,
uint256 const& id,
std::optional<ClosedInterval<uint32_t>> const& range,
Expand Down Expand Up @@ -2185,7 +2187,7 @@ getTransaction(
}

bool
dbHasSpace(MDB_env* env, Config const& config, beast::Journal j)
dbHasSpace(MDB_env *env, Config const& config, beast::Journal j)
{
boost::filesystem::space_info space =
boost::filesystem::space(config.legacy("database_path"));
Expand Down
60 changes: 30 additions & 30 deletions src/ripple/app/rdb/impl/RelationalDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,37 @@ RelationalDatabase::init(
{
bool use_sqlite = false;
bool use_postgres = false;
bool use_lmdb = false;
bool use_lmdb = true;

if (config.reporting())
{
use_postgres = true;
}
else
{
const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)};
if (!rdb_section.empty())
{
if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
{
use_sqlite = true;
}
else if (boost::iequals(get(rdb_section, "backend"), "lmdb"))
{
use_lmdb = true;
}
else
{
Throw<std::runtime_error>(
"Invalid rdb_section backend value: " +
get(rdb_section, "backend"));
}
}
else
{
use_sqlite = true;
}
}
// if (config.reporting())
// {
// use_postgres = true;
// }
// else
// {
// const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)};
// if (!rdb_section.empty())
// {
// if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
// {
// use_sqlite = true;
// }
// else if (boost::iequals(get(rdb_section, "backend"), "lmdb"))
// {
// use_lmdb = true;
// }
// else
// {
// Throw<std::runtime_error>(
// "Invalid rdb_section backend value: " +
// get(rdb_section, "backend"));
// }
// }
// else
// {
// use_sqlite = true;
// }
// }

if (use_sqlite)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Config : public BasicConfig

std::string START_LEDGER;

uint32_t RELATIONAL_DB = 0; // 0 == SQLite, 1 == LMDB
uint32_t RELATIONAL_DB = 1; // 0 == SQLite, 1 == LMDB

// Network parameters
uint32_t NETWORK_ID = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/core/impl/DatabaseCon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ setup_DatabaseCon(Config const& c, std::optional<beast::Journal> j)
setup.startUp = c.START_UP;
setup.standAlone = c.standalone();
setup.reporting = c.reporting();
std::cout << c.RELATIONAL_DB;
setup.sqlite3 = true;
setup.sqlite3 = false;
setup.dataDir = c.legacy("database_path");
if (!setup.standAlone && setup.dataDir.empty())
{
Expand Down

0 comments on commit e51bcb4

Please sign in to comment.