22#include "data/BackendInterface.hpp"
24#include "data/LedgerCacheInterface.hpp"
25#include "data/LedgerHeaderCache.hpp"
26#include "data/Types.hpp"
27#include "data/cassandra/Concepts.hpp"
28#include "data/cassandra/Handle.hpp"
29#include "data/cassandra/Types.hpp"
30#include "data/cassandra/impl/ExecutionStrategy.hpp"
31#include "util/Assert.hpp"
32#include "util/LedgerUtils.hpp"
33#include "util/Profiler.hpp"
34#include "util/log/Logger.hpp"
36#include <boost/asio/spawn.hpp>
37#include <boost/json/object.hpp>
38#include <boost/uuid/string_generator.hpp>
39#include <boost/uuid/uuid.hpp>
41#include <fmt/format.h>
42#include <xrpl/basics/Blob.h>
43#include <xrpl/basics/base_uint.h>
44#include <xrpl/basics/strHex.h>
45#include <xrpl/protocol/AccountID.h>
46#include <xrpl/protocol/Indexes.h>
47#include <xrpl/protocol/LedgerHeader.h>
48#include <xrpl/protocol/nft.h>
64class CacheBackendCassandraTest;
87 SettingsProviderType settingsProvider_;
89 std::atomic_uint32_t ledgerSequence_ = 0u;
90 friend class ::CacheBackendCassandraTest;
95 mutable ExecutionStrategyType executor_;
97 mutable FetchLedgerCacheType ledgerCache_{};
109 , settingsProvider_{std::move(settingsProvider)}
110 , schema_{settingsProvider_}
111 , handle_{settingsProvider_.getSettings()}
112 , executor_{settingsProvider_.getSettings(), handle_}
114 if (
auto const res = handle_.connect(); not res.has_value())
115 throw std::runtime_error(
"Could not connect to database: " + res.error());
118 if (
auto const res = handle_.execute(schema_.createKeyspace); not res.has_value()) {
121 if (res.error().code() != CASS_ERROR_SERVER_UNAUTHORIZED)
122 throw std::runtime_error(
"Could not create keyspace: " + res.error());
125 if (
auto const res = handle_.executeEach(schema_.createSchema); not res.has_value())
126 throw std::runtime_error(
"Could not create schema: " + res.error());
130 schema_.prepareStatements(handle_);
131 }
catch (std::runtime_error
const& ex) {
132 auto const error = fmt::format(
133 "Failed to prepare the statements: {}; readOnly: {}. ReadOnly should be turned off or another Clio "
134 "node with write access to DB should be started first.",
138 LOG(log_.error()) << error;
139 throw std::runtime_error(error);
141 LOG(log_.info()) <<
"Created (revamped) CassandraBackend";
151 ripple::AccountID
const& account,
152 std::uint32_t
const limit,
154 std::optional<TransactionsCursor>
const& txnCursor,
155 boost::asio::yield_context yield
160 return {.txns = {}, .cursor = {}};
162 Statement
const statement = [
this, forward, &account]() {
164 return schema_->selectAccountTxForward.bind(account);
166 return schema_->selectAccountTx.bind(account);
169 auto cursor = txnCursor;
171 statement.
bindAt(1, cursor->asTuple());
172 LOG(log_.debug()) <<
"account = " << ripple::strHex(account) <<
" tuple = " << cursor->ledgerSequence
173 << cursor->transactionIndex;
175 auto const seq = forward ? rng->minSequence : rng->maxSequence;
176 auto const placeHolder = forward ? 0u : std::numeric_limits<std::uint32_t>::max();
178 statement.
bindAt(1, std::make_tuple(placeHolder, placeHolder));
179 LOG(log_.debug()) <<
"account = " << ripple::strHex(account) <<
" idx = " << seq
180 <<
" tuple = " << placeHolder;
187 auto const res = executor_.read(yield, statement);
188 auto const& results = res.value();
189 if (not results.hasRows()) {
190 LOG(log_.debug()) <<
"No rows returned";
194 std::vector<ripple::uint256> hashes = {};
195 auto numRows = results.numRows();
196 LOG(log_.info()) <<
"num_rows = " << numRows;
198 for (
auto [hash,
data] :
extract<ripple::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
199 hashes.push_back(hash);
200 if (--numRows == 0) {
201 LOG(log_.debug()) <<
"Setting cursor";
207 LOG(log_.debug()) <<
"Txns = " << txns.size();
209 if (txns.size() == limit) {
210 LOG(log_.debug()) <<
"Returning cursor";
211 return {txns, cursor};
224 writeLedger(ripple::LedgerHeader
const& ledgerHeader, std::string&& blob)
override
226 executor_.write(schema_->insertLedgerHeader, ledgerHeader.seq, std::move(blob));
228 executor_.write(schema_->insertLedgerHash, ledgerHeader.hash, ledgerHeader.seq);
230 ledgerSequence_ = ledgerHeader.seq;
233 std::optional<std::uint32_t>
236 if (
auto const res = executor_.read(yield, schema_->selectLatestLedger); res.has_value()) {
237 if (
auto const& rows = *res; rows) {
238 if (
auto const maybeRow = rows.template get<uint32_t>(); maybeRow.has_value())
241 LOG(log_.error()) <<
"Could not fetch latest ledger - no rows";
245 LOG(log_.error()) <<
"Could not fetch latest ledger - no result";
247 LOG(log_.error()) <<
"Could not fetch latest ledger: " << res.error();
253 std::optional<ripple::LedgerHeader>
256 if (
auto const lock = ledgerCache_.get(); lock.has_value() && lock->seq == sequence)
259 auto const res = executor_.read(yield, schema_->selectLedgerBySeq, sequence);
261 if (
auto const& result = res.value(); result) {
262 if (
auto const maybeValue = result.template get<std::vector<unsigned char>>(); maybeValue) {
268 LOG(log_.error()) <<
"Could not fetch ledger by sequence - no rows";
272 LOG(log_.error()) <<
"Could not fetch ledger by sequence - no result";
274 LOG(log_.error()) <<
"Could not fetch ledger by sequence: " << res.error();
280 std::optional<ripple::LedgerHeader>
283 if (
auto const res = executor_.read(yield, schema_->selectLedgerByHash, hash); res) {
284 if (
auto const& result = res.value(); result) {
285 if (
auto const maybeValue = result.template get<uint32_t>(); maybeValue)
288 LOG(log_.error()) <<
"Could not fetch ledger by hash - no rows";
292 LOG(log_.error()) <<
"Could not fetch ledger by hash - no result";
294 LOG(log_.error()) <<
"Could not fetch ledger by hash: " << res.error();
300 std::optional<LedgerRange>
303 auto const res = executor_.read(yield, schema_->selectLedgerRange);
305 auto const& results = res.value();
306 if (not results.hasRows()) {
307 LOG(log_.debug()) <<
"Could not fetch ledger range - no rows";
318 range.maxSequence = range.minSequence = seq;
319 }
else if (idx == 1) {
320 range.maxSequence = seq;
326 if (range.minSequence > range.maxSequence)
327 std::swap(range.minSequence, range.maxSequence);
329 LOG(log_.debug()) <<
"After hardFetchLedgerRange range is " << range.minSequence <<
":"
330 << range.maxSequence;
333 LOG(log_.error()) <<
"Could not fetch ledger range: " << res.error();
338 std::vector<TransactionAndMetadata>
345 std::vector<ripple::uint256>
347 std::uint32_t
const ledgerSequence,
348 boost::asio::yield_context yield
351 auto start = std::chrono::system_clock::now();
352 auto const res = executor_.read(yield, schema_->selectAllTransactionHashesInLedger, ledgerSequence);
355 LOG(log_.error()) <<
"Could not fetch all transaction hashes: " << res.error();
359 auto const& result = res.value();
360 if (not result.hasRows()) {
361 LOG(log_.warn()) <<
"Could not fetch all transaction hashes - no rows; ledger = "
362 << std::to_string(ledgerSequence);
366 std::vector<ripple::uint256> hashes;
368 hashes.push_back(std::move(hash));
370 auto end = std::chrono::system_clock::now();
371 LOG(log_.debug()) <<
"Fetched " << hashes.size() <<
" transaction hashes from database in "
372 << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
380 ripple::uint256
const& tokenID,
381 std::uint32_t
const ledgerSequence,
382 boost::asio::yield_context yield
385 auto const res = executor_.read(yield, schema_->selectNFT, tokenID, ledgerSequence);
389 if (
auto const maybeRow = res->template get<uint32_t, ripple::AccountID, bool>(); maybeRow) {
390 auto [seq, owner, isBurned] = *maybeRow;
391 auto result = std::make_optional<NFT>(tokenID, seq, owner, isBurned);
404 auto uriRes = executor_.read(yield, schema_->selectNFTURI, tokenID, ledgerSequence);
406 if (
auto const maybeUri = uriRes->template get<ripple::Blob>(); maybeUri)
407 result->uri = *maybeUri;
413 LOG(log_.error()) <<
"Could not fetch NFT - no rows";
419 ripple::uint256
const& tokenID,
420 std::uint32_t
const limit,
422 std::optional<TransactionsCursor>
const& cursorIn,
423 boost::asio::yield_context yield
428 return {.txns = {}, .cursor = {}};
430 Statement
const statement = [
this, forward, &tokenID]() {
432 return schema_->selectNFTTxForward.bind(tokenID);
434 return schema_->selectNFTTx.bind(tokenID);
437 auto cursor = cursorIn;
439 statement.
bindAt(1, cursor->asTuple());
440 LOG(log_.debug()) <<
"token_id = " << ripple::strHex(tokenID) <<
" tuple = " << cursor->ledgerSequence
441 << cursor->transactionIndex;
443 auto const seq = forward ? rng->minSequence : rng->maxSequence;
444 auto const placeHolder = forward ? 0 : std::numeric_limits<std::uint32_t>::max();
446 statement.
bindAt(1, std::make_tuple(placeHolder, placeHolder));
447 LOG(log_.debug()) <<
"token_id = " << ripple::strHex(tokenID) <<
" idx = " << seq
448 <<
" tuple = " << placeHolder;
453 auto const res = executor_.read(yield, statement);
454 auto const& results = res.value();
455 if (not results.hasRows()) {
456 LOG(log_.debug()) <<
"No rows returned";
460 std::vector<ripple::uint256> hashes = {};
461 auto numRows = results.numRows();
462 LOG(log_.info()) <<
"num_rows = " << numRows;
464 for (
auto [hash,
data] :
extract<ripple::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
465 hashes.push_back(hash);
466 if (--numRows == 0) {
467 LOG(log_.debug()) <<
"Setting cursor";
473 ++cursor->transactionIndex;
478 LOG(log_.debug()) <<
"NFT Txns = " << txns.size();
480 if (txns.size() == limit) {
481 LOG(log_.debug()) <<
"Returning cursor";
482 return {txns, cursor};
490 ripple::uint192
const& mptID,
491 std::uint32_t
const limit,
492 std::optional<ripple::AccountID>
const& cursorIn,
493 std::uint32_t
const ledgerSequence,
494 boost::asio::yield_context yield
497 auto const holderEntries = executor_.read(
498 yield, schema_->selectMPTHolders, mptID, cursorIn.value_or(ripple::AccountID(0)),
Limit{limit}
501 auto const& holderResults = holderEntries.value();
502 if (not holderResults.hasRows()) {
503 LOG(log_.debug()) <<
"No rows returned";
507 std::vector<ripple::uint256> mptKeys;
508 std::optional<ripple::AccountID> cursor;
510 mptKeys.push_back(ripple::keylet::mptoken(mptID, holder).key);
516 auto it = std::remove_if(mptObjects.begin(), mptObjects.end(), [](Blob
const& mpt) { return mpt.empty(); });
518 mptObjects.erase(it, mptObjects.end());
520 ASSERT(mptKeys.size() <= limit,
"Number of keys can't exceed the limit");
521 if (mptKeys.size() == limit)
522 return {mptObjects, cursor};
524 return {mptObjects, {}};
529 ripple::uint256
const& key,
530 std::uint32_t
const sequence,
531 boost::asio::yield_context yield
534 LOG(log_.debug()) <<
"Fetching ledger object for seq " << sequence <<
", key = " << ripple::to_string(key);
535 if (
auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
536 if (
auto const result = res->template get<Blob>(); result) {
540 LOG(log_.debug()) <<
"Could not fetch ledger object - no rows";
543 LOG(log_.error()) <<
"Could not fetch ledger object: " << res.error();
549 std::optional<std::uint32_t>
551 ripple::uint256
const& key,
552 std::uint32_t
const sequence,
553 boost::asio::yield_context yield
556 LOG(log_.debug()) <<
"Fetching ledger object for seq " << sequence <<
", key = " << ripple::to_string(key);
557 if (
auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
558 if (
auto const result = res->template get<Blob, std::uint32_t>(); result) {
559 auto [_, seq] = result.value();
562 LOG(log_.debug()) <<
"Could not fetch ledger object sequence - no rows";
564 LOG(log_.error()) <<
"Could not fetch ledger object sequence: " << res.error();
570 std::optional<TransactionAndMetadata>
571 fetchTransaction(ripple::uint256
const& hash, boost::asio::yield_context yield)
const override
573 if (
auto const res = executor_.read(yield, schema_->selectTransaction, hash); res) {
574 if (
auto const maybeValue = res->template get<Blob, Blob, uint32_t, uint32_t>(); maybeValue) {
575 auto [transaction, meta, seq, date] = *maybeValue;
576 return std::make_optional<TransactionAndMetadata>(transaction, meta, seq, date);
579 LOG(log_.debug()) <<
"Could not fetch transaction - no rows";
581 LOG(log_.error()) <<
"Could not fetch transaction: " << res.error();
587 std::optional<ripple::uint256>
590 std::uint32_t
const ledgerSequence,
591 boost::asio::yield_context yield
594 if (
auto const res = executor_.read(yield, schema_->selectSuccessor, key, ledgerSequence); res) {
595 if (
auto const result = res->template get<ripple::uint256>(); result) {
596 if (*result == kLAST_KEY)
601 LOG(log_.debug()) <<
"Could not fetch successor - no rows";
603 LOG(log_.error()) <<
"Could not fetch successor: " << res.error();
609 std::vector<TransactionAndMetadata>
610 fetchTransactions(std::vector<ripple::uint256>
const& hashes, boost::asio::yield_context yield)
const override
615 auto const numHashes = hashes.size();
616 std::vector<TransactionAndMetadata> results;
617 results.reserve(numHashes);
619 std::vector<Statement> statements;
620 statements.reserve(numHashes);
622 auto const timeDiff =
util::timed([
this, yield, &results, &hashes, &statements]() {
625 std::cbegin(hashes), std::cend(hashes), std::back_inserter(statements), [
this](
auto const& hash) {
626 return schema_->selectTransaction.bind(hash);
630 auto const entries = executor_.readEach(yield, statements);
632 std::cbegin(entries),
634 std::back_inserter(results),
636 if (
auto const maybeRow = res.template get<Blob, Blob, uint32_t, uint32_t>(); maybeRow)
644 ASSERT(numHashes == results.size(),
"Number of hashes and results must match");
645 LOG(log_.debug()) <<
"Fetched " << numHashes <<
" transactions from database in " << timeDiff
652 std::vector<ripple::uint256>
const& keys,
653 std::uint32_t
const sequence,
654 boost::asio::yield_context yield
660 auto const numKeys = keys.size();
661 LOG(log_.trace()) <<
"Fetching " << numKeys <<
" objects";
663 std::vector<Blob> results;
664 results.reserve(numKeys);
666 std::vector<Statement> statements;
667 statements.reserve(numKeys);
671 std::cbegin(keys), std::cend(keys), std::back_inserter(statements), [
this, &sequence](
auto const& key) {
672 return schema_->selectObject.bind(key, sequence);
676 auto const entries = executor_.readEach(yield, statements);
678 std::cbegin(entries), std::cend(entries), std::back_inserter(results), [](
auto const& res) -> Blob {
679 if (
auto const maybeValue = res.template get<Blob>(); maybeValue)
686 LOG(log_.trace()) <<
"Fetched " << numKeys <<
" objects";
690 std::vector<LedgerObject>
691 fetchLedgerDiff(std::uint32_t
const ledgerSequence, boost::asio::yield_context yield)
const override
693 auto const [keys, timeDiff] =
util::timed([
this, &ledgerSequence, yield]() -> std::vector<ripple::uint256> {
694 auto const res = executor_.read(yield, schema_->selectDiff, ledgerSequence);
696 LOG(log_.error()) <<
"Could not fetch ledger diff: " << res.error() <<
"; ledger = " << ledgerSequence;
700 auto const& results = res.value();
702 LOG(log_.error()) <<
"Could not fetch ledger diff - no rows; ledger = " << ledgerSequence;
706 std::vector<ripple::uint256> resultKeys;
708 resultKeys.push_back(key);
717 LOG(log_.debug()) <<
"Fetched " << keys.size() <<
" diff hashes from database in " << timeDiff
721 std::vector<LedgerObject> results;
722 results.reserve(keys.size());
728 std::back_inserter(results),
729 [](
auto const& key,
auto const& obj) {
return LedgerObject{key, obj}; }
735 std::optional<std::string>
738 auto const res = executor_.read(yield, schema_->selectMigratorStatus,
Text(migratorName));
740 LOG(log_.error()) <<
"Could not fetch migrator status: " << res.error();
744 auto const& results = res.value();
755 std::expected<std::vector<std::pair<boost::uuids::uuid, std::string>>, std::string>
758 auto const readResult = executor_.read(yield, schema_->selectClioNodesData);
760 return std::unexpected{readResult.error().message()};
762 std::vector<std::pair<boost::uuids::uuid, std::string>> result;
765 result.emplace_back(uuid, std::move(message));
774 LOG(log_.trace()) <<
" Writing ledger object " << key.size() <<
":" << seq <<
" [" << blob.size() <<
" bytes]";
777 executor_.write(schema_->insertDiff, seq, key);
779 executor_.write(schema_->insertObject, std::move(key), seq, std::move(blob));
783 writeSuccessor(std::string&& key, std::uint32_t
const seq, std::string&& successor)
override
785 LOG(log_.trace()) <<
"Writing successor. key = " << key.size() <<
" bytes. "
786 <<
" seq = " << std::to_string(seq) <<
" successor = " << successor.size() <<
" bytes.";
787 ASSERT(!key.empty(),
"Key must not be empty");
788 ASSERT(!successor.empty(),
"Successor must not be empty");
790 executor_.write(schema_->insertSuccessor, std::move(key), seq, std::move(successor));
796 std::vector<Statement> statements;
797 statements.reserve(
data.size() * 10);
799 for (
auto& record :
data) {
800 std::ranges::transform(record.accounts, std::back_inserter(statements), [
this, &record](
auto&& account) {
801 return schema_->insertAccountTx.bind(
802 std::forward<decltype(account)>(account),
803 std::make_tuple(record.ledgerSequence, record.transactionIndex),
809 executor_.write(std::move(statements));
815 std::vector<Statement> statements;
816 statements.reserve(record.accounts.size());
818 std::ranges::transform(record.accounts, std::back_inserter(statements), [
this, &record](
auto&& account) {
819 return schema_->insertAccountTx.bind(
820 std::forward<decltype(account)>(account),
821 std::make_tuple(record.ledgerSequence, record.transactionIndex),
826 executor_.write(std::move(statements));
832 std::vector<Statement> statements;
833 statements.reserve(
data.size());
835 std::ranges::transform(
data, std::back_inserter(statements), [
this](
auto const& record) {
836 return schema_->insertNFTTx.bind(
837 record.tokenID, std::make_tuple(record.ledgerSequence, record.transactionIndex), record.txHash
841 executor_.write(std::move(statements));
847 std::uint32_t
const seq,
848 std::uint32_t
const date,
849 std::string&& transaction,
850 std::string&& metadata
853 LOG(log_.trace()) <<
"Writing txn to database";
855 executor_.write(schema_->insertLedgerTransaction, seq, hash);
857 schema_->insertTransaction, std::move(hash), seq, date, std::move(transaction), std::move(metadata)
864 std::vector<Statement> statements;
865 statements.reserve(
data.size() * 3);
868 if (!record.onlyUriChanged) {
869 statements.push_back(
870 schema_->insertNFT.bind(record.tokenID, record.ledgerSequence, record.owner, record.isBurned)
879 statements.push_back(schema_->insertIssuerNFT.bind(
880 ripple::nft::getIssuer(record.tokenID),
881 static_cast<uint32_t
>(ripple::nft::getTaxon(record.tokenID)),
884 statements.push_back(
885 schema_->insertNFTURI.bind(record.tokenID, record.ledgerSequence, record.uri.value())
890 statements.push_back(
891 schema_->insertNFTURI.bind(record.tokenID, record.ledgerSequence, record.uri.value())
896 executor_.writeEach(std::move(statements));
902 std::vector<Statement> statements;
903 statements.reserve(
data.size());
904 for (
auto [mptId, holder] :
data)
905 statements.push_back(schema_->insertMPTHolder.bind(mptId, holder));
907 executor_.write(std::move(statements));
928 executor_.writeSync(schema_->updateClioNodeMessage,
data::cassandra::Text{std::move(message)}, uuid);
934 return executor_.isTooBusy();
940 return executor_.stats();
953 auto const res = executor_.writeSync(statement);
954 auto maybeSuccess = res->template get<bool>();
955 if (not maybeSuccess) {
956 LOG(log_.error()) <<
"executeSyncUpdate - error getting result - no row";
960 if (not maybeSuccess.value()) {
961 LOG(log_.warn()) <<
"Update failed. Checking if DB state is what we expect";
968 return rng && rng->maxSequence == ledgerSequence_;
std::vector< Blob > fetchLedgerObjects(std::vector< ripple::uint256 > const &keys, std::uint32_t sequence, boost::asio::yield_context yield) const
Fetches all ledger objects by their keys.
Definition BackendInterface.cpp:114
BackendInterface(LedgerCacheInterface &cache)
Construct a new backend interface instance.
Definition BackendInterface.hpp:153
std::optional< LedgerRange > hardFetchLedgerRangeNoThrow() const
Fetches the ledger range from DB retrying until no DatabaseTimeout is thrown.
Definition BackendInterface.cpp:72
std::optional< LedgerRange > fetchLedgerRange() const
Fetch the current ledger range.
Definition BackendInterface.cpp:262
LedgerCacheInterface const & cache() const
Definition BackendInterface.hpp:165
A simple cache holding one ripple::LedgerHeader to reduce DB lookups.
Definition LedgerHeaderCache.hpp:41
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:38
Implements BackendInterface for Cassandra/ScyllaDB/Keyspace.
Definition CassandraBackendFamily.hpp:83
void writeMigratorStatus(std::string const &migratorName, std::string const &status) override
Mark the migration status of a migrator as Migrated in the database.
Definition CassandraBackendFamily.hpp:918
std::optional< LedgerRange > hardFetchLedgerRange(boost::asio::yield_context yield) const override
Fetches the ledger range from DB.
Definition CassandraBackendFamily.hpp:301
void startWrites() const override
Starts a write transaction with the DB. No-op for cassandra.
Definition CassandraBackendFamily.hpp:911
void doWriteLedgerObject(std::string &&key, std::uint32_t const seq, std::string &&blob) override
Writes a ledger object to the database.
Definition CassandraBackendFamily.hpp:772
std::optional< TransactionAndMetadata > fetchTransaction(ripple::uint256 const &hash, boost::asio::yield_context yield) const override
Fetches a specific transaction.
Definition CassandraBackendFamily.hpp:571
TransactionsAndCursor fetchAccountTransactions(ripple::AccountID const &account, std::uint32_t const limit, bool forward, std::optional< TransactionsCursor > const &txnCursor, boost::asio::yield_context yield) const override
Fetches all transactions for a specific account.
Definition CassandraBackendFamily.hpp:150
MPTHoldersAndCursor fetchMPTHolders(ripple::uint192 const &mptID, std::uint32_t const limit, std::optional< ripple::AccountID > const &cursorIn, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches all holders' balances for a MPTIssuanceID.
Definition CassandraBackendFamily.hpp:489
void writeNFTs(std::vector< NFTsData > const &data) override
Writes NFTs to the database.
Definition CassandraBackendFamily.hpp:862
std::optional< ripple::LedgerHeader > fetchLedgerBySequence(std::uint32_t const sequence, boost::asio::yield_context yield) const override
Fetches a specific ledger by sequence number.
Definition CassandraBackendFamily.hpp:254
void writeNFTTransactions(std::vector< NFTTransactionsData > const &data) override
Write NFTs transactions.
Definition CassandraBackendFamily.hpp:830
void writeNodeMessage(boost::uuids::uuid const &uuid, std::string message) override
Write a node message. Used by ClusterCommunicationService.
Definition CassandraBackendFamily.hpp:926
std::optional< std::uint32_t > fetchLatestLedgerSequence(boost::asio::yield_context yield) const override
Fetches the latest ledger sequence.
Definition CassandraBackendFamily.hpp:234
CassandraBackendFamily(SettingsProviderType settingsProvider, data::LedgerCacheInterface &cache, bool readOnly)
Create a new cassandra/scylla backend instance.
Definition CassandraBackendFamily.hpp:107
std::optional< ripple::LedgerHeader > fetchLedgerByHash(ripple::uint256 const &hash, boost::asio::yield_context yield) const override
Fetches a specific ledger by hash.
Definition CassandraBackendFamily.hpp:281
std::optional< std::uint32_t > doFetchLedgerObjectSeq(ripple::uint256 const &key, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching a ledger object sequence.
Definition CassandraBackendFamily.hpp:550
bool isTooBusy() const override
Definition CassandraBackendFamily.hpp:932
std::optional< NFT > fetchNFT(ripple::uint256 const &tokenID, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches a specific NFT.
Definition CassandraBackendFamily.hpp:379
void writeMPTHolders(std::vector< MPTHolderData > const &data) override
Write accounts that started holding onto a MPT.
Definition CassandraBackendFamily.hpp:900
void writeAccountTransaction(AccountTransactionsData record) override
Write a new account transaction.
Definition CassandraBackendFamily.hpp:813
void writeSuccessor(std::string &&key, std::uint32_t const seq, std::string &&successor) override
Write a new successor.
Definition CassandraBackendFamily.hpp:783
std::vector< ripple::uint256 > fetchAllTransactionHashesInLedger(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches all transaction hashes from a specific ledger.
Definition CassandraBackendFamily.hpp:346
void waitForWritesToFinish() override
Wait for all pending writes to finish.
Definition CassandraBackendFamily.hpp:218
std::vector< TransactionAndMetadata > fetchTransactions(std::vector< ripple::uint256 > const &hashes, boost::asio::yield_context yield) const override
Fetches multiple transactions.
Definition CassandraBackendFamily.hpp:610
std::vector< Blob > doFetchLedgerObjects(std::vector< ripple::uint256 > const &keys, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching ledger objects.
Definition CassandraBackendFamily.hpp:651
std::optional< ripple::uint256 > doFetchSuccessorKey(ripple::uint256 key, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Database-specific implementation of fetching the successor key.
Definition CassandraBackendFamily.hpp:588
boost::json::object stats() const override
Definition CassandraBackendFamily.hpp:938
std::optional< std::string > fetchMigratorStatus(std::string const &migratorName, boost::asio::yield_context yield) const override
Fetches the status of migrator by name.
Definition CassandraBackendFamily.hpp:736
std::expected< std::vector< std::pair< boost::uuids::uuid, std::string > >, std::string > fetchClioNodesData(boost::asio::yield_context yield) const override
Fetches the data of all nodes in the cluster.
Definition CassandraBackendFamily.hpp:756
void writeAccountTransactions(std::vector< AccountTransactionsData > data) override
Write a new set of account transactions.
Definition CassandraBackendFamily.hpp:794
std::optional< Blob > doFetchLedgerObject(ripple::uint256 const &key, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching a ledger object.
Definition CassandraBackendFamily.hpp:528
bool executeSyncUpdate(Statement statement)
Executes statements and tries to write to DB.
Definition CassandraBackendFamily.hpp:951
void writeLedger(ripple::LedgerHeader const &ledgerHeader, std::string &&blob) override
Writes to a specific ledger.
Definition CassandraBackendFamily.hpp:224
TransactionsAndCursor fetchNFTTransactions(ripple::uint256 const &tokenID, std::uint32_t const limit, bool const forward, std::optional< TransactionsCursor > const &cursorIn, boost::asio::yield_context yield) const override
Fetches all transactions for a specific NFT.
Definition CassandraBackendFamily.hpp:418
void writeTransaction(std::string &&hash, std::uint32_t const seq, std::uint32_t const date, std::string &&transaction, std::string &&metadata) override
Writes a new transaction.
Definition CassandraBackendFamily.hpp:845
std::vector< LedgerObject > fetchLedgerDiff(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Returns the difference between ledgers.
Definition CassandraBackendFamily.hpp:691
std::vector< TransactionAndMetadata > fetchAllTransactionsInLedger(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches all transactions from a specific ledger.
Definition CassandraBackendFamily.hpp:339
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:46
void bindAt(std::size_t const idx, Type &&value) const
Binds an argument to a specific index.
Definition Statement.hpp:95
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:94
The requirements of an execution strategy.
Definition Concepts.hpp:54
The requirements of a settings provider.
Definition Concepts.hpp:43
This namespace implements a wrapper for the Cassandra C++ driver.
Definition CassandraBackendFamily.hpp:66
impl::ResultExtractor< Types... > extract(Handle::ResultType const &result)
Extracts the results into series of std::tuple<Types...> by creating a simple wrapper with an STL inp...
Definition Handle.hpp:329
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
ripple::LedgerHeader deserializeHeader(ripple::Slice data)
Deserializes a ripple::LedgerHeader from ripple::Slice of data.
Definition LedgerUtils.hpp:217
auto timed(FnType &&func)
Profiler function to measure the time a function execution consumes.
Definition Profiler.hpp:40
Struct used to keep track of what to write to account_transactions/account_tx tables.
Definition DBHelpers.hpp:45
Represents an NFT state at a particular ledger.
Definition DBHelpers.hpp:103
Struct to store ledger header cache entry and the sequence it belongs to.
Definition LedgerHeaderCache.hpp:48
Represents an object in the ledger.
Definition Types.hpp:41
Stores a range of sequences as a min and max pair.
Definition Types.hpp:247
Represents an array of MPTokens.
Definition Types.hpp:239
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:164
A strong type wrapper for int32_t.
Definition Types.hpp:57
A strong type wrapper for string.
Definition Types.hpp:68