Skip to content

Commit c12601c

Browse files
committed
Merge branch 'develop' into release/2.6.0
2 parents 3810098 + dabaa5b commit c12601c

File tree

17 files changed

+138
-86
lines changed

17 files changed

+138
-86
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ jobs:
5151
with:
5252
overwrite_release: false
5353
prerelease: ${{ contains(github.ref_name, '-') }}
54-
title: "${{ github.ref_name}}"
54+
title: "${{ github.ref_name }}"
5555
version: "${{ github.ref_name }}"
5656
header: >
5757
${{ contains(github.ref_name, '-') && '> **Note:** Please remember that this is a release candidate and it is not recommended for production use.' || '' }}
5858
generate_changelog: ${{ !contains(github.ref_name, '-') }}
59-
draft: true
59+
draft: ${{ !contains(github.ref_name, '-') }}

src/data/BackendFactory.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace data {
4646
inline std::shared_ptr<BackendInterface>
4747
makeBackend(util::config::ClioConfigDefinition const& config, data::LedgerCacheInterface& cache)
4848
{
49+
using namespace cassandra::impl;
4950
static util::Logger const log{"Backend"}; // NOLINT(readability-identifier-naming)
5051
LOG(log.info()) << "Constructing BackendInterface";
5152

@@ -56,7 +57,7 @@ makeBackend(util::config::ClioConfigDefinition const& config, data::LedgerCacheI
5657

5758
if (boost::iequals(type, "cassandra")) {
5859
auto const cfg = config.getObject("database." + type);
59-
if (cfg.getValueView("provider").asString() == toString(cassandra::impl::Provider::Keyspace)) {
60+
if (providerFromString(cfg.getValueView("provider").asString()) == Provider::Keyspace) {
6061
backend = std::make_shared<data::cassandra::KeyspaceBackend>(
6162
data::cassandra::SettingsProvider{cfg}, cache, readOnly
6263
);

src/data/CassandraBackend.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ class BasicCassandraBackend : public CassandraBackendFamily<
189189
auto const nftUris = executor_.readEach(yield, selectNFTURIStatements);
190190

191191
for (auto i = 0u; i < nftIDs.size(); i++) {
192-
if (auto const maybeRow = nftInfos[i].template get<uint32_t, ripple::AccountID, bool>(); maybeRow) {
192+
if (auto const maybeRow = nftInfos[i].template get<uint32_t, ripple::AccountID, bool>();
193+
maybeRow.has_value()) {
193194
auto [seq, owner, isBurned] = *maybeRow;
194195
NFT nft(nftIDs[i], seq, owner, isBurned);
195-
if (auto const maybeUri = nftUris[i].template get<ripple::Blob>(); maybeUri)
196+
if (auto const maybeUri = nftUris[i].template get<ripple::Blob>(); maybeUri.has_value())
196197
nft.uri = *maybeUri;
197198
ret.nfts.push_back(nft);
198199
}

src/data/KeyspaceBackend.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ namespace data::cassandra {
5757
/**
5858
* @brief Implements @ref CassandraBackendFamily for Keyspace
5959
*
60-
* @tparam SettingsProviderType The settings provider type to use
61-
* @tparam ExecutionStrategyType The execution strategy type to use
62-
* @tparam FetchLedgerCacheType The ledger header cache type to use
60+
* @tparam SettingsProviderType The settings provider type
61+
* @tparam ExecutionStrategyType The execution strategy type
62+
* @tparam FetchLedgerCacheType The ledger header cache type
6363
*/
6464
template <
6565
SomeSettingsProvider SettingsProviderType,
@@ -101,9 +101,9 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
101101
// !range_.has_value() means the table 'ledger_range' is not populated;
102102
// This would be the first write to the table.
103103
// In this case, insert both min_sequence/max_sequence range into the table.
104-
if (not(range_.has_value())) {
105-
executor_.writeSync(schema_->insertLedgerRange, false, ledgerSequence_);
106-
executor_.writeSync(schema_->insertLedgerRange, true, ledgerSequence_);
104+
if (not range_.has_value()) {
105+
executor_.writeSync(schema_->insertLedgerRange, /* isLatestLedger =*/false, ledgerSequence_);
106+
executor_.writeSync(schema_->insertLedgerRange, /* isLatestLedger =*/true, ledgerSequence_);
107107
}
108108

109109
if (not this->executeSyncUpdate(schema_->updateLedgerRange.bind(ledgerSequence_, true, ledgerSequence_ - 1))) {
@@ -130,7 +130,7 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
130130
// Keyspace and ScyllaDB uses the same logic for taxon-filtered queries
131131
nftIDs = fetchNFTIDsByTaxon(issuer, *taxon, limit, cursorIn, yield);
132132
} else {
133-
// --- Amazon Keyspaces Workflow for non-taxon queries ---
133+
// Amazon Keyspaces Workflow for non-taxon queries
134134
auto const startTaxon = cursorIn.has_value() ? ripple::nft::toUInt32(ripple::nft::getTaxon(*cursorIn)) : 0;
135135
auto const startTokenID = cursorIn.value_or(ripple::uint256(0));
136136

@@ -140,8 +140,8 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
140140
firstQuery.bindAt(3, Limit{limit});
141141

142142
auto const firstRes = executor_.read(yield, firstQuery);
143-
if (firstRes) {
144-
for (auto const [nftID] : extract<ripple::uint256>(firstRes.value()))
143+
if (firstRes.has_value()) {
144+
for (auto const [nftID] : extract<ripple::uint256>(*firstRes))
145145
nftIDs.push_back(nftID);
146146
}
147147

@@ -152,8 +152,8 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
152152
secondQuery.bindAt(2, Limit{remainingLimit});
153153

154154
auto const secondRes = executor_.read(yield, secondQuery);
155-
if (secondRes) {
156-
for (auto const [nftID] : extract<ripple::uint256>(secondRes.value()))
155+
if (secondRes.has_value()) {
156+
for (auto const [nftID] : extract<ripple::uint256>(*secondRes))
157157
nftIDs.push_back(nftID);
158158
}
159159
}
@@ -163,7 +163,7 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
163163

164164
/**
165165
* @brief (Unsupported in Keyspaces) Fetches account root object indexes by page.
166-
* * @note Loading the cache by enumerating all accounts is currently unsupported by the AWS Keyspaces backend.
166+
* @note Loading the cache by enumerating all accounts is currently unsupported by the AWS Keyspaces backend.
167167
* This function's logic relies on "PER PARTITION LIMIT 1", which Keyspaces does not support, and there is
168168
* no efficient alternative. This is acceptable as the cache is primarily loaded via diffs. Calling this
169169
* function will throw an exception.
@@ -203,8 +203,8 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
203203
statement.bindAt(3, Limit{limit});
204204

205205
auto const res = executor_.read(yield, statement);
206-
if (res && res.value().hasRows()) {
207-
for (auto const [nftID] : extract<ripple::uint256>(res.value()))
206+
if (res.has_value() && res->hasRows()) {
207+
for (auto const [nftID] : extract<ripple::uint256>(*res))
208208
nftIDs.push_back(nftID);
209209
}
210210
return nftIDs;
@@ -229,8 +229,8 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
229229
firstQuery.bindAt(3, Limit{limit});
230230

231231
auto const firstRes = executor_.read(yield, firstQuery);
232-
if (firstRes) {
233-
for (auto const [nftID] : extract<ripple::uint256>(firstRes.value()))
232+
if (firstRes.has_value()) {
233+
for (auto const [nftID] : extract<ripple::uint256>(*firstRes))
234234
nftIDs.push_back(nftID);
235235
}
236236

@@ -241,8 +241,8 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
241241
secondQuery.bindAt(2, Limit{remainingLimit});
242242

243243
auto const secondRes = executor_.read(yield, secondQuery);
244-
if (secondRes) {
245-
for (auto const [nftID] : extract<ripple::uint256>(secondRes.value()))
244+
if (secondRes.has_value()) {
245+
for (auto const [nftID] : extract<ripple::uint256>(*secondRes))
246246
nftIDs.push_back(nftID);
247247
}
248248
}
@@ -291,10 +291,11 @@ class BasicKeyspaceBackend : public CassandraBackendFamily<
291291

292292
// Combine the results into final NFT objects.
293293
for (auto i = 0u; i < nftIDs.size(); ++i) {
294-
if (auto const maybeRow = nftInfos[i].template get<uint32_t, ripple::AccountID, bool>(); maybeRow) {
294+
if (auto const maybeRow = nftInfos[i].template get<uint32_t, ripple::AccountID, bool>();
295+
maybeRow.has_value()) {
295296
auto [seq, owner, isBurned] = *maybeRow;
296297
NFT nft(nftIDs[i], seq, owner, isBurned);
297-
if (auto const maybeUri = nftUris[i].template get<ripple::Blob>(); maybeUri)
298+
if (auto const maybeUri = nftUris[i].template get<ripple::Blob>(); maybeUri.has_value())
298299
nft.uri = *maybeUri;
299300
ret.nfts.push_back(nft);
300301
}

src/data/cassandra/CassandraBackendFamily.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ namespace data::cassandra {
7070
*
7171
* Note: This is a safer and more correct rewrite of the original implementation of the backend.
7272
*
73-
* @tparam SettingsProviderType The settings provider type to use
74-
* @tparam ExecutionStrategyType The execution strategy type to use
75-
* @tparam SchemaType The Schema type to use
76-
* @tparam FetchLedgerCacheType The ledger header cache type to use
73+
* @tparam SettingsProviderType The settings provider type
74+
* @tparam ExecutionStrategyType The execution strategy type
75+
* @tparam SchemaType The Schema type
76+
* @tparam FetchLedgerCacheType The ledger header cache type
7777
*/
7878
template <
7979
SomeSettingsProvider SettingsProviderType,
@@ -100,8 +100,8 @@ class CassandraBackendFamily : public BackendInterface {
100100
/**
101101
* @brief Create a new cassandra/scylla backend instance.
102102
*
103-
* @param settingsProvider The settings provider to use
104-
* @param cache The ledger cache to use
103+
* @param settingsProvider The settings provider
104+
* @param cache The ledger cache
105105
* @param readOnly Whether the database should be in readonly mode
106106
*/
107107
CassandraBackendFamily(SettingsProviderType settingsProvider, data::LedgerCacheInterface& cache, bool readOnly)
@@ -111,18 +111,18 @@ class CassandraBackendFamily : public BackendInterface {
111111
, handle_{settingsProvider_.getSettings()}
112112
, executor_{settingsProvider_.getSettings(), handle_}
113113
{
114-
if (auto const res = handle_.connect(); not res)
114+
if (auto const res = handle_.connect(); not res.has_value())
115115
throw std::runtime_error("Could not connect to database: " + res.error());
116116

117117
if (not readOnly) {
118-
if (auto const res = handle_.execute(schema_.createKeyspace); not res) {
118+
if (auto const res = handle_.execute(schema_.createKeyspace); not res.has_value()) {
119119
// on datastax, creation of keyspaces can be configured to only be done thru the admin
120120
// interface. this does not mean that the keyspace does not already exist tho.
121121
if (res.error().code() != CASS_ERROR_SERVER_UNAUTHORIZED)
122122
throw std::runtime_error("Could not create keyspace: " + res.error());
123123
}
124124

125-
if (auto const res = handle_.executeEach(schema_.createSchema); not res)
125+
if (auto const res = handle_.executeEach(schema_.createSchema); not res.has_value())
126126
throw std::runtime_error("Could not create schema: " + res.error());
127127
}
128128

@@ -233,10 +233,10 @@ class CassandraBackendFamily : public BackendInterface {
233233
std::optional<std::uint32_t>
234234
fetchLatestLedgerSequence(boost::asio::yield_context yield) const override
235235
{
236-
if (auto const res = executor_.read(yield, schema_->selectLatestLedger); res) {
237-
if (auto const& result = res.value(); result) {
238-
if (auto const maybeValue = result.template get<uint32_t>(); maybeValue)
239-
return maybeValue;
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())
239+
return maybeRow;
240240

241241
LOG(log_.error()) << "Could not fetch latest ledger - no rows";
242242
return std::nullopt;

src/data/cassandra/SettingsProvider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ SettingsProvider::parseSettings() const
9797
settings.coreConnectionsPerHost = config_.get<uint32_t>("core_connections_per_host");
9898
settings.queueSizeIO = config_.maybeValue<uint32_t>("queue_size_io");
9999
settings.writeBatchSize = config_.get<std::size_t>("write_batch_size");
100-
settings.provider = config_.get<std::string>("provider");
100+
settings.provider = impl::providerFromString(config_.get<std::string>("provider"));
101101

102102
if (config_.getValueView("connect_timeout").hasValue()) {
103103
auto const connectTimeoutSecond = config_.get<uint32_t>("connect_timeout");

src/data/cassandra/impl/Cluster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Cluster::Cluster(Settings const& settings) : ManagedObject{cass_cluster_new(), k
6161
cass_cluster_set_request_timeout(*this, settings.requestTimeout.count());
6262

6363
// TODO: AWS keyspace reads should be local_one to save cost
64-
if (settings.provider == toString(cassandra::impl::Provider::Keyspace)) {
64+
if (settings.provider == cassandra::impl::Provider::Keyspace) {
6565
if (auto const rc = cass_cluster_set_consistency(*this, CASS_CONSISTENCY_LOCAL_QUORUM); rc != CASS_OK) {
6666
throw std::runtime_error(fmt::format("Error setting keyspace consistency: {}", cass_error_desc(rc)));
6767
}

src/data/cassandra/impl/Cluster.hpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma once
2121

2222
#include "data/cassandra/impl/ManagedObject.hpp"
23+
#include "util/Assert.hpp"
2324
#include "util/log/Logger.hpp"
2425

2526
#include <cassandra.h>
@@ -31,29 +32,22 @@
3132
#include <string>
3233
#include <string_view>
3334
#include <thread>
34-
#include <utility>
3535
#include <variant>
3636

3737
namespace data::cassandra::impl {
3838

39-
namespace {
40-
4139
enum class Provider { Cassandra, Keyspace };
4240

43-
inline std::string
44-
toString(Provider provider)
41+
inline Provider
42+
providerFromString(std::string const& provider)
4543
{
46-
switch (provider) {
47-
case Provider::Cassandra:
48-
return "cassandra";
49-
case Provider::Keyspace:
50-
return "aws_keyspace";
51-
}
52-
std::unreachable();
44+
ASSERT(
45+
provider == "cassandra" || provider == "aws_keyspace",
46+
"Provider type must be one of 'cassandra' or 'aws_keyspace'"
47+
);
48+
return provider == "cassandra" ? Provider::Cassandra : Provider::Keyspace;
5349
}
5450

55-
} // namespace
56-
5751
// TODO: move Settings to public interface, not impl
5852

5953
/**
@@ -109,7 +103,7 @@ struct Settings {
109103
std::size_t writeBatchSize = kDEFAULT_BATCH_SIZE;
110104

111105
/** @brief Provider to know if we are using scylladb or keyspace */
112-
std::string provider = toString(kDEFAULT_PROVIDER);
106+
Provider provider = kDEFAULT_PROVIDER;
113107

114108
/** @brief Size of the IO queue */
115109
std::optional<uint32_t> queueSizeIO = std::nullopt; // NOLINT(readability-redundant-member-init)

src/util/config/ConfigConstraints.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ConfigValue;
4545
/**
4646
* @brief specific values that are accepted for logger levels in config.
4747
*/
48-
static constexpr std::array<char const*, 6> kLOG_LEVELS = {
48+
static constexpr std::array<std::string_view, 6> kLOG_LEVELS = {
4949
"trace",
5050
"debug",
5151
"info",
@@ -57,7 +57,7 @@ static constexpr std::array<char const*, 6> kLOG_LEVELS = {
5757
/**
5858
* @brief specific values that are accepted for logger tag style in config.
5959
*/
60-
static constexpr std::array<char const*, 5> kLOG_TAGS = {
60+
static constexpr std::array<std::string_view, 5> kLOG_TAGS = {
6161
"int",
6262
"uint",
6363
"null",
@@ -68,7 +68,7 @@ static constexpr std::array<char const*, 5> kLOG_TAGS = {
6868
/**
6969
* @brief specific values that are accepted for cache loading in config.
7070
*/
71-
static constexpr std::array<char const*, 3> kLOAD_CACHE_MODE = {
71+
static constexpr std::array<std::string_view, 3> kLOAD_CACHE_MODE = {
7272
"sync",
7373
"async",
7474
"none",
@@ -77,17 +77,17 @@ static constexpr std::array<char const*, 3> kLOAD_CACHE_MODE = {
7777
/**
7878
* @brief specific values that are accepted for database type in config.
7979
*/
80-
static constexpr std::array<char const*, 1> kDATABASE_TYPE = {"cassandra"};
80+
static constexpr std::array<std::string_view, 1> kDATABASE_TYPE = {"cassandra"};
8181

8282
/**
8383
* @brief specific values that are accepted for server's processing_policy in config.
8484
*/
85-
static constexpr std::array<char const*, 2> kPROCESSING_POLICY = {"parallel", "sequent"};
85+
static constexpr std::array<std::string_view, 2> kPROCESSING_POLICY = {"parallel", "sequent"};
8686

8787
/**
8888
* @brief specific values that are accepted for database provider in config.
8989
*/
90-
static constexpr std::array<char const*, 2> kPROVIDER = {"cassandra", "aws_keyspace"};
90+
static constexpr std::array<std::string_view, 2> kPROVIDER = {"cassandra", "aws_keyspace"};
9191

9292
/**
9393
* @brief An interface to enforce constraints on certain values within ClioConfigDefinition.
@@ -123,7 +123,7 @@ class Constraint {
123123
*/
124124
template <std::size_t ArrSize>
125125
constexpr std::string
126-
makeErrorMsg(std::string_view key, Value const& value, std::array<char const*, ArrSize> arr) const
126+
makeErrorMsg(std::string_view key, Value const& value, std::array<std::string_view, ArrSize> arr) const
127127
{
128128
// Extract the value from the variant
129129
auto const valueStr = std::visit([](auto const& v) { return fmt::format("{}", v); }, value);
@@ -271,7 +271,7 @@ class OneOf final : public Constraint {
271271
* @param key The key of the ConfigValue that has this constraint
272272
* @param arr The value that has this constraint must be of the values in arr
273273
*/
274-
constexpr OneOf(std::string_view key, std::array<char const*, ArrSize> arr) : key_{key}, arr_{arr}
274+
constexpr OneOf(std::string_view key, std::array<std::string_view, ArrSize> arr) : key_{key}, arr_{arr}
275275
{
276276
}
277277

@@ -318,7 +318,7 @@ class OneOf final : public Constraint {
318318
print(std::ostream& stream) const override
319319
{
320320
std::string valuesStream;
321-
std::ranges::for_each(arr_, [&valuesStream](std::string const& elem) {
321+
std::ranges::for_each(arr_, [&valuesStream](std::string_view elem) {
322322
valuesStream += fmt::format(" `{}`,", elem);
323323
});
324324
// replace the last "," with "."
@@ -327,7 +327,7 @@ class OneOf final : public Constraint {
327327
}
328328

329329
std::string_view key_;
330-
std::array<char const*, ArrSize> arr_;
330+
std::array<std::string_view, ArrSize> arr_;
331331
};
332332

333333
/**

0 commit comments

Comments
 (0)