Properly handle configurations where use_tx_tables = 0

This commit is contained in:
cdy20
2021-04-08 20:38:58 -04:00
committed by Nik Bougalis
parent 3be668b343
commit 2a298469be
3 changed files with 721 additions and 452 deletions

View File

@@ -277,7 +277,11 @@ getTxHistory(
* @param j Journal.
* @return Vector of pairs of found transactions and their metadata
* sorted in ascending order by account sequence.
* Also number of transactions processed.
* Also number of transactions processed or skpiied.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
std::pair<RelationalDBInterface::AccountTxs, int>
getOldestAccountTxs(
@@ -304,7 +308,11 @@ getOldestAccountTxs(
* @param j Journal.
* @return Vector of pairs of found transactions and their metadata
* sorted in descending order by account sequence.
* Also number of transactions processed.
* Also number of transactions processed or skipped.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
std::pair<RelationalDBInterface::AccountTxs, int>
getNewestAccountTxs(
@@ -331,7 +339,11 @@ getNewestAccountTxs(
* @param j Journal.
* @return Vector of tuples of found transactions, their metadata and
* account sequences sorted in ascending order by account
* sequence. Also number of transactions processed.
* sequence. Also number of transactions processed or skpiied.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
std::pair<std::vector<RelationalDBInterface::txnMetaLedgerType>, int>
getOldestAccountTxsB(
@@ -357,7 +369,11 @@ getOldestAccountTxsB(
* @param j Journal.
* @return Vector of tuples of found transactions, their metadata and
* account sequences sorted in descending order by account
* sequence. Also number of transactions processed.
* sequence. Also number of transactions processed or skpiied.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
std::pair<std::vector<RelationalDBInterface::txnMetaLedgerType>, int>
getNewestAccountTxsB(

View File

@@ -46,7 +46,9 @@ public:
Application& app,
Config const& config,
JobQueue& jobQueue)
: app_(app), j_(app_.journal("Ledger"))
: app_(app)
, useTxTables_(config.useTxTables())
, j_(app_.journal("Ledger"))
{
DatabaseCon::Setup setup = setup_DatabaseCon(config, j_);
if (!makeLedgerDBs(
@@ -191,6 +193,7 @@ public:
private:
Application& app_;
bool useTxTables_;
beast::Journal j_;
std::unique_ptr<DatabaseCon> lgrdb_, txdb_;
std::unique_ptr<DatabaseCon> lgrMetaDB_, txMetaDB_;
@@ -257,23 +260,43 @@ private:
}
/**
* @brief checkoutLedger Checks if node ledger DB exists.
* @brief existsLedger Checks if node ledger DB exists.
* @return True if node ledger DB exists.
*/
bool
existsLedger()
{
return !!lgrdb_;
return (bool)lgrdb_;
}
/**
* @brief checkoutTransaction Checks if node transaction DB exists.
* @brief existsTransaction Checks if node transaction DB exists.
* @return True if node transaction DB exists.
*/
bool
existsTransaction()
{
return !!txdb_;
return (bool)txdb_;
}
/**
* @brief existsShardLedger Checks if shard ledger DBs exist.
* @return True if node ledger DB exists.
*/
bool
existsShardLedger()
{
return app_.getShardStore() != nullptr;
}
/**
* @brief existsShardTransaction Checks if shard transaction DBs exist.
* @return True if node transaction DB exists.
*/
bool
existsShardTransaction()
{
return useTxTables_ && app_.getShardStore() != nullptr;
}
/**
@@ -457,7 +480,9 @@ RelationalDBInterfaceSqliteImp::getMinLedgerSeq()
return ripple::getMinLedgerSeq(*db, TableType::Ledgers);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::optional<LedgerIndex> res;
iterateLedgerForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -465,6 +490,10 @@ RelationalDBInterfaceSqliteImp::getMinLedgerSeq()
return !res;
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerIndex>
@@ -477,7 +506,9 @@ RelationalDBInterfaceSqliteImp::getTransactionsMinLedgerSeq()
return ripple::getMinLedgerSeq(*db, TableType::Transactions);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::optional<LedgerIndex> res;
iterateTransactionForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -485,6 +516,10 @@ RelationalDBInterfaceSqliteImp::getTransactionsMinLedgerSeq()
return !res;
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerIndex>
@@ -497,7 +532,9 @@ RelationalDBInterfaceSqliteImp::getAccountTransactionsMinLedgerSeq()
return ripple::getMinLedgerSeq(*db, TableType::AccountTransactions);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::optional<LedgerIndex> res;
iterateTransactionForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -506,6 +543,10 @@ RelationalDBInterfaceSqliteImp::getAccountTransactionsMinLedgerSeq()
return !res;
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerIndex>
@@ -518,7 +559,9 @@ RelationalDBInterfaceSqliteImp::getMaxLedgerSeq()
return ripple::getMaxLedgerSeq(*db, TableType::Ledgers);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::optional<LedgerIndex> res;
iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -526,6 +569,10 @@ RelationalDBInterfaceSqliteImp::getMaxLedgerSeq()
return !res;
});
return res;
}
/* else return empty value */
return {};
}
void
@@ -540,11 +587,17 @@ RelationalDBInterfaceSqliteImp::deleteTransactionByLedgerSeq(
return;
}
/* else use shard database */
/* else use shard database, if available */
if (existsShardTransaction())
{
doTransaction(ledgerSeq, [&](soci::session& session) {
ripple::deleteByLedgerSeq(session, TableType::Transactions, ledgerSeq);
ripple::deleteByLedgerSeq(
session, TableType::Transactions, ledgerSeq);
return true;
});
}
/* else nothing to do */
}
void
@@ -558,7 +611,9 @@ RelationalDBInterfaceSqliteImp::deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)
return;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
iterateLedgerBack(
seqToShardIndex(ledgerSeq),
[&](soci::session& session, std::uint32_t shardIndex) {
@@ -566,6 +621,9 @@ RelationalDBInterfaceSqliteImp::deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)
session, TableType::Ledgers, ledgerSeq);
return true;
});
}
/* else nothing to do */
}
void
@@ -580,7 +638,9 @@ RelationalDBInterfaceSqliteImp::deleteTransactionsBeforeLedgerSeq(
return;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
iterateTransactionBack(
seqToShardIndex(ledgerSeq),
[&](soci::session& session, std::uint32_t shardIndex) {
@@ -588,6 +648,9 @@ RelationalDBInterfaceSqliteImp::deleteTransactionsBeforeLedgerSeq(
session, TableType::Transactions, ledgerSeq);
return true;
});
}
/* else nothing to do */
}
void
@@ -603,7 +666,9 @@ RelationalDBInterfaceSqliteImp::deleteAccountTransactionsBeforeLedgerSeq(
return;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
iterateTransactionBack(
seqToShardIndex(ledgerSeq),
[&](soci::session& session, std::uint32_t shardIndex) {
@@ -611,6 +676,9 @@ RelationalDBInterfaceSqliteImp::deleteAccountTransactionsBeforeLedgerSeq(
session, TableType::AccountTransactions, ledgerSeq);
return true;
});
}
/* else nothing to do */
}
std::size_t
@@ -623,7 +691,9 @@ RelationalDBInterfaceSqliteImp::getTransactionCount()
return ripple::getRows(*db, TableType::Transactions);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::size_t rows = 0;
iterateTransactionForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -631,6 +701,10 @@ RelationalDBInterfaceSqliteImp::getTransactionCount()
return true;
});
return rows;
}
/* else return 0 */
return 0;
}
std::size_t
@@ -643,14 +717,21 @@ RelationalDBInterfaceSqliteImp::getAccountTransactionCount()
return ripple::getRows(*db, TableType::AccountTransactions);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::size_t rows = 0;
iterateTransactionForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
rows += ripple::getRows(session, TableType::AccountTransactions);
rows +=
ripple::getRows(session, TableType::AccountTransactions);
return true;
});
return rows;
}
/* else return 0 */
return 0;
}
RelationalDBInterface::CountMinMax
@@ -663,7 +744,9 @@ RelationalDBInterfaceSqliteImp::getLedgerCountMinMax()
return ripple::getRowsMinMax(*db, TableType::Ledgers);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
CountMinMax res{0, 0, 0};
iterateLedgerForward(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -678,6 +761,10 @@ RelationalDBInterfaceSqliteImp::getLedgerCountMinMax()
return true;
});
return res;
}
/* else return zero values */
return {0, 0, 0};
}
bool
@@ -693,7 +780,9 @@ RelationalDBInterfaceSqliteImp::saveValidatedLedger(
return false;
}
if (auto shardStore = app_.getShardStore())
/* else use shard databases, if available */
if (auto shardStore = app_.getShardStore();
shardStore && existsShardTransaction())
{
if (ledger->info().seq < shardStore->earliestLedgerSeq())
// For the moment return false only when the ShardStore
@@ -727,13 +816,19 @@ RelationalDBInterfaceSqliteImp::getLedgerInfoByIndex(LedgerIndex ledgerSeq)
return ripple::getLedgerInfoByIndex(*db, ledgerSeq, j_);
}
/* else use shard database */
/* else use shard database, if available */
if (existsShardLedger())
{
std::optional<LedgerInfo> res;
doLedger(ledgerSeq, [&](soci::session& session) {
res = ripple::getLedgerInfoByIndex(session, ledgerSeq, j_);
return true;
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerInfo>
@@ -746,7 +841,9 @@ RelationalDBInterfaceSqliteImp::getNewestLedgerInfo()
return ripple::getNewestLedgerInfo(*db, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::optional<LedgerInfo> res;
iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -759,6 +856,10 @@ RelationalDBInterfaceSqliteImp::getNewestLedgerInfo()
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerInfo>
@@ -772,7 +873,9 @@ RelationalDBInterfaceSqliteImp::getLimitedOldestLedgerInfo(
return ripple::getLimitedOldestLedgerInfo(*db, ledgerFirstIndex, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::optional<LedgerInfo> res;
iterateLedgerForward(
seqToShardIndex(ledgerFirstIndex),
@@ -787,6 +890,10 @@ RelationalDBInterfaceSqliteImp::getLimitedOldestLedgerInfo(
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerInfo>
@@ -800,7 +907,9 @@ RelationalDBInterfaceSqliteImp::getLimitedNewestLedgerInfo(
return ripple::getLimitedNewestLedgerInfo(*db, ledgerFirstIndex, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::optional<LedgerInfo> res;
iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -814,6 +923,10 @@ RelationalDBInterfaceSqliteImp::getLimitedNewestLedgerInfo(
});
return res;
}
/* else return empty value */
return {};
}
std::optional<LedgerInfo>
@@ -826,7 +939,7 @@ RelationalDBInterfaceSqliteImp::getLedgerInfoByHash(uint256 const& ledgerHash)
return ripple::getLedgerInfoByHash(*db, ledgerHash, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (auto shardStore = app_.getShardStore())
{
std::optional<LedgerInfo> res;
@@ -845,6 +958,7 @@ RelationalDBInterfaceSqliteImp::getLedgerInfoByHash(uint256 const& ledgerHash)
return res;
}
/* else return empty value */
return {};
}
@@ -858,13 +972,19 @@ RelationalDBInterfaceSqliteImp::getHashByIndex(LedgerIndex ledgerIndex)
return ripple::getHashByIndex(*db, ledgerIndex);
}
/* else use shard database */
/* else use shard database, if available */
if (existsShardLedger())
{
uint256 hash;
doLedger(ledgerIndex, [&](soci::session& session) {
hash = ripple::getHashByIndex(session, ledgerIndex);
return true;
});
return hash;
}
/* else return zero value */
return uint256();
}
std::optional<LedgerHashPair>
@@ -877,13 +997,19 @@ RelationalDBInterfaceSqliteImp::getHashesByIndex(LedgerIndex ledgerIndex)
return ripple::getHashesByIndex(*db, ledgerIndex, j_);
}
/* else use shard database */
/* else use shard database, if available */
if (existsShardLedger())
{
std::optional<LedgerHashPair> res;
doLedger(ledgerIndex, [&](soci::session& session) {
res = ripple::getHashesByIndex(session, ledgerIndex, j_);
return true;
});
return res;
}
/* else return empty value */
return {};
}
std::map<LedgerIndex, LedgerHashPair>
@@ -898,7 +1024,9 @@ RelationalDBInterfaceSqliteImp::getHashesByIndex(
return ripple::getHashesByIndex(*db, minSeq, maxSeq, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::map<LedgerIndex, LedgerHashPair> res;
while (minSeq <= maxSeq)
{
@@ -906,7 +1034,8 @@ RelationalDBInterfaceSqliteImp::getHashesByIndex(
if (shardMaxSeq > maxSeq)
shardMaxSeq = maxSeq;
doLedger(minSeq, [&](soci::session& session) {
auto r = ripple::getHashesByIndex(session, minSeq, shardMaxSeq, j_);
auto r =
ripple::getHashesByIndex(session, minSeq, shardMaxSeq, j_);
res.insert(r.begin(), r.end());
return true;
});
@@ -914,6 +1043,10 @@ RelationalDBInterfaceSqliteImp::getHashesByIndex(
}
return res;
}
/* else return empty value */
return {};
}
std::vector<std::shared_ptr<Transaction>>
@@ -926,13 +1059,15 @@ RelationalDBInterfaceSqliteImp::getTxHistory(LedgerIndex startIndex)
return ripple::getTxHistory(*db, app_, startIndex, 20, false).first;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::vector<std::shared_ptr<Transaction>> txs;
int quantity = 20;
iterateTransactionBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
auto [tx, total] =
ripple::getTxHistory(session, app_, startIndex, quantity, true);
auto [tx, total] = ripple::getTxHistory(
session, app_, startIndex, quantity, true);
txs.insert(txs.end(), tx.begin(), tx.end());
if (total > 0)
{
@@ -949,6 +1084,10 @@ RelationalDBInterfaceSqliteImp::getTxHistory(LedgerIndex startIndex)
});
return txs;
}
/* else return empty value */
return {};
}
RelationalDBInterface::AccountTxs
@@ -966,7 +1105,9 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxs(
.first;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxs ret;
AccountTxOptions opt = options;
int limit_used = 0;
@@ -974,7 +1115,8 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxs(
opt.minLedger ? seqToShardIndex(opt.minLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.maxLedger && shardIndex > seqToShardIndex(opt.maxLedger))
if (opt.maxLedger &&
shardIndex > seqToShardIndex(opt.maxLedger))
return false;
auto [r, total] = ripple::getOldestAccountTxs(
session, app_, ledgerMaster, opt, limit_used, j_);
@@ -988,6 +1130,11 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxs(
}
else
{
/*
* If total < 0, then ~total means number of transactions
* skipped, see definition of return value of function
* ripple::getOldestAccountTxs().
*/
total = ~total;
if (opt.offset <= total)
opt.offset = 0;
@@ -998,6 +1145,10 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxs(
});
return ret;
}
/* else return empty value */
return {};
}
RelationalDBInterface::AccountTxs
@@ -1015,7 +1166,9 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
.first;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxs ret;
AccountTxOptions opt = options;
int limit_used = 0;
@@ -1023,7 +1176,8 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
opt.maxLedger ? seqToShardIndex(opt.maxLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.minLedger && shardIndex < seqToShardIndex(opt.minLedger))
if (opt.minLedger &&
shardIndex < seqToShardIndex(opt.minLedger))
return false;
auto [r, total] = ripple::getNewestAccountTxs(
session, app_, ledgerMaster, opt, limit_used, j_);
@@ -1037,6 +1191,11 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
}
else
{
/*
* If total < 0, then ~total means number of transactions
* skipped, see definition of return value of function
* ripple::getNewestAccountTxs().
*/
total = ~total;
if (opt.offset <= total)
opt.offset = 0;
@@ -1047,6 +1206,10 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxs(
});
return ret;
}
/* else return empty value */
return {};
}
RelationalDBInterface::MetaTxsList
@@ -1060,7 +1223,9 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
return ripple::getOldestAccountTxsB(*db, app_, options, {}, j_).first;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
MetaTxsList ret;
AccountTxOptions opt = options;
int limit_used = 0;
@@ -1068,7 +1233,8 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
opt.minLedger ? seqToShardIndex(opt.minLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.maxLedger && shardIndex > seqToShardIndex(opt.maxLedger))
if (opt.maxLedger &&
shardIndex > seqToShardIndex(opt.maxLedger))
return false;
auto [r, total] = ripple::getOldestAccountTxsB(
session, app_, opt, limit_used, j_);
@@ -1082,6 +1248,11 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
}
else
{
/*
* If total < 0, then ~total means number of transactions
* skipped, see definition of return value of function
* ripple::getOldestAccountTxsB().
*/
total = ~total;
if (opt.offset <= total)
opt.offset = 0;
@@ -1092,6 +1263,10 @@ RelationalDBInterfaceSqliteImp::getOldestAccountTxsB(
});
return ret;
}
/* else return empty value */
return {};
}
RelationalDBInterface::MetaTxsList
@@ -1105,7 +1280,9 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
return ripple::getNewestAccountTxsB(*db, app_, options, {}, j_).first;
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
MetaTxsList ret;
AccountTxOptions opt = options;
int limit_used = 0;
@@ -1113,7 +1290,8 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
opt.maxLedger ? seqToShardIndex(opt.maxLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.minLedger && shardIndex < seqToShardIndex(opt.minLedger))
if (opt.minLedger &&
shardIndex < seqToShardIndex(opt.minLedger))
return false;
auto [r, total] = ripple::getNewestAccountTxsB(
session, app_, opt, limit_used, j_);
@@ -1127,6 +1305,11 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
}
else
{
/*
* If total < 0, then ~total means number of transactions
* skipped, see definition of return value of function
* ripple::getNewestAccountTxsB().
*/
total = ~total;
if (opt.offset <= total)
opt.offset = 0;
@@ -1137,6 +1320,10 @@ RelationalDBInterfaceSqliteImp::getNewestAccountTxsB(
});
return ret;
}
/* else return empty value */
return {};
}
std::pair<
@@ -1175,7 +1362,9 @@ RelationalDBInterfaceSqliteImp::oldestAccountTxPage(
return {ret, newmarker};
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxPageOptions opt = options;
int limit_used = 0;
iterateTransactionForward(
@@ -1201,6 +1390,10 @@ RelationalDBInterfaceSqliteImp::oldestAccountTxPage(
});
return {ret, opt.marker};
}
/* else return empty value */
return {};
}
std::pair<
@@ -1239,14 +1432,17 @@ RelationalDBInterfaceSqliteImp::newestAccountTxPage(
return {ret, newmarker};
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxPageOptions opt = options;
int limit_used = 0;
iterateTransactionBack(
opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.minLedger && shardIndex < seqToShardIndex(opt.minLedger))
if (opt.minLedger &&
shardIndex < seqToShardIndex(opt.minLedger))
return false;
auto [marker, total] = ripple::newestAccountTxPage(
session,
@@ -1264,6 +1460,10 @@ RelationalDBInterfaceSqliteImp::newestAccountTxPage(
});
return {ret, opt.marker};
}
/* else return empty value */
return {};
}
std::pair<
@@ -1301,7 +1501,9 @@ RelationalDBInterfaceSqliteImp::oldestAccountTxPageB(
return {ret, newmarker};
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxPageOptions opt = options;
int limit_used = 0;
iterateTransactionForward(
@@ -1327,6 +1529,10 @@ RelationalDBInterfaceSqliteImp::oldestAccountTxPageB(
});
return {ret, opt.marker};
}
/* else return empty value */
return {};
}
std::pair<
@@ -1364,14 +1570,17 @@ RelationalDBInterfaceSqliteImp::newestAccountTxPageB(
return {ret, newmarker};
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
AccountTxPageOptions opt = options;
int limit_used = 0;
iterateTransactionBack(
opt.maxLedger != UINT32_MAX ? seqToShardIndex(opt.maxLedger)
: std::optional<std::uint32_t>(),
[&](soci::session& session, std::uint32_t shardIndex) {
if (opt.minLedger && shardIndex < seqToShardIndex(opt.minLedger))
if (opt.minLedger &&
shardIndex < seqToShardIndex(opt.minLedger))
return false;
auto [marker, total] = ripple::newestAccountTxPage(
session,
@@ -1389,6 +1598,10 @@ RelationalDBInterfaceSqliteImp::newestAccountTxPageB(
});
return {ret, opt.marker};
}
/* else return empty value */
return {};
}
std::variant<RelationalDBInterface::AccountTx, TxSearched>
@@ -1404,8 +1617,9 @@ RelationalDBInterfaceSqliteImp::getTransaction(
return ripple::getTransaction(*db, app_, id, range, ec);
}
/* else use shard databases */
if (auto shardStore = app_.getShardStore())
/* else use shard databases, if available */
if (auto shardStore = app_.getShardStore();
shardStore && existsShardTransaction())
{
std::variant<AccountTx, TxSearched> res(TxSearched::unknown);
auto txMetaSession = txMetaDB_->checkoutDb();
@@ -1436,7 +1650,8 @@ RelationalDBInterfaceSqliteImp::getTransaction(
return res;
}
return {TxSearched::unknown};
/* else return unknown value */
return TxSearched::unknown;
}
bool
@@ -1449,11 +1664,17 @@ RelationalDBInterfaceSqliteImp::ledgerDbHasSpace(Config const& config)
return ripple::dbHasSpace(*db, config, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
return iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
return ripple::dbHasSpace(session, config, j_);
});
}
/* else return true */
return true;
}
bool
@@ -1466,11 +1687,17 @@ RelationalDBInterfaceSqliteImp::transactionDbHasSpace(Config const& config)
return ripple::dbHasSpace(*db, config, j_);
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
return iterateTransactionBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
return ripple::dbHasSpace(session, config, j_);
});
}
/* else return true */
return true;
}
std::uint32_t
@@ -1482,7 +1709,9 @@ RelationalDBInterfaceSqliteImp::getKBUsedAll()
return ripple::getKBUsedAll(lgrdb_->getSession());
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::uint32_t sum = 0;
iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -1490,6 +1719,10 @@ RelationalDBInterfaceSqliteImp::getKBUsedAll()
return true;
});
return sum;
}
/* else return zero */
return 0;
}
std::uint32_t
@@ -1501,7 +1734,9 @@ RelationalDBInterfaceSqliteImp::getKBUsedLedger()
return ripple::getKBUsedDB(lgrdb_->getSession());
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardLedger())
{
std::uint32_t sum = 0;
iterateLedgerBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -1509,6 +1744,10 @@ RelationalDBInterfaceSqliteImp::getKBUsedLedger()
return true;
});
return sum;
}
/* else return zero */
return 0;
}
std::uint32_t
@@ -1520,7 +1759,9 @@ RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
return ripple::getKBUsedDB(txdb_->getSession());
}
/* else use shard databases */
/* else use shard databases, if available */
if (existsShardTransaction())
{
std::uint32_t sum = 0;
iterateTransactionBack(
{}, [&](soci::session& session, std::uint32_t shardIndex) {
@@ -1528,6 +1769,10 @@ RelationalDBInterfaceSqliteImp::getKBUsedTransaction()
return true;
});
return sum;
}
/* else return zero */
return 0;
}
void

View File

@@ -798,7 +798,11 @@ transactionsSQL(
* @param j Journal.
* @return Vector of pairs of found transactions and its metadata
* sorted in given order by account sequence.
* Also number of transactions processed.
* Also the number of transactions processed or skipped.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
static std::pair<RelationalDBInterface::AccountTxs, int>
getAccountTxs(
@@ -937,7 +941,11 @@ getNewestAccountTxs(
* @param j Journal.
* @return Vector of tuples of found transactions, its metadata and
* account sequences sorted in given order by account
* sequence. Also number of transactions processed.
* sequence. Also number of transactions processed or skipped.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
* offset is > 0 in the options structure.
*/
static std::pair<std::vector<RelationalDBInterface::txnMetaLedgerType>, int>
getAccountTxsB(