mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-27 07:05:54 +00:00
cleanup and postgres stubs
This commit is contained in:
@@ -57,6 +57,7 @@ include(Postgres)
|
|||||||
target_sources(reporting PRIVATE
|
target_sources(reporting PRIVATE
|
||||||
reporting/ETLSource.cpp
|
reporting/ETLSource.cpp
|
||||||
reporting/ReportingBackend.cpp
|
reporting/ReportingBackend.cpp
|
||||||
|
reporting/PostgresBackend.cpp
|
||||||
reporting/Pg.cpp
|
reporting/Pg.cpp
|
||||||
reporting/DBHelpers.cpp
|
reporting/DBHelpers.cpp
|
||||||
reporting/ReportingETL.cpp
|
reporting/ReportingETL.cpp
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ doAccountTx(
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BackendInterface::AccountTransactionsCursor> cursor;
|
std::optional<Backend::AccountTransactionsCursor> cursor;
|
||||||
if (request.contains("cursor"))
|
if (request.contains("cursor"))
|
||||||
{
|
{
|
||||||
auto const& obj = request.at("cursor").as_object();
|
auto const& obj = request.at("cursor").as_object();
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ doBookOffers(
|
|||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
ripple::uint256 bookBase = getBookBase(book);
|
ripple::uint256 bookBase = getBookBase(book);
|
||||||
std::vector<BackendInterface::LedgerObject> offers;
|
std::vector<Backend::LedgerObject> offers;
|
||||||
if (!cursor.isZero())
|
if (!cursor.isZero())
|
||||||
{
|
{
|
||||||
offers = backend.fetchBookOffers(bookBase, *sequence, cursor);
|
offers = backend.fetchBookOffers(bookBase, *sequence, cursor);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ doLedgerData(
|
|||||||
request.contains("binary") ? request.at("binary").as_bool() : false;
|
request.contains("binary") ? request.at("binary").as_bool() : false;
|
||||||
size_t limit = request.contains("limit") ? request.at("limit").as_int64()
|
size_t limit = request.contains("limit") ? request.at("limit").as_int64()
|
||||||
: (binary ? 2048 : 256);
|
: (binary ? 2048 : 256);
|
||||||
BackendInterface::LedgerPage page;
|
Backend::LedgerPage page;
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
page = backend.fetchLedgerPage(cursor, ledger, limit);
|
page = backend.fetchLedgerPage(cursor, ledger, limit);
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ doLedgerData(
|
|||||||
std::chrono::duration_cast<std::chrono::microseconds>(end - start)
|
std::chrono::duration_cast<std::chrono::microseconds>(end - start)
|
||||||
.count();
|
.count();
|
||||||
boost::json::array objects;
|
boost::json::array objects;
|
||||||
std::vector<BackendInterface::LedgerObject>& results = page.objects;
|
std::vector<Backend::LedgerObject>& results = page.objects;
|
||||||
std::optional<ripple::uint256> const& returnedCursor = page.cursor;
|
std::optional<ripple::uint256> const& returnedCursor = page.cursor;
|
||||||
BOOST_LOG_TRIVIAL(debug)
|
BOOST_LOG_TRIVIAL(debug)
|
||||||
<< "doUpperBound returned " << results.size() << " results";
|
<< "doUpperBound returned " << results.size() << " results";
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ accountFromStringStrict(std::string const& account)
|
|||||||
std::pair<
|
std::pair<
|
||||||
std::shared_ptr<ripple::STTx const>,
|
std::shared_ptr<ripple::STTx const>,
|
||||||
std::shared_ptr<ripple::STObject const>>
|
std::shared_ptr<ripple::STObject const>>
|
||||||
deserializeTxPlusMeta(BackendInterface::TransactionAndMetadata const& blobs)
|
deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs)
|
||||||
{
|
{
|
||||||
std::pair<
|
std::pair<
|
||||||
std::shared_ptr<ripple::STTx const>,
|
std::shared_ptr<ripple::STTx const>,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ accountFromStringStrict(std::string const& account);
|
|||||||
std::pair<
|
std::pair<
|
||||||
std::shared_ptr<ripple::STTx const>,
|
std::shared_ptr<ripple::STTx const>,
|
||||||
std::shared_ptr<ripple::STObject const>>
|
std::shared_ptr<ripple::STObject const>>
|
||||||
deserializeTxPlusMeta(BackendInterface::TransactionAndMetadata const& blobs);
|
deserializeTxPlusMeta(Backend::TransactionAndMetadata const& blobs);
|
||||||
|
|
||||||
boost::json::object
|
boost::json::object
|
||||||
getJson(ripple::STBase const& obj);
|
getJson(ripple::STBase const& obj);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <reporting/ReportingBackend.h>
|
#include <reporting/ReportingBackend.h>
|
||||||
|
namespace Backend {
|
||||||
// Process the result of an asynchronous write. Retry on error
|
// Process the result of an asynchronous write. Retry on error
|
||||||
// @param fut cassandra future associated with the write
|
// @param fut cassandra future associated with the write
|
||||||
// @param cbData struct that holds the request parameters
|
// @param cbData struct that holds the request parameters
|
||||||
@@ -1529,3 +1530,4 @@ CassandraFlatMapBackend::open()
|
|||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "Opened database successfully";
|
BOOST_LOG_TRIVIAL(info) << "Opened database successfully";
|
||||||
}
|
}
|
||||||
|
} // namespace Backend
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#include <reporting/BackendInterface.h>
|
#include <reporting/BackendInterface.h>
|
||||||
#include <reporting/DBHelpers.h>
|
#include <reporting/DBHelpers.h>
|
||||||
|
|
||||||
|
namespace Backend {
|
||||||
|
|
||||||
void
|
void
|
||||||
flatMapWriteCallback(CassFuture* fut, void* cbData);
|
flatMapWriteCallback(CassFuture* fut, void* cbData);
|
||||||
void
|
void
|
||||||
@@ -259,12 +261,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<
|
std::pair<
|
||||||
std::vector<BackendInterface::TransactionAndMetadata>,
|
std::vector<TransactionAndMetadata>,
|
||||||
std::optional<BackendInterface::AccountTransactionsCursor>>
|
std::optional<AccountTransactionsCursor>>
|
||||||
fetchAccountTransactions(
|
fetchAccountTransactions(
|
||||||
ripple::AccountID const& account,
|
ripple::AccountID const& account,
|
||||||
std::optional<BackendInterface::AccountTransactionsCursor> const&
|
std::optional<AccountTransactionsCursor> const& cursor) const override
|
||||||
cursor) const override
|
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Starting doAccountTx";
|
BOOST_LOG_TRIVIAL(debug) << "Starting doAccountTx";
|
||||||
CassStatement* statement = cass_prepared_bind(selectAccountTx_);
|
CassStatement* statement = cass_prepared_bind(selectAccountTx_);
|
||||||
@@ -707,7 +708,7 @@ public:
|
|||||||
// @param key the key of the object
|
// @param key the key of the object
|
||||||
// @param pno object in which to store the result
|
// @param pno object in which to store the result
|
||||||
// @return result status of query
|
// @return result status of query
|
||||||
std::optional<BackendInterface::Blob>
|
std::optional<Blob>
|
||||||
fetchLedgerObject(ripple::uint256 const& key, uint32_t sequence)
|
fetchLedgerObject(ripple::uint256 const& key, uint32_t sequence)
|
||||||
const override
|
const override
|
||||||
{
|
{
|
||||||
@@ -837,7 +838,7 @@ public:
|
|||||||
return token + 1;
|
return token + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BackendInterface::TransactionAndMetadata>
|
std::optional<TransactionAndMetadata>
|
||||||
fetchTransaction(ripple::uint256 const& hash) const override
|
fetchTransaction(ripple::uint256 const& hash) const override
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(trace) << "Fetching from cassandra";
|
BOOST_LOG_TRIVIAL(trace) << "Fetching from cassandra";
|
||||||
@@ -913,7 +914,7 @@ public:
|
|||||||
<< " microseconds";
|
<< " microseconds";
|
||||||
return {{txResult, metaResult}};
|
return {{txResult, metaResult}};
|
||||||
}
|
}
|
||||||
BackendInterface::LedgerPage
|
LedgerPage
|
||||||
fetchLedgerPage(
|
fetchLedgerPage(
|
||||||
std::optional<ripple::uint256> const& cursor,
|
std::optional<ripple::uint256> const& cursor,
|
||||||
std::uint32_t ledgerSequence,
|
std::uint32_t ledgerSequence,
|
||||||
@@ -1018,8 +1019,7 @@ public:
|
|||||||
if (keys.size())
|
if (keys.size())
|
||||||
{
|
{
|
||||||
std::vector<LedgerObject> results;
|
std::vector<LedgerObject> results;
|
||||||
std::vector<BackendInterface::Blob> objs =
|
std::vector<Blob> objs = fetchLedgerObjects(keys, ledgerSequence);
|
||||||
fetchLedgerObjects(keys, ledgerSequence);
|
|
||||||
for (size_t i = 0; i < objs.size(); ++i)
|
for (size_t i = 0; i < objs.size(); ++i)
|
||||||
{
|
{
|
||||||
results.push_back({keys[i], objs[i]});
|
results.push_back({keys[i], objs[i]});
|
||||||
@@ -1030,7 +1030,7 @@ public:
|
|||||||
return {{}, {}};
|
return {{}, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BackendInterface::LedgerObject>
|
std::vector<LedgerObject>
|
||||||
fetchBookOffers(
|
fetchBookOffers(
|
||||||
ripple::uint256 const& book,
|
ripple::uint256 const& book,
|
||||||
uint32_t sequence,
|
uint32_t sequence,
|
||||||
@@ -1139,8 +1139,7 @@ public:
|
|||||||
if (keys.size())
|
if (keys.size())
|
||||||
{
|
{
|
||||||
std::vector<LedgerObject> results;
|
std::vector<LedgerObject> results;
|
||||||
std::vector<BackendInterface::Blob> objs =
|
std::vector<Blob> objs = fetchLedgerObjects(keys, sequence);
|
||||||
fetchLedgerObjects(keys, sequence);
|
|
||||||
for (size_t i = 0; i < objs.size(); ++i)
|
for (size_t i = 0; i < objs.size(); ++i)
|
||||||
{
|
{
|
||||||
results.push_back({keys[i], objs[i]});
|
results.push_back({keys[i], objs[i]});
|
||||||
@@ -1160,7 +1159,7 @@ public:
|
|||||||
{
|
{
|
||||||
CassandraFlatMapBackend const& backend;
|
CassandraFlatMapBackend const& backend;
|
||||||
ripple::uint256 const& hash;
|
ripple::uint256 const& hash;
|
||||||
BackendInterface::TransactionAndMetadata& result;
|
TransactionAndMetadata& result;
|
||||||
std::condition_variable& cv;
|
std::condition_variable& cv;
|
||||||
|
|
||||||
std::atomic_uint32_t& numFinished;
|
std::atomic_uint32_t& numFinished;
|
||||||
@@ -1169,7 +1168,7 @@ public:
|
|||||||
ReadCallbackData(
|
ReadCallbackData(
|
||||||
CassandraFlatMapBackend const& backend,
|
CassandraFlatMapBackend const& backend,
|
||||||
ripple::uint256 const& hash,
|
ripple::uint256 const& hash,
|
||||||
BackendInterface::TransactionAndMetadata& result,
|
TransactionAndMetadata& result,
|
||||||
std::condition_variable& cv,
|
std::condition_variable& cv,
|
||||||
std::atomic_uint32_t& numFinished,
|
std::atomic_uint32_t& numFinished,
|
||||||
size_t batchSize)
|
size_t batchSize)
|
||||||
@@ -1185,7 +1184,7 @@ public:
|
|||||||
ReadCallbackData(ReadCallbackData const& other) = default;
|
ReadCallbackData(ReadCallbackData const& other) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<BackendInterface::TransactionAndMetadata>
|
std::vector<TransactionAndMetadata>
|
||||||
fetchTransactions(std::vector<ripple::uint256> const& hashes) const override
|
fetchTransactions(std::vector<ripple::uint256> const& hashes) const override
|
||||||
{
|
{
|
||||||
std::size_t const numHashes = hashes.size();
|
std::size_t const numHashes = hashes.size();
|
||||||
@@ -1194,8 +1193,7 @@ public:
|
|||||||
std::atomic_uint32_t numFinished = 0;
|
std::atomic_uint32_t numFinished = 0;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
std::vector<BackendInterface::TransactionAndMetadata> results{
|
std::vector<TransactionAndMetadata> results{numHashes};
|
||||||
numHashes};
|
|
||||||
std::vector<std::shared_ptr<ReadCallbackData>> cbs;
|
std::vector<std::shared_ptr<ReadCallbackData>> cbs;
|
||||||
cbs.reserve(numHashes);
|
cbs.reserve(numHashes);
|
||||||
for (std::size_t i = 0; i < hashes.size(); ++i)
|
for (std::size_t i = 0; i < hashes.size(); ++i)
|
||||||
@@ -1251,7 +1249,7 @@ public:
|
|||||||
CassandraFlatMapBackend const& backend;
|
CassandraFlatMapBackend const& backend;
|
||||||
ripple::uint256 const& key;
|
ripple::uint256 const& key;
|
||||||
uint32_t sequence;
|
uint32_t sequence;
|
||||||
BackendInterface::Blob& result;
|
Blob& result;
|
||||||
std::condition_variable& cv;
|
std::condition_variable& cv;
|
||||||
|
|
||||||
std::atomic_uint32_t& numFinished;
|
std::atomic_uint32_t& numFinished;
|
||||||
@@ -1261,7 +1259,7 @@ public:
|
|||||||
CassandraFlatMapBackend const& backend,
|
CassandraFlatMapBackend const& backend,
|
||||||
ripple::uint256 const& key,
|
ripple::uint256 const& key,
|
||||||
uint32_t sequence,
|
uint32_t sequence,
|
||||||
BackendInterface::Blob& result,
|
Blob& result,
|
||||||
std::condition_variable& cv,
|
std::condition_variable& cv,
|
||||||
std::atomic_uint32_t& numFinished,
|
std::atomic_uint32_t& numFinished,
|
||||||
size_t batchSize)
|
size_t batchSize)
|
||||||
@@ -1277,7 +1275,7 @@ public:
|
|||||||
|
|
||||||
ReadObjectCallbackData(ReadObjectCallbackData const& other) = default;
|
ReadObjectCallbackData(ReadObjectCallbackData const& other) = default;
|
||||||
};
|
};
|
||||||
std::vector<BackendInterface::Blob>
|
std::vector<Blob>
|
||||||
fetchLedgerObjects(
|
fetchLedgerObjects(
|
||||||
std::vector<ripple::uint256> const& keys,
|
std::vector<ripple::uint256> const& keys,
|
||||||
uint32_t sequence) const override
|
uint32_t sequence) const override
|
||||||
@@ -1288,7 +1286,7 @@ public:
|
|||||||
std::atomic_uint32_t numFinished = 0;
|
std::atomic_uint32_t numFinished = 0;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
std::vector<BackendInterface::Blob> results{numKeys};
|
std::vector<Blob> results{numKeys};
|
||||||
std::vector<std::shared_ptr<ReadObjectCallbackData>> cbs;
|
std::vector<std::shared_ptr<ReadObjectCallbackData>> cbs;
|
||||||
cbs.reserve(numKeys);
|
cbs.reserve(numKeys);
|
||||||
for (std::size_t i = 0; i < keys.size(); ++i)
|
for (std::size_t i = 0; i < keys.size(); ++i)
|
||||||
@@ -1743,12 +1741,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
writeAccountTransactions(AccountTransactionsData&& data) const override
|
writeAccountTransactions(
|
||||||
|
std::vector<AccountTransactionsData>&& data) const override
|
||||||
{
|
{
|
||||||
numRequestsOutstanding_ += data.accounts.size();
|
for (auto& record : data)
|
||||||
WriteAccountTxCallbackData* cbData =
|
{
|
||||||
new WriteAccountTxCallbackData(this, std::move(data));
|
numRequestsOutstanding_ += record.accounts.size();
|
||||||
writeAccountTx(*cbData, false);
|
WriteAccountTxCallbackData* cbData =
|
||||||
|
new WriteAccountTxCallbackData(this, std::move(record));
|
||||||
|
writeAccountTx(*cbData, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1778,6 +1780,7 @@ public:
|
|||||||
static_cast<cass_byte_t const*>(accountData),
|
static_cast<cass_byte_t const*>(accountData),
|
||||||
account.size());
|
account.size());
|
||||||
if (rc != CASS_OK)
|
if (rc != CASS_OK)
|
||||||
|
|
||||||
{
|
{
|
||||||
cass_statement_free(statement);
|
cass_statement_free(statement);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@@ -1985,4 +1988,5 @@ public:
|
|||||||
flatMapGetCreatedCallback(CassFuture* fut, void* cbData);
|
flatMapGetCreatedCallback(CassFuture* fut, void* cbData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Backend
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -127,10 +127,7 @@ ReportingETL::loadInitialLedger(uint32_t startingSequence)
|
|||||||
|
|
||||||
if (!stopping_)
|
if (!stopping_)
|
||||||
{
|
{
|
||||||
for (auto& data : accountTxData)
|
flatMapBackend_->writeAccountTransactions(std::move(accountTxData));
|
||||||
{
|
|
||||||
flatMapBackend_->writeAccountTransactions(std::move(data));
|
|
||||||
}
|
|
||||||
bool success = flatMapBackend_->writeLedger(
|
bool success = flatMapBackend_->writeLedger(
|
||||||
lgrInfo, std::move(*ledgerData->mutable_ledger_header()));
|
lgrInfo, std::move(*ledgerData->mutable_ledger_header()));
|
||||||
}
|
}
|
||||||
@@ -301,10 +298,7 @@ ReportingETL::buildNextLedger(org::xrpl::rpc::v1::GetLedgerResponse& rawData)
|
|||||||
isDeleted,
|
isDeleted,
|
||||||
std::move(bookDir));
|
std::move(bookDir));
|
||||||
}
|
}
|
||||||
for (auto& data : accountTxData)
|
flatMapBackend_->writeAccountTransactions(std::move(accountTxData));
|
||||||
{
|
|
||||||
flatMapBackend_->writeAccountTransactions(std::move(data));
|
|
||||||
}
|
|
||||||
bool success = flatMapBackend_->writeLedger(
|
bool success = flatMapBackend_->writeLedger(
|
||||||
lgrInfo, std::move(*rawData.mutable_ledger_header()));
|
lgrInfo, std::move(*rawData.mutable_ledger_header()));
|
||||||
BOOST_LOG_TRIVIAL(debug)
|
BOOST_LOG_TRIVIAL(debug)
|
||||||
@@ -638,7 +632,7 @@ ReportingETL::ReportingETL(
|
|||||||
boost::asio::io_context& ioc)
|
boost::asio::io_context& ioc)
|
||||||
: publishStrand_(ioc)
|
: publishStrand_(ioc)
|
||||||
, ioContext_(ioc)
|
, ioContext_(ioc)
|
||||||
, flatMapBackend_(makeBackend(config))
|
, flatMapBackend_(Backend::makeBackend(config))
|
||||||
, pgPool_(make_PgPool(
|
, pgPool_(make_PgPool(
|
||||||
config.at("database").as_object().at("postgres").as_object()))
|
config.at("database").as_object().at("postgres").as_object()))
|
||||||
, loadBalancer_(
|
, loadBalancer_(
|
||||||
|
|||||||
Reference in New Issue
Block a user