rippled
Loading...
Searching...
No Matches
SQLiteDatabase.h
1#pragma once
2
3#include <xrpl/rdb/RelationalDatabase.h>
4
5#include <map>
6#include <memory>
7#include <optional>
8#include <variant>
9#include <vector>
10
11namespace xrpl {
12
13class Config;
14class JobQueue;
15class ServiceRegistry;
16
18{
19public:
26 getMinLedgerSeq() override;
27
34 getMaxLedgerSeq() override;
35
42 getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
43
49 getNewestLedgerInfo() override;
50
58 getLedgerInfoByHash(uint256 const& ledgerHash) override;
59
67 getHashByIndex(LedgerIndex ledgerIndex) override;
68
77 getHashesByIndex(LedgerIndex ledgerIndex) override;
78
89 getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
90
99 getTxHistory(LedgerIndex startIndex) override;
100
108
116
122 void
123 deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
124
130 void
131 deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
132
139 void
141
148 void
150
156 getTransactionCount() override;
157
165
173 getLedgerCountMinMax() override;
174
181 bool
182 saveValidatedLedger(std::shared_ptr<Ledger const> const& ledger, bool current) override;
183
192 getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
193
202 getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
203
216 getOldestAccountTxs(AccountTxOptions const& options) override;
217
230 getNewestAccountTxs(AccountTxOptions const& options) override;
231
244 getOldestAccountTxsB(AccountTxOptions const& options) override;
245
259 getNewestAccountTxsB(AccountTxOptions const& options) override;
260
274 oldestAccountTxPage(AccountTxPageOptions const& options) override;
275
289 newestAccountTxPage(AccountTxPageOptions const& options) override;
290
305 oldestAccountTxPageB(AccountTxPageOptions const& options) override;
306
321 newestAccountTxPageB(AccountTxPageOptions const& options) override;
322
340 override;
341
347 getKBUsedAll() override;
348
355 getKBUsedLedger() override;
356
363 getKBUsedTransaction() override;
364
368 void
369 closeLedgerDB() override;
370
374 void
375 closeTransactionDB() override;
376
377 SQLiteDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
378
380 SQLiteDatabase(SQLiteDatabase&& rhs) noexcept;
381
383 operator=(SQLiteDatabase const&) = delete;
386
393 bool
394 ledgerDbHasSpace(Config const& config);
395
402 bool
403 transactionDbHasSpace(Config const& config);
404
405private:
410
419 bool
421 Config const& config,
422 DatabaseCon::Setup const& setup,
423 DatabaseCon::CheckpointerSetup const& checkpointerSetup);
424
429 bool
431 {
432 return static_cast<bool>(ledgerDb_);
433 }
434
440 bool
442 {
443 return static_cast<bool>(txdb_);
444 }
445
451 auto
453 {
454 return ledgerDb_->checkoutDb();
455 }
456
462 auto
464 {
465 return txdb_->checkoutDb();
466 }
467};
468
479SQLiteDatabase
480setup_RelationalDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
481
482} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
A pool of threads to perform work.
Definition JobQueue.h:37
bool existsLedger()
existsLedger Checks if the node store ledger database exists.
uint256 getHashByIndex(LedgerIndex ledgerIndex) override
getHashByIndex Returns the hash of the ledger with the given sequence.
MetaTxsList getNewestAccountTxsB(AccountTxOptions const &options) override
getNewestAccountTxsB Returns the newest transactions in binary form for the account that matches the ...
bool ledgerDbHasSpace(Config const &config)
ledgerDbHasSpace Checks if the ledger database has available space.
auto checkoutTransaction()
checkoutTransaction Checks out and returns the node store transaction database.
void deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionByLedgerSeq Deletes transactions from the ledger with the given sequence.
std::optional< LedgerHeader > getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedOldestLedgerInfo Returns the info of the oldest ledger whose sequence number is greater tha...
bool makeLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeLedgerDBs Opens ledger and transaction databases for the node store, and stores their descriptors...
std::vector< std::shared_ptr< Transaction > > getTxHistory(LedgerIndex startIndex) override
getTxHistory Returns the 20 most recent transactions starting from the given number.
AccountTxs getOldestAccountTxs(AccountTxOptions const &options) override
getOldestAccountTxs Returns the oldest transactions for the account that matches the given criteria s...
void closeTransactionDB() override
Closes the transaction database.
auto checkoutLedger()
checkoutTransaction Checks out and returns node store ledger database.
void closeLedgerDB() override
Closes the ledger database.
SQLiteDatabase & operator=(SQLiteDatabase const &)=delete
std::optional< LedgerHeader > getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override
getLimitedNewestLedgerInfo Returns the info of the newest ledger whose sequence number is greater tha...
CountMinMax getLedgerCountMinMax() override
getLedgerCountMinMax Returns the minimum ledger sequence, maximum ledger sequence and total number of...
std::unique_ptr< DatabaseCon > txdb_
MetaTxsList getOldestAccountTxsB(AccountTxOptions const &options) override
getOldestAccountTxsB Returns the oldest transactions in binary form for the account that matches the ...
bool saveValidatedLedger(std::shared_ptr< Ledger const > const &ledger, bool current) override
saveValidatedLedger Saves a ledger into the database.
std::optional< LedgerIndex > getMaxLedgerSeq() override
getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.
std::optional< LedgerIndex > getMinLedgerSeq() override
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
std::uint32_t getKBUsedTransaction() override
getKBUsedTransaction Returns the amount of space used by the transaction database.
std::uint32_t getKBUsedLedger() override
getKBUsedLedger Returns the amount of space space used by the ledger database.
AccountTxs getNewestAccountTxs(AccountTxOptions const &options) override
getNewestAccountTxs Returns the newest transactions for the account that matches the given criteria s...
void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with a sequence number less...
std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq() override
getAccountTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the AccountTransacti...
std::size_t getAccountTransactionCount() override
getAccountTransactionCount Returns the number of account transactions.
bool existsTransaction()
existsTransaction Checks if the node store transaction database exists.
std::pair< AccountTxs, std::optional< AccountTxMarker > > newestAccountTxPage(AccountTxPageOptions const &options) override
newestAccountTxPage Returns the newest transactions for the account that matches the given criteria s...
std::pair< MetaTxsList, std::optional< AccountTxMarker > > oldestAccountTxPageB(AccountTxPageOptions const &options) override
oldestAccountTxPageB Returns the oldest transactions in binary form for the account that matches the ...
void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteTransactionsBeforeLedgerSeq Deletes all transactions with a sequence number less than or equal ...
std::unique_ptr< DatabaseCon > ledgerDb_
std::optional< LedgerHeader > getLedgerInfoByHash(uint256 const &ledgerHash) override
getLedgerInfoByHash Returns the info of the ledger with given hash.
std::optional< LedgerHeader > getNewestLedgerInfo() override
getNewestLedgerInfo Returns the info of the newest saved ledger.
void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override
deleteBeforeLedgerSeq Deletes all ledgers with a sequence number less than or equal to the given ledg...
std::uint32_t getKBUsedAll() override
getKBUsedAll Returns the amount of space used by all databases.
std::size_t getTransactionCount() override
getTransactionCount Returns the number of transactions.
ServiceRegistry & registry_
std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex) override
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
std::variant< AccountTx, TxSearched > getTransaction(uint256 const &id, std::optional< ClosedInterval< std::uint32_t > > const &range, error_code_i &ec) override
getTransaction Returns the transaction with the given hash.
std::optional< LedgerIndex > getTransactionsMinLedgerSeq() override
getTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the Transactions table.
std::pair< AccountTxs, std::optional< AccountTxMarker > > oldestAccountTxPage(AccountTxPageOptions const &options) override
oldestAccountTxPage Returns the oldest transactions for the account that matches the given criteria s...
bool transactionDbHasSpace(Config const &config)
transactionDbHasSpace Checks if the transaction database has available space.
std::pair< MetaTxsList, std::optional< AccountTxMarker > > newestAccountTxPageB(AccountTxPageOptions const &options) override
newestAccountTxPageB Returns the newest transactions in binary form for the account that matches the ...
SQLiteDatabase & operator=(SQLiteDatabase &&)=delete
std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns a ledger by its sequence.
SQLiteDatabase(SQLiteDatabase const &)=delete
Service registry for dependency injection.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:34
@ current
This was a new validation and was added.
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:25
SQLiteDatabase setup_RelationalDatabase(ServiceRegistry &registry, Config const &config, JobQueue &jobQueue)
setup_RelationalDatabase Creates and returns a SQLiteDatabase instance based on configuration.
error_code_i
Definition ErrorCodes.h:20