Skip to content

Commit e51bcb4

Browse files
committed
fixup
1 parent 2ce12d4 commit e51bcb4

File tree

7 files changed

+126
-53
lines changed

7 files changed

+126
-53
lines changed

src/ripple/app/ledger/Ledger.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,20 @@ saveValidatedLedger(
10111011
return true;
10121012
}
10131013

1014+
if (app.config().RELATIONAL_DB == 0)
1015+
{
1016+
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
1017+
if (!db)
1018+
Throw<std::runtime_error>("Failed to get relational database");
1019+
1020+
auto const res = db->saveValidatedLedger(ledger, current);
1021+
// Clients can now trust the database for
1022+
// information about this ledger sequence.
1023+
1024+
app.pendingSaves().finishWork(seq);
1025+
return res;
1026+
}
1027+
10141028
auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());
10151029
if (!db)
10161030
Throw<std::runtime_error>("Failed to get relational database");

src/ripple/app/misc/SHAMapStoreImp.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,51 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
635635
if (healthWait() == stopping)
636636
return;
637637

638+
if (app_.config().RELATIONAL_DB == 0)
639+
{
640+
641+
SQLiteDatabase* const db =
642+
dynamic_cast<SQLiteDatabase*>(&app_.getRelationalDatabase());
643+
644+
if (!db)
645+
Throw<std::runtime_error>("Failed to get relational database");
646+
647+
clearSql(
648+
lastRotated,
649+
"Ledgers",
650+
[db]() -> std::optional<LedgerIndex> { return db->getMinLedgerSeq(); },
651+
[db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); });
652+
if (healthWait() == stopping)
653+
return;
654+
655+
if (!app_.config().useTxTables())
656+
return;
657+
658+
clearSql(
659+
lastRotated,
660+
"Transactions",
661+
[&db]() -> std::optional<LedgerIndex> {
662+
return db->getTransactionsMinLedgerSeq();
663+
},
664+
[&db](LedgerIndex min) -> void {
665+
db->deleteTransactionsBeforeLedgerSeq(min);
666+
});
667+
if (healthWait() == stopping)
668+
return;
669+
670+
clearSql(
671+
lastRotated,
672+
"AccountTransactions",
673+
[&db]() -> std::optional<LedgerIndex> {
674+
return db->getAccountTransactionsMinLedgerSeq();
675+
},
676+
[&db](LedgerIndex min) -> void {
677+
db->deleteAccountTransactionsBeforeLedgerSeq(min);
678+
});
679+
if (healthWait() == stopping)
680+
return;
681+
}
682+
638683
LMDBDatabase* const db =
639684
dynamic_cast<LMDBDatabase*>(&app_.getRelationalDatabase());
640685

src/ripple/app/misc/impl/Transaction.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,20 @@ Transaction::load(
163163
std::optional<ClosedInterval<uint32_t>> const& range,
164164
error_code_i& ec)
165165
{
166-
auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());
166+
167+
if (app.config().RELATIONAL_DB == 0)
168+
{
169+
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
170+
171+
if (!db)
172+
{
173+
Throw<std::runtime_error>("Failed to get relational database");
174+
}
175+
176+
return db->getTransaction(id, range, ec);
177+
}
178+
179+
auto const db = dynamic_cast<LMDBDatabase*>(&app.getRelationalDatabase());
167180

168181
if (!db)
169182
{

src/ripple/app/rdb/backend/detail/impl/Node.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ makeLedgerDBs(
150150
DatabaseCon::CheckpointerSetup const& checkpointerSetup)
151151
{
152152
if (setup.sqlite3)
153+
{
153154
return makeSQLLedgerDBs(config, setup, checkpointerSetup);
155+
}
154156

155157
return makeLMDBLedgerDBs(config, setup, checkpointerSetup);
156158
}
157159

158160
std::optional<LedgerIndex>
159-
getMinLedgerSeq(MDB_env* env, TableType type)
161+
getMinLedgerSeq(MDB_env *env, TableType type)
160162
{
161163
MDB_txn* txn;
162164
MDB_dbi dbi;
@@ -182,7 +184,7 @@ getMinLedgerSeq(MDB_env* env, TableType type)
182184
}
183185

184186
std::optional<LedgerIndex>
185-
getMaxLedgerSeq(MDB_env* env, TableType type)
187+
getMaxLedgerSeq(MDB_env *env, TableType type)
186188
{
187189
MDB_txn* txn;
188190
MDB_dbi dbi;
@@ -208,7 +210,7 @@ getMaxLedgerSeq(MDB_env* env, TableType type)
208210
}
209211

210212
void
211-
deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
213+
deleteByLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq)
212214
{
213215
MDB_txn* txn;
214216
MDB_dbi dbi;
@@ -227,7 +229,7 @@ deleteByLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
227229
}
228230

229231
void
230-
deleteBeforeLedgerSeq(MDB_env* env, TableType type, LedgerIndex ledgerSeq)
232+
deleteBeforeLedgerSeq(MDB_env *env, TableType type, LedgerIndex ledgerSeq)
231233
{
232234
MDB_txn* txn;
233235
MDB_dbi dbi;
@@ -294,7 +296,7 @@ deleteBeforeLedgerSeq(
294296
}
295297

296298
std::size_t
297-
getRows(MDB_env* env, TableType type)
299+
getRows(MDB_env *env, TableType type)
298300
{
299301
MDB_txn* txn;
300302
MDB_dbi dbi;
@@ -323,7 +325,7 @@ getRows(MDB_env* env, TableType type)
323325
}
324326

325327
RelationalDatabase::CountMinMax
326-
getRowsMinMax(MDB_env* env, TableType type)
328+
getRowsMinMax(MDB_env *env, TableType type)
327329
{
328330
MDB_txn* txn;
329331
MDB_dbi dbi;
@@ -455,7 +457,7 @@ saveLMDBValidatedLedger(
455457
MDB_dbi dbi;
456458
MDB_txn* txn;
457459
auto db = ldgDB.checkoutLMDB();
458-
MDB_env* env = db.get();
460+
MDB_env *env = db.get();
459461
mdb_txn_begin(env, nullptr, 0, &txn);
460462
try
461463
{
@@ -538,7 +540,7 @@ saveLMDBValidatedLedger(
538540
MDB_dbi dbi;
539541
MDB_txn* txn;
540542
auto db = ldgDB.checkoutLMDB();
541-
MDB_env* env = db.get();
543+
MDB_env *env = db.get();
542544
mdb_txn_begin(env, nullptr, 0, &txn);
543545

544546
try
@@ -797,7 +799,7 @@ saveValidatedLedger(
797799

798800
// Function to get the ledger info from the LMDB database
799801
static std::optional<LedgerInfo>
800-
getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j)
802+
getLedgerInfo(MDB_env *env, std::string const& key, beast::Journal j)
801803
{
802804
MDB_txn* txn;
803805
MDB_dbi dbi;
@@ -842,15 +844,15 @@ getLedgerInfo(MDB_env* env, std::string const& key, beast::Journal j)
842844
}
843845

844846
std::optional<LedgerInfo>
845-
getLedgerInfoByIndex(MDB_env* env, LedgerIndex ledgerSeq, beast::Journal j)
847+
getLedgerInfoByIndex(MDB_env *env, LedgerIndex ledgerSeq, beast::Journal j)
846848
{
847849
std::ostringstream s;
848850
s << "LedgerSeq_" << ledgerSeq;
849851
return getLedgerInfo(env, s.str(), j);
850852
}
851853

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

862864
std::optional<LedgerInfo>
863865
getLimitedOldestLedgerInfo(
864-
MDB_env* env,
866+
MDB_env *env,
865867
LedgerIndex ledgerFirstIndex,
866868
beast::Journal j)
867869
{
@@ -873,7 +875,7 @@ getLimitedOldestLedgerInfo(
873875

874876
std::optional<LedgerInfo>
875877
getLimitedNewestLedgerInfo(
876-
MDB_env* env,
878+
MDB_env *env,
877879
LedgerIndex ledgerFirstIndex,
878880
beast::Journal j)
879881
{
@@ -884,7 +886,7 @@ getLimitedNewestLedgerInfo(
884886
}
885887

886888
std::optional<LedgerInfo>
887-
getLedgerInfoByHash(MDB_env* env, uint256 const& ledgerHash, beast::Journal j)
889+
getLedgerInfoByHash(MDB_env *env, uint256 const& ledgerHash, beast::Journal j)
888890
{
889891
std::ostringstream s;
890892
s << "LedgerHash_" << ledgerHash;
@@ -1024,7 +1026,7 @@ getLedgerInfoByHash(
10241026
}
10251027

10261028
uint256
1027-
getHashByIndex(MDB_env* env, LedgerIndex ledgerIndex)
1029+
getHashByIndex(MDB_env *env, LedgerIndex ledgerIndex)
10281030
{
10291031
uint256 ret;
10301032
MDB_txn* txn;
@@ -1098,7 +1100,7 @@ getHashByIndex(soci::session& session, LedgerIndex ledgerIndex)
10981100
}
10991101

11001102
std::optional<LedgerHashPair>
1101-
getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j)
1103+
getHashesByIndex(MDB_env *env, LedgerIndex ledgerIndex, beast::Journal j)
11021104
{
11031105
MDB_txn* txn;
11041106
MDB_dbi dbi;
@@ -1158,7 +1160,7 @@ getHashesByIndex(MDB_env* env, LedgerIndex ledgerIndex, beast::Journal j)
11581160

11591161
std::map<LedgerIndex, LedgerHashPair>
11601162
getHashesByIndex(
1161-
MDB_env* env,
1163+
MDB_env *env,
11621164
LedgerIndex minSeq,
11631165
LedgerIndex maxSeq,
11641166
beast::Journal j)
@@ -1982,7 +1984,7 @@ newestAccountTxPage(
19821984

19831985
std::variant<RelationalDatabase::AccountTx, TxSearched>
19841986
getTransaction(
1985-
MDB_env* env,
1987+
MDB_env *env,
19861988
Application& app,
19871989
uint256 const& id,
19881990
std::optional<ClosedInterval<uint32_t>> const& range,
@@ -2185,7 +2187,7 @@ getTransaction(
21852187
}
21862188

21872189
bool
2188-
dbHasSpace(MDB_env* env, Config const& config, beast::Journal j)
2190+
dbHasSpace(MDB_env *env, Config const& config, beast::Journal j)
21892191
{
21902192
boost::filesystem::space_info space =
21912193
boost::filesystem::space(config.legacy("database_path"));

src/ripple/app/rdb/impl/RelationalDatabase.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,37 @@ RelationalDatabase::init(
4141
{
4242
bool use_sqlite = false;
4343
bool use_postgres = false;
44-
bool use_lmdb = false;
44+
bool use_lmdb = true;
4545

46-
if (config.reporting())
47-
{
48-
use_postgres = true;
49-
}
50-
else
51-
{
52-
const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)};
53-
if (!rdb_section.empty())
54-
{
55-
if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
56-
{
57-
use_sqlite = true;
58-
}
59-
else if (boost::iequals(get(rdb_section, "backend"), "lmdb"))
60-
{
61-
use_lmdb = true;
62-
}
63-
else
64-
{
65-
Throw<std::runtime_error>(
66-
"Invalid rdb_section backend value: " +
67-
get(rdb_section, "backend"));
68-
}
69-
}
70-
else
71-
{
72-
use_sqlite = true;
73-
}
74-
}
46+
// if (config.reporting())
47+
// {
48+
// use_postgres = true;
49+
// }
50+
// else
51+
// {
52+
// const Section& rdb_section{config.section(SECTION_RELATIONAL_DB)};
53+
// if (!rdb_section.empty())
54+
// {
55+
// if (boost::iequals(get(rdb_section, "backend"), "sqlite"))
56+
// {
57+
// use_sqlite = true;
58+
// }
59+
// else if (boost::iequals(get(rdb_section, "backend"), "lmdb"))
60+
// {
61+
// use_lmdb = true;
62+
// }
63+
// else
64+
// {
65+
// Throw<std::runtime_error>(
66+
// "Invalid rdb_section backend value: " +
67+
// get(rdb_section, "backend"));
68+
// }
69+
// }
70+
// else
71+
// {
72+
// use_sqlite = true;
73+
// }
74+
// }
7575

7676
if (use_sqlite)
7777
{

src/ripple/core/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Config : public BasicConfig
169169

170170
std::string START_LEDGER;
171171

172-
uint32_t RELATIONAL_DB = 0; // 0 == SQLite, 1 == LMDB
172+
uint32_t RELATIONAL_DB = 1; // 0 == SQLite, 1 == LMDB
173173

174174
// Network parameters
175175
uint32_t NETWORK_ID = 0;

src/ripple/core/impl/DatabaseCon.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ setup_DatabaseCon(Config const& c, std::optional<beast::Journal> j)
110110
setup.startUp = c.START_UP;
111111
setup.standAlone = c.standalone();
112112
setup.reporting = c.reporting();
113-
std::cout << c.RELATIONAL_DB;
114-
setup.sqlite3 = true;
113+
setup.sqlite3 = false;
115114
setup.dataDir = c.legacy("database_path");
116115
if (!setup.standAlone && setup.dataDir.empty())
117116
{

0 commit comments

Comments
 (0)