3#include "data/BackendInterface.hpp"
5#include "data/LedgerCacheInterface.hpp"
6#include "data/LedgerHeaderCache.hpp"
7#include "data/Types.hpp"
8#include "data/cassandra/Concepts.hpp"
9#include "data/cassandra/Handle.hpp"
10#include "data/cassandra/Types.hpp"
11#include "data/cassandra/impl/ExecutionStrategy.hpp"
12#include "util/Assert.hpp"
13#include "util/LedgerUtils.hpp"
14#include "util/Profiler.hpp"
15#include "util/log/Logger.hpp"
17#include <boost/asio/spawn.hpp>
18#include <boost/json/object.hpp>
19#include <boost/uuid/string_generator.hpp>
20#include <boost/uuid/uuid.hpp>
22#include <fmt/format.h>
23#include <xrpl/basics/Blob.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/basics/strHex.h>
26#include <xrpl/protocol/AccountID.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/LedgerHeader.h>
29#include <xrpl/protocol/nft.h>
45class CacheBackendCassandraTest;
68 SettingsProviderType settingsProvider_;
70 std::atomic_uint32_t ledgerSequence_ = 0u;
71 friend class ::CacheBackendCassandraTest;
76 mutable ExecutionStrategyType executor_;
78 mutable FetchLedgerCacheType ledgerCache_{};
89 SettingsProviderType settingsProvider,
94 , settingsProvider_{std::move(settingsProvider)}
95 , schema_{settingsProvider_}
96 , handle_{settingsProvider_.getSettings()}
97 , executor_{settingsProvider_.getSettings(), handle_}
99 if (
auto const res = handle_.connect(); not res.has_value())
100 throw std::runtime_error(
"Could not connect to database: " + res.error());
103 if (
auto const res = handle_.execute(schema_.createKeyspace); not res.has_value()) {
106 if (res.error().code() != CASS_ERROR_SERVER_UNAUTHORIZED)
107 throw std::runtime_error(
"Could not create keyspace: " + res.error());
110 if (
auto const res = handle_.executeEach(schema_.createSchema); not res.has_value())
111 throw std::runtime_error(
"Could not create schema: " + res.error());
115 schema_.prepareStatements(handle_);
116 }
catch (std::runtime_error
const& ex) {
117 auto const error = fmt::format(
118 "Failed to prepare the statements: {}; readOnly: {}. ReadOnly should be turned off "
120 "node with write access to DB should be started first.",
124 LOG(log_.error()) << error;
125 throw std::runtime_error(error);
127 LOG(log_.info()) <<
"Created (revamped) CassandraBackend";
137 ripple::AccountID
const& account,
138 std::uint32_t
const limit,
140 std::optional<TransactionsCursor>
const& txnCursor,
141 boost::asio::yield_context yield
146 return {.txns = {}, .cursor = {}};
148 Statement
const statement = [
this, forward, &account]() {
150 return schema_->selectAccountTxForward.bind(account);
152 return schema_->selectAccountTx.bind(account);
155 auto cursor = txnCursor;
157 statement.
bindAt(1, cursor->asTuple());
158 LOG(log_.debug()) <<
"account = " << ripple::strHex(account)
159 <<
" tuple = " << cursor->ledgerSequence << cursor->transactionIndex;
161 auto const seq = forward ? rng->minSequence : rng->maxSequence;
162 auto const placeHolder = forward ? 0u : std::numeric_limits<std::uint32_t>::max();
164 statement.
bindAt(1, std::make_tuple(placeHolder, placeHolder));
165 LOG(log_.debug()) <<
"account = " << ripple::strHex(account) <<
" idx = " << seq
166 <<
" tuple = " << placeHolder;
173 auto const res = executor_.read(yield, statement);
174 auto const& results = res.value();
175 if (not results.hasRows()) {
176 LOG(log_.debug()) <<
"No rows returned";
180 std::vector<ripple::uint256> hashes = {};
181 auto numRows = results.numRows();
182 LOG(log_.info()) <<
"num_rows = " << numRows;
184 for (
auto [hash,
data] :
185 extract<ripple::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
186 hashes.push_back(hash);
187 if (--numRows == 0) {
188 LOG(log_.debug()) <<
"Setting cursor";
194 LOG(log_.debug()) <<
"Txns = " << txns.size();
196 if (txns.size() == limit) {
197 LOG(log_.debug()) <<
"Returning cursor";
198 return {txns, cursor};
211 writeLedger(ripple::LedgerHeader
const& ledgerHeader, std::string&& blob)
override
213 executor_.write(schema_->insertLedgerHeader, ledgerHeader.seq, std::move(blob));
215 executor_.write(schema_->insertLedgerHash, ledgerHeader.hash, ledgerHeader.seq);
217 ledgerSequence_ = ledgerHeader.seq;
220 std::optional<std::uint32_t>
223 if (
auto const res = executor_.read(yield, schema_->selectLatestLedger); res.has_value()) {
224 if (
auto const& rows = *res; rows) {
225 if (
auto const maybeRow = rows.template get<uint32_t>(); maybeRow.has_value())
228 LOG(log_.error()) <<
"Could not fetch latest ledger - no rows";
232 LOG(log_.error()) <<
"Could not fetch latest ledger - no result";
234 LOG(log_.error()) <<
"Could not fetch latest ledger: " << res.error();
240 std::optional<ripple::LedgerHeader>
242 std::uint32_t
const sequence,
243 boost::asio::yield_context yield
246 if (
auto const lock = ledgerCache_.get(); lock.has_value() && lock->seq == sequence)
249 auto const res = executor_.read(yield, schema_->selectLedgerBySeq, sequence);
251 if (
auto const& result = res.value(); result) {
252 if (
auto const maybeValue = result.template get<std::vector<unsigned char>>();
259 LOG(log_.error()) <<
"Could not fetch ledger by sequence - no rows";
263 LOG(log_.error()) <<
"Could not fetch ledger by sequence - no result";
265 LOG(log_.error()) <<
"Could not fetch ledger by sequence: " << res.error();
271 std::optional<ripple::LedgerHeader>
274 if (
auto const res = executor_.read(yield, schema_->selectLedgerByHash, hash); res) {
275 if (
auto const& result = res.value(); result) {
276 if (
auto const maybeValue = result.template get<uint32_t>(); maybeValue)
279 LOG(log_.error()) <<
"Could not fetch ledger by hash - no rows";
283 LOG(log_.error()) <<
"Could not fetch ledger by hash - no result";
285 LOG(log_.error()) <<
"Could not fetch ledger by hash: " << res.error();
291 std::optional<LedgerRange>
294 auto const res = executor_.read(yield, schema_->selectLedgerRange);
296 auto const& results = res.value();
297 if (not results.hasRows()) {
298 LOG(log_.debug()) <<
"Could not fetch ledger range - no rows";
309 range.maxSequence = range.minSequence = seq;
310 }
else if (idx == 1) {
311 range.maxSequence = seq;
317 if (range.minSequence > range.maxSequence)
318 std::swap(range.minSequence, range.maxSequence);
320 LOG(log_.debug()) <<
"After hardFetchLedgerRange range is " << range.minSequence <<
":"
321 << range.maxSequence;
324 LOG(log_.error()) <<
"Could not fetch ledger range: " << res.error();
329 std::vector<TransactionAndMetadata>
331 std::uint32_t
const ledgerSequence,
332 boost::asio::yield_context yield
339 std::vector<ripple::uint256>
341 std::uint32_t
const ledgerSequence,
342 boost::asio::yield_context yield
345 auto start = std::chrono::system_clock::now();
347 executor_.read(yield, schema_->selectAllTransactionHashesInLedger, ledgerSequence);
350 LOG(log_.error()) <<
"Could not fetch all transaction hashes: " << res.error();
354 auto const& result = res.value();
355 if (not result.hasRows()) {
356 LOG(log_.warn()) <<
"Could not fetch all transaction hashes - no rows; ledger = "
357 << std::to_string(ledgerSequence);
361 std::vector<ripple::uint256> hashes;
363 hashes.push_back(std::move(hash));
365 auto end = std::chrono::system_clock::now();
369 << hashes.size() <<
" transaction hashes from database in "
370 << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
378 ripple::uint256
const& tokenID,
379 std::uint32_t
const ledgerSequence,
380 boost::asio::yield_context yield
383 auto const res = executor_.read(yield, schema_->selectNFT, tokenID, ledgerSequence);
387 if (
auto const maybeRow = res->template get<uint32_t, ripple::AccountID, bool>();
389 auto [seq, owner, isBurned] = *maybeRow;
390 auto result = std::make_optional<NFT>(tokenID, seq, owner, isBurned);
403 auto uriRes = executor_.read(yield, schema_->selectNFTURI, tokenID, ledgerSequence);
405 if (
auto const maybeUri = uriRes->template get<ripple::Blob>(); maybeUri)
406 result->uri = *maybeUri;
412 LOG(log_.error()) <<
"Could not fetch NFT - no rows";
418 ripple::uint256
const& tokenID,
419 std::uint32_t
const limit,
421 std::optional<TransactionsCursor>
const& cursorIn,
422 boost::asio::yield_context yield
427 return {.txns = {}, .cursor = {}};
429 Statement
const statement = [
this, forward, &tokenID]() {
431 return schema_->selectNFTTxForward.bind(tokenID);
433 return schema_->selectNFTTx.bind(tokenID);
436 auto cursor = cursorIn;
438 statement.
bindAt(1, cursor->asTuple());
439 LOG(log_.debug()) <<
"token_id = " << ripple::strHex(tokenID)
440 <<
" tuple = " << cursor->ledgerSequence << cursor->transactionIndex;
442 auto const seq = forward ? rng->minSequence : rng->maxSequence;
443 auto const placeHolder = forward ? 0 : std::numeric_limits<std::uint32_t>::max();
445 statement.
bindAt(1, std::make_tuple(placeHolder, placeHolder));
446 LOG(log_.debug()) <<
"token_id = " << ripple::strHex(tokenID) <<
" idx = " << seq
447 <<
" tuple = " << placeHolder;
452 auto const res = executor_.read(yield, statement);
453 auto const& results = res.value();
454 if (not results.hasRows()) {
455 LOG(log_.debug()) <<
"No rows returned";
459 std::vector<ripple::uint256> hashes = {};
460 auto numRows = results.numRows();
461 LOG(log_.info()) <<
"num_rows = " << numRows;
463 for (
auto [hash,
data] :
464 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(
499 schema_->selectMPTHolders,
501 cursorIn.value_or(ripple::AccountID(0)),
505 auto const& holderResults = holderEntries.value();
506 if (not holderResults.hasRows()) {
507 LOG(log_.debug()) <<
"No rows returned";
511 std::vector<ripple::uint256> mptKeys;
512 std::optional<ripple::AccountID> cursor;
514 mptKeys.push_back(ripple::keylet::mptoken(mptID, holder).key);
520 auto it = std::remove_if(mptObjects.begin(), mptObjects.end(), [](Blob
const& mpt) {
524 mptObjects.erase(it, mptObjects.end());
526 ASSERT(mptKeys.size() <= limit,
"Number of keys can't exceed the limit");
527 if (mptKeys.size() == limit)
528 return {mptObjects, cursor};
530 return {mptObjects, {}};
535 ripple::uint256
const& key,
536 std::uint32_t
const sequence,
537 boost::asio::yield_context yield
540 LOG(log_.debug()) <<
"Fetching ledger object for seq " << sequence
541 <<
", key = " << ripple::to_string(key);
542 if (
auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
543 if (
auto const result = res->template get<Blob>(); result) {
547 LOG(log_.debug()) <<
"Could not fetch ledger object - no rows";
550 LOG(log_.error()) <<
"Could not fetch ledger object: " << res.error();
556 std::optional<std::uint32_t>
558 ripple::uint256
const& key,
559 std::uint32_t
const sequence,
560 boost::asio::yield_context yield
563 LOG(log_.debug()) <<
"Fetching ledger object for seq " << sequence
564 <<
", key = " << ripple::to_string(key);
565 if (
auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
566 if (
auto const result = res->template get<Blob, std::uint32_t>(); result) {
567 auto [_, seq] = result.value();
570 LOG(log_.debug()) <<
"Could not fetch ledger object sequence - no rows";
572 LOG(log_.error()) <<
"Could not fetch ledger object sequence: " << res.error();
578 std::optional<TransactionAndMetadata>
579 fetchTransaction(ripple::uint256
const& hash, boost::asio::yield_context yield)
const override
581 if (
auto const res = executor_.read(yield, schema_->selectTransaction, hash); res) {
582 if (
auto const maybeValue = res->template get<Blob, Blob, uint32_t, uint32_t>();
584 auto [transaction, meta, seq, date] = *maybeValue;
585 return std::make_optional<TransactionAndMetadata>(transaction, meta, seq, date);
588 LOG(log_.debug()) <<
"Could not fetch transaction - no rows";
590 LOG(log_.error()) <<
"Could not fetch transaction: " << res.error();
596 std::optional<ripple::uint256>
599 std::uint32_t
const ledgerSequence,
600 boost::asio::yield_context yield
603 if (
auto const res = executor_.read(yield, schema_->selectSuccessor, key, ledgerSequence);
605 if (
auto const result = res->template get<ripple::uint256>(); result) {
606 if (*result == kLAST_KEY)
611 LOG(log_.debug()) <<
"Could not fetch successor - no rows";
613 LOG(log_.error()) <<
"Could not fetch successor: " << res.error();
619 std::vector<TransactionAndMetadata>
621 std::vector<ripple::uint256>
const& hashes,
622 boost::asio::yield_context yield
628 auto const numHashes = hashes.size();
629 std::vector<TransactionAndMetadata> results;
630 results.reserve(numHashes);
632 std::vector<Statement> statements;
633 statements.reserve(numHashes);
635 auto const timeDiff =
util::timed([
this, yield, &results, &hashes, &statements]() {
640 std::back_inserter(statements),
641 [
this](
auto const& hash) {
return schema_->selectTransaction.bind(hash); }
644 auto const entries = executor_.readEach(yield, statements);
646 std::cbegin(entries),
648 std::back_inserter(results),
650 if (
auto const maybeRow = res.template get<Blob, Blob, uint32_t, uint32_t>();
659 ASSERT(numHashes == results.size(),
"Number of hashes and results must match");
660 LOG(log_.debug()) <<
"Fetched " << numHashes <<
" transactions from database in "
661 << timeDiff <<
" milliseconds";
667 std::vector<ripple::uint256>
const& keys,
668 std::uint32_t
const sequence,
669 boost::asio::yield_context yield
675 auto const numKeys = keys.size();
676 LOG(log_.trace()) <<
"Fetching " << numKeys <<
" objects";
678 std::vector<Blob> results;
679 results.reserve(numKeys);
681 std::vector<Statement> statements;
682 statements.reserve(numKeys);
688 std::back_inserter(statements),
689 [
this, &sequence](
auto const& key) {
return schema_->selectObject.bind(key, sequence); }
692 auto const entries = executor_.readEach(yield, statements);
694 std::cbegin(entries),
696 std::back_inserter(results),
697 [](
auto const& res) -> Blob {
698 if (
auto const maybeValue = res.template get<Blob>(); maybeValue)
705 LOG(log_.trace()) <<
"Fetched " << numKeys <<
" objects";
709 std::vector<LedgerObject>
711 std::uint32_t
const ledgerSequence,
712 boost::asio::yield_context yield
715 auto const [keys, timeDiff] =
716 util::timed([
this, &ledgerSequence, yield]() -> std::vector<ripple::uint256> {
717 auto const res = executor_.read(yield, schema_->selectDiff, ledgerSequence);
719 LOG(log_.error()) <<
"Could not fetch ledger diff: " << res.error()
720 <<
"; ledger = " << ledgerSequence;
724 auto const& results = res.value();
727 <<
"Could not fetch ledger diff - no rows; ledger = " << ledgerSequence;
731 std::vector<ripple::uint256> resultKeys;
733 resultKeys.push_back(key);
742 LOG(log_.debug()) <<
"Fetched " << keys.size() <<
" diff hashes from database in "
743 << timeDiff <<
" milliseconds";
746 std::vector<LedgerObject> results;
747 results.reserve(keys.size());
753 std::back_inserter(results),
754 [](
auto const& key,
auto const& obj) {
return LedgerObject{key, obj}; }
760 std::optional<std::string>
762 std::string
const& migratorName,
763 boost::asio::yield_context yield
766 auto const res = executor_.read(yield, schema_->selectMigratorStatus,
Text(migratorName));
768 LOG(log_.error()) <<
"Could not fetch migrator status: " << res.error();
772 auto const& results = res.value();
783 std::expected<std::vector<std::pair<boost::uuids::uuid, std::string>>, std::string>
786 auto const readResult = executor_.read(yield, schema_->selectClioNodesData);
788 return std::unexpected{readResult.error().message()};
790 std::vector<std::pair<boost::uuids::uuid, std::string>> result;
793 result.emplace_back(uuid, std::move(message));
802 LOG(log_.trace()) <<
" Writing ledger object " << key.size() <<
":" << seq <<
" ["
803 << blob.size() <<
" bytes]";
806 executor_.write(schema_->insertDiff, seq, key);
808 executor_.write(schema_->insertObject, std::move(key), seq, std::move(blob));
812 writeSuccessor(std::string&& key, std::uint32_t
const seq, std::string&& successor)
override
814 LOG(log_.trace()) <<
"Writing successor. key = " << key.size() <<
" bytes. "
815 <<
" seq = " << std::to_string(seq) <<
" successor = " << successor.size()
817 ASSERT(!key.empty(),
"Key must not be empty");
818 ASSERT(!successor.empty(),
"Successor must not be empty");
820 executor_.write(schema_->insertSuccessor, std::move(key), seq, std::move(successor));
826 std::vector<Statement> statements;
827 statements.reserve(
data.size() * 10);
829 for (
auto& record :
data) {
830 std::ranges::transform(
831 record.accounts, std::back_inserter(statements), [
this, &record](
auto&& account) {
832 return schema_->insertAccountTx.bind(
833 std::forward<decltype(account)>(account),
834 std::make_tuple(record.ledgerSequence, record.transactionIndex),
841 executor_.write(std::move(statements));
847 std::vector<Statement> statements;
848 statements.reserve(record.accounts.size());
850 std::ranges::transform(
851 record.accounts, std::back_inserter(statements), [
this, &record](
auto&& account) {
852 return schema_->insertAccountTx.bind(
853 std::forward<decltype(account)>(account),
854 std::make_tuple(record.ledgerSequence, record.transactionIndex),
860 executor_.write(std::move(statements));
866 std::vector<Statement> statements;
867 statements.reserve(
data.size());
869 std::ranges::transform(
data, std::back_inserter(statements), [
this](
auto const& record) {
870 return schema_->insertNFTTx.bind(
872 std::make_tuple(record.ledgerSequence, record.transactionIndex),
877 executor_.write(std::move(statements));
883 std::uint32_t
const seq,
884 std::uint32_t
const date,
885 std::string&& transaction,
886 std::string&& metadata
889 LOG(log_.trace()) <<
"Writing txn to database";
891 executor_.write(schema_->insertLedgerTransaction, seq, hash);
893 schema_->insertTransaction,
897 std::move(transaction),
905 std::vector<Statement> statements;
906 statements.reserve(
data.size() * 3);
909 if (!record.onlyUriChanged) {
910 statements.push_back(schema_->insertNFT.bind(
911 record.tokenID, record.ledgerSequence, record.owner, record.isBurned
920 statements.push_back(schema_->insertIssuerNFT.bind(
921 ripple::nft::getIssuer(record.tokenID),
922 static_cast<uint32_t
>(ripple::nft::getTaxon(record.tokenID)),
925 statements.push_back(schema_->insertNFTURI.bind(
926 record.tokenID, record.ledgerSequence, record.uri.value()
931 statements.push_back(schema_->insertNFTURI.bind(
932 record.tokenID, record.ledgerSequence, record.uri.value()
937 executor_.writeEach(std::move(statements));
943 std::vector<Statement> statements;
944 statements.reserve(
data.size());
945 for (
auto [mptId, holder] :
data)
946 statements.push_back(schema_->insertMPTHolder.bind(mptId, holder));
948 executor_.write(std::move(statements));
962 schema_->insertMigratorStatus,
979 return executor_.isTooBusy();
985 return executor_.stats();
998 auto const res = executor_.writeSync(statement);
999 auto maybeSuccess = res->template get<bool>();
1000 if (not maybeSuccess) {
1001 LOG(log_.error()) <<
"executeSyncUpdate - error getting result - no row";
1005 if (not maybeSuccess.value()) {
1006 LOG(log_.warn()) <<
"Update failed. Checking if DB state is what we expect";
1013 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:95
BackendInterface(LedgerCacheInterface &cache)
Construct a new backend interface instance.
Definition BackendInterface.hpp:139
std::optional< LedgerRange > hardFetchLedgerRangeNoThrow() const
Fetches the ledger range from DB retrying until no DatabaseTimeout is thrown.
Definition BackendInterface.cpp:53
std::optional< LedgerRange > fetchLedgerRange() const
Fetch the current ledger range.
Definition BackendInterface.cpp:249
LedgerCacheInterface const & cache() const
Definition BackendInterface.hpp:151
A simple cache holding one ripple::LedgerHeader to reduce DB lookups.
Definition LedgerHeaderCache.hpp:22
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:21
Implements BackendInterface for Cassandra/ScyllaDB/Keyspace.
Definition CassandraBackendFamily.hpp:64
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:959
std::optional< LedgerRange > hardFetchLedgerRange(boost::asio::yield_context yield) const override
Fetches the ledger range from DB.
Definition CassandraBackendFamily.hpp:292
void startWrites() const override
Starts a write transaction with the DB. No-op for cassandra.
Definition CassandraBackendFamily.hpp:952
void doWriteLedgerObject(std::string &&key, std::uint32_t const seq, std::string &&blob) override
Writes a ledger object to the database.
Definition CassandraBackendFamily.hpp:800
std::optional< TransactionAndMetadata > fetchTransaction(ripple::uint256 const &hash, boost::asio::yield_context yield) const override
Fetches a specific transaction.
Definition CassandraBackendFamily.hpp:579
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:136
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:903
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:241
void writeNFTTransactions(std::vector< NFTTransactionsData > const &data) override
Write NFTs transactions.
Definition CassandraBackendFamily.hpp:864
void writeNodeMessage(boost::uuids::uuid const &uuid, std::string message) override
Write a node message. Used by ClusterCommunicationService.
Definition CassandraBackendFamily.hpp:969
std::optional< std::uint32_t > fetchLatestLedgerSequence(boost::asio::yield_context yield) const override
Fetches the latest ledger sequence.
Definition CassandraBackendFamily.hpp:221
CassandraBackendFamily(SettingsProviderType settingsProvider, data::LedgerCacheInterface &cache, bool readOnly)
Create a new cassandra/scylla backend instance.
Definition CassandraBackendFamily.hpp:88
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:272
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:557
bool isTooBusy() const override
Definition CassandraBackendFamily.hpp:977
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:377
void writeMPTHolders(std::vector< MPTHolderData > const &data) override
Write accounts that started holding onto a MPT.
Definition CassandraBackendFamily.hpp:941
void writeAccountTransaction(AccountTransactionsData record) override
Write a new account transaction.
Definition CassandraBackendFamily.hpp:845
void writeSuccessor(std::string &&key, std::uint32_t const seq, std::string &&successor) override
Write a new successor.
Definition CassandraBackendFamily.hpp:812
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:340
void waitForWritesToFinish() override
Wait for all pending writes to finish.
Definition CassandraBackendFamily.hpp:205
std::vector< TransactionAndMetadata > fetchTransactions(std::vector< ripple::uint256 > const &hashes, boost::asio::yield_context yield) const override
Fetches multiple transactions.
Definition CassandraBackendFamily.hpp:620
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:666
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:597
boost::json::object stats() const override
Definition CassandraBackendFamily.hpp:983
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:761
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:784
void writeAccountTransactions(std::vector< AccountTransactionsData > data) override
Write a new set of account transactions.
Definition CassandraBackendFamily.hpp:824
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:534
bool executeSyncUpdate(Statement statement)
Executes statements and tries to write to DB.
Definition CassandraBackendFamily.hpp:996
void writeLedger(ripple::LedgerHeader const &ledgerHeader, std::string &&blob) override
Writes to a specific ledger.
Definition CassandraBackendFamily.hpp:211
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:417
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:881
std::vector< LedgerObject > fetchLedgerDiff(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Returns the difference between ledgers.
Definition CassandraBackendFamily.hpp:710
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:330
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:27
void bindAt(std::size_t const idx, Type &&value) const
Binds an argument to a specific index.
Definition Statement.hpp:76
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
The requirements of an execution strategy.
Definition Concepts.hpp:35
The requirements of a settings provider.
Definition Concepts.hpp:24
This namespace implements a wrapper for the Cassandra C++ driver.
Definition CassandraBackendFamily.hpp:47
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:314
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
ripple::LedgerHeader deserializeHeader(ripple::Slice data)
Deserializes a ripple::LedgerHeader from ripple::Slice of data.
Definition LedgerUtils.hpp:233
auto timed(FnType &&func)
Profiler function to measure the time a function execution consumes.
Definition Profiler.hpp:21
Struct used to keep track of what to write to account_transactions/account_tx tables.
Definition DBHelpers.hpp:26
Represents an NFT state at a particular ledger.
Definition DBHelpers.hpp:93
Struct to store ledger header cache entry and the sequence it belongs to.
Definition LedgerHeaderCache.hpp:29
Represents an object in the ledger.
Definition Types.hpp:22
Stores a range of sequences as a min and max pair.
Definition Types.hpp:243
Represents an array of MPTokens.
Definition Types.hpp:235
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:153
A strong type wrapper for int32_t.
Definition Types.hpp:38
A strong type wrapper for string.
Definition Types.hpp:49