rippled
Loading...
Searching...
No Matches
SQLiteDatabase.h
1#pragma once
2
3#include <xrpl/rdb/RelationalDatabase.h>
4
5#include <memory>
6
7namespace xrpl {
8
9class Config;
10class JobQueue;
11class ServiceRegistry;
12
14{
15public:
22 getMinLedgerSeq() override;
23
30 getMaxLedgerSeq() override;
31
38 getLedgerInfoByIndex(LedgerIndex ledgerSeq) override;
39
45 getNewestLedgerInfo() override;
46
54 getLedgerInfoByHash(uint256 const& ledgerHash) override;
55
63 getHashByIndex(LedgerIndex ledgerIndex) override;
64
73 getHashesByIndex(LedgerIndex ledgerIndex) override;
74
85 getHashesByIndex(LedgerIndex minSeq, LedgerIndex maxSeq) override;
86
95 getTxHistory(LedgerIndex startIndex) override;
96
104
112
118 void
119 deleteTransactionByLedgerSeq(LedgerIndex ledgerSeq) override;
120
126 void
127 deleteBeforeLedgerSeq(LedgerIndex ledgerSeq) override;
128
135 void
137
144 void
146
152 getTransactionCount() override;
153
161
169 getLedgerCountMinMax() override;
170
177 bool
178 saveValidatedLedger(std::shared_ptr<Ledger const> const& ledger, bool current) override;
179
188 getLimitedOldestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
189
198 getLimitedNewestLedgerInfo(LedgerIndex ledgerFirstIndex) override;
199
212 getOldestAccountTxs(AccountTxOptions const& options) override;
213
226 getNewestAccountTxs(AccountTxOptions const& options) override;
227
240 getOldestAccountTxsB(AccountTxOptions const& options) override;
241
255 getNewestAccountTxsB(AccountTxOptions const& options) override;
256
270 oldestAccountTxPage(AccountTxPageOptions const& options) override;
271
285 newestAccountTxPage(AccountTxPageOptions const& options) override;
286
301 oldestAccountTxPageB(AccountTxPageOptions const& options) override;
302
317 newestAccountTxPageB(AccountTxPageOptions const& options) override;
318
336 override;
337
343 getKBUsedAll() override;
344
351 getKBUsedLedger() override;
352
359 getKBUsedTransaction() override;
360
364 void
365 closeLedgerDB() override;
366
370 void
371 closeTransactionDB() override;
372
373 SQLiteDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
374
376 SQLiteDatabase(SQLiteDatabase&& rhs) noexcept;
377
379 operator=(SQLiteDatabase const&) = delete;
381 operator=(SQLiteDatabase&& rhs) = delete;
382
389 bool
390 ledgerDbHasSpace(Config const& config);
391
398 bool
399 transactionDbHasSpace(Config const& config);
400
401private:
403 bool const useTxTables_;
406
415 bool
417 Config const& config,
418 DatabaseCon::Setup const& setup,
419 DatabaseCon::CheckpointerSetup const& checkpointerSetup);
420
425 bool
427 {
428 return static_cast<bool>(ledgerDb_);
429 }
430
436 bool
438 {
439 return static_cast<bool>(txdb_);
440 }
441
447 auto
449 {
450 return ledgerDb_->checkoutDb();
451 }
452
458 auto
460 {
461 return txdb_->checkoutDb();
462 }
463};
464
473SQLiteDatabase
474setup_RelationalDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue);
475
476} // 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 ...
std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq) override
getLedgerInfoByIndex Returns a ledger by its sequence.
SQLiteDatabase(SQLiteDatabase const &)=delete
SQLiteDatabase & operator=(SQLiteDatabase &&rhs)=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