Skip to content

Commit

Permalink
Apply new clang-tidy rules
Browse files Browse the repository at this point in the history
  • Loading branch information
godexsoft committed Dec 26, 2024
1 parent 4c94d26 commit 04a6da8
Show file tree
Hide file tree
Showing 47 changed files with 589 additions and 583 deletions.
12 changes: 6 additions & 6 deletions src/main/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ try {
std::cerr << json.error().error << std::endl;
return EXIT_FAILURE;
}
auto const errors = ClioConfig.parse(json.value());
auto const errors = gClioConfig.parse(json.value());
if (errors.has_value()) {
for (auto const& err : errors.value())
std::cerr << err.error << std::endl;
return EXIT_FAILURE;
}
util::LogService::init(ClioConfig);
app::ClioApplication clio{ClioConfig};
util::LogService::init(gClioConfig);
app::ClioApplication clio{gClioConfig};
return clio.run(run.useNgWebServer);
},
[](app::CliArgs::Action::Migrate const& migrate) {
Expand All @@ -62,14 +62,14 @@ try {
std::cerr << json.error().error << std::endl;
return EXIT_FAILURE;
}
auto const errors = ClioConfig.parse(json.value());
auto const errors = gClioConfig.parse(json.value());
if (errors.has_value()) {
for (auto const& err : errors.value())
std::cerr << err.error << std::endl;
return EXIT_FAILURE;
}
util::LogService::init(ClioConfig);
app::MigratorApplication migrator{ClioConfig, migrate.subCmd};
util::LogService::init(gClioConfig);
app::MigratorApplication migrator{gClioConfig, migrate.subCmd};
return migrator.run();
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/migration/MigratiorStatus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MigratorStatus {
fromString(std::string const& statusStr);

private:
static constexpr std::array<char const*, static_cast<size_t>(NumStatuses)> statusStrMap = {
static constexpr std::array<char const*, static_cast<size_t>(NumStatuses)> kSTATUS_STR_MAP = {
"Migrated",
"NotMigrated",
"NotKnown"
Expand Down
6 changes: 3 additions & 3 deletions src/migration/MigratorStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ MigratorStatus::operator==(Status const& other) const
std::string
MigratorStatus::toString() const
{
return statusStrMap[static_cast<size_t>(status_)];
return kSTATUS_STR_MAP[static_cast<size_t>(status_)];
}

MigratorStatus
MigratorStatus::fromString(std::string const& statusStr)
{
for (std::size_t i = 0; i < statusStrMap.size(); ++i) {
if (statusStr == statusStrMap[i]) {
for (std::size_t i = 0; i < kSTATUS_STR_MAP.size(); ++i) {
if (statusStr == kSTATUS_STR_MAP[i]) {
return MigratorStatus(static_cast<Status>(i));
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/migration/cassandra/CassandraMigrationBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ class CassandraMigrationBackend : public data::cassandra::CassandraBackend {
)
{
LOG(log_.debug()) << "Travsering token range: " << start << " - " << end
<< " ; table: " << TableDesc::TABLE_NAME;
<< " ; table: " << TableDesc::kTABLE_NAME;
// for each table we only have one prepared statement
static auto statementPrepared =
migrationSchema_.getPreparedFullScanStatement(handle_, TableDesc::TABLE_NAME, TableDesc::PARTITION_KEY);
static auto kSTATEMENT_PREPARED =
migrationSchema_.getPreparedFullScanStatement(handle_, TableDesc::kTABLE_NAME, TableDesc::kPARTITION_KEY);

auto const statement = statementPrepared.bind(start, end);
auto const statement = kSTATEMENT_PREPARED.bind(start, end);

auto const res = this->executor_.read(yield, statement);
if (not res) {
LOG(log_.error()) << "Could not fetch data from table: " << TableDesc::TABLE_NAME << " range: " << start
LOG(log_.error()) << "Could not fetch data from table: " << TableDesc::kTABLE_NAME << " range: " << start
<< " - " << end << ";" << res.error();
return;
}

auto const& results = res.value();
if (not results.hasRows()) {
LOG(log_.debug()) << "No rows returned - table: " << TableDesc::TABLE_NAME << " range: " << start << " - "
LOG(log_.debug()) << "No rows returned - table: " << TableDesc::kTABLE_NAME << " range: " << start << " - "
<< end;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/migration/cassandra/impl/CassandraMigrationSchema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ class CassandraMigrationSchema {
data::cassandra::PreparedStatement const&
getPreparedInsertMigratedMigrator(data::cassandra::Handle const& handler)
{
static auto prepared = handler.prepare(fmt::format(
static auto kPREPARED = handler.prepare(fmt::format(
R"(
INSERT INTO {}
(migrator_name, status)
VALUES (?, ?)
)",
data::cassandra::qualifiedTableName<SettingsProviderType>(settingsProvider_.get(), "migrator_status")
));
return prepared;
return kPREPARED;
}
};
} // namespace migration::cassandra::impl
14 changes: 7 additions & 7 deletions src/migration/cassandra/impl/FullTableScanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class FullTableScanner {
* @brief The helper to generate the token ranges.
*/
struct TokenRangesProvider {
uint32_t numRanges_;
uint32_t numRanges;

TokenRangesProvider(uint32_t numRanges) : numRanges_{numRanges}
TokenRangesProvider(uint32_t numRanges) : numRanges{numRanges}
{
}

Expand All @@ -85,18 +85,18 @@ class FullTableScanner {
{
auto const minValue = std::numeric_limits<std::int64_t>::min();
auto const maxValue = std::numeric_limits<std::int64_t>::max();
if (numRanges_ == 1)
if (numRanges == 1)
return {TokenRange{minValue, maxValue}};

// Safely calculate the range size using uint64_t to avoid overflow
uint64_t const rangeSize = (static_cast<uint64_t>(maxValue) * 2) / numRanges_;
uint64_t const rangeSize = (static_cast<uint64_t>(maxValue) * 2) / numRanges;

std::vector<TokenRange> ranges;
ranges.reserve(numRanges_);
ranges.reserve(numRanges);

for (std::int64_t i = 0; i < numRanges_; ++i) {
for (std::int64_t i = 0; i < numRanges; ++i) {
int64_t const start = minValue + (i * rangeSize);
int64_t const end = (i == numRanges_ - 1) ? maxValue : start + static_cast<int64_t>(rangeSize) - 1;
int64_t const end = (i == numRanges - 1) ? maxValue : start + static_cast<int64_t>(rangeSize) - 1;
ranges.emplace_back(start, end);
}

Expand Down
4 changes: 2 additions & 2 deletions src/migration/cassandra/impl/ObjectsAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace migration::cassandra::impl {
*/
struct TableObjectsDesc {
using Row = std::tuple<ripple::uint256, std::uint32_t, data::Blob>;
static constexpr char const* PARTITION_KEY = "key";
static constexpr char const* TABLE_NAME = "objects";
static constexpr char const* kPARTITION_KEY = "key";
static constexpr char const* kTABLE_NAME = "objects";
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/migration/cassandra/impl/Spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ concept TableSpec = requires {
requires std::tuple_size<typename T::Row>::value >= 0; // Ensures 'row' is a tuple

// Check that static constexpr members 'partitionKey' and 'tableName' exist
{ T::PARTITION_KEY } -> std::convertible_to<char const*>;
{ T::TABLE_NAME } -> std::convertible_to<char const*>;
{ T::kPARTITION_KEY } -> std::convertible_to<char const*>;
{ T::kTABLE_NAME } -> std::convertible_to<char const*>;
};
} // namespace migration::cassandra::impl
4 changes: 2 additions & 2 deletions src/migration/cassandra/impl/TransactionsAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace migration::cassandra::impl {
struct TableTransactionsDesc {
// hash, date, ledger_seq, metadata, transaction
using Row = std::tuple<ripple::uint256, std::uint64_t, std::uint32_t, ripple::Blob, ripple::Blob>;
static constexpr char const* PARTITION_KEY = "hash";
static constexpr char const* TABLE_NAME = "transactions";
static constexpr char const* kPARTITION_KEY = "hash";
static constexpr char const* kTABLE_NAME = "transactions";
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/migration/impl/MigrationManagerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ namespace migration::impl {
std::expected<std::shared_ptr<MigrationManagerInterface>, std::string>
makeMigrationManager(util::config::ClioConfigDefinition const& config)
{
static util::Logger const log{"Migration"};
LOG(log.info()) << "Constructing MigrationManager";
static util::Logger const kLOG{"Migration"};
LOG(kLOG.info()) << "Constructing MigrationManager";

auto const type = config.get<std::string>("database.type");

if (not boost::iequals(type, "cassandra")) {
LOG(log.error()) << "Unknown database type to migrate: " << type;
LOG(kLOG.error()) << "Unknown database type to migrate: " << type;
return std::unexpected(std::string("Invalid database type"));
}

Expand Down
6 changes: 3 additions & 3 deletions src/migration/impl/MigratorsRegister.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MigratorsRegister {
void
callMigration(std::string const& name, util::config::ObjectView const& config)
{
if (name == Migrator::name) {
if (name == Migrator::kNAME) {
LOG(log_.info()) << "Running migration: " << name;
Migrator::runMigration(backend_, config);
backend_->writeMigratorStatus(name, MigratorStatus(MigratorStatus::Migrated).toString());
Expand All @@ -78,7 +78,7 @@ class MigratorsRegister {
static constexpr std::string_view
getDescriptionIfMatch(std::string_view targetName)
{
return (T::name == targetName) ? T::description : "";
return (T::kNAME == targetName) ? T::kDESCRIPTION : "";
}

public:
Expand Down Expand Up @@ -156,7 +156,7 @@ class MigratorsRegister {
constexpr auto
getMigratorNames() const
{
return std::array<std::string_view, sizeof...(MigratorType)>{MigratorType::name...};
return std::array<std::string_view, sizeof...(MigratorType)>{MigratorType::kNAME...};
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/migration/impl/Spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace migration::impl {
*/
template <typename T, typename Backend>
concept MigratorSpec = requires(std::shared_ptr<Backend> const& backend, util::config::ObjectView const& cfg) {
// Check that 'name' exists and is a string
{ T::name } -> std::convertible_to<std::string>;
// Check that 'kNAME' exists and is a string
{ T::kNAME } -> std::convertible_to<std::string>;

// Check that 'description' exists and is a string
{ T::description } -> std::convertible_to<std::string>;
// Check that 'kDESCRIPTION' exists and is a string
{ T::kDESCRIPTION } -> std::convertible_to<std::string>;

// Check that the migrator specifies the backend type it supports
typename T::Backend;
Expand Down
6 changes: 3 additions & 3 deletions src/util/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ template <typename... Types>
constexpr bool
hasNoDuplicateNames()
{
constexpr std::array<std::string_view, sizeof...(Types)> names = {Types::name...};
return !std::ranges::any_of(names, [&](std::string_view const& name1) {
return std::ranges::any_of(names, [&](std::string_view const& name2) {
constexpr std::array<std::string_view, sizeof...(Types)> kNAMES = {Types::kNAME...};
return !std::ranges::any_of(kNAMES, [&](std::string_view const& name1) {
return std::ranges::any_of(kNAMES, [&](std::string_view const& name2) {
return &name1 != &name2 && name1 == name2; // Ensure different elements are compared
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/util/newconfig/ConfigDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class ClioConfigDefinition {
* Specifies which keys are valid in Clio Config and provides default values if user's do not specify one. Those
* without default values must be present in the user's config file.
*/
static ClioConfigDefinition ClioConfig = ClioConfigDefinition{
static ClioConfigDefinition gClioConfig = ClioConfigDefinition{
{{"database.type", ConfigValue{ConfigType::String}.defaultValue("cassandra").withConstraint(gValidateCassandraName)
},
{"database.cassandra.contact_points", ConfigValue{ConfigType::String}.defaultValue("localhost")},
Expand Down
8 changes: 4 additions & 4 deletions tests/common/migration/TestMigrators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

struct SimpleTestMigrator {
using Backend = MockMigrationBackend;
static constexpr auto name = "SimpleTestMigrator";
static constexpr auto description = "The migrator for version 0 -> 1";
static constexpr auto kNAME = "SimpleTestMigrator";
static constexpr auto kDESCRIPTION = "The migrator for version 0 -> 1";
static void
runMigration(std::shared_ptr<MockMigrationBackend>, util::config::ObjectView const&)
{
Expand All @@ -39,8 +39,8 @@ struct SimpleTestMigrator {

struct SimpleTestMigrator2 {
using Backend = MockMigrationBackend;
static constexpr auto name = "SimpleTestMigrator2";
static constexpr auto description = "The migrator for version 1 -> 2";
static constexpr auto kNAME = "SimpleTestMigrator2";
static constexpr auto kDESCRIPTION = "The migrator for version 1 -> 2";
static void
runMigration(std::shared_ptr<MockMigrationBackend>, util::config::ObjectView const&)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/common/util/MockMigrationBackendFixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@
template <template <typename> typename MockType = ::testing::NiceMock>
struct MockMigrationBackendTestBase : virtual public NoLoggerFixture {
class BackendProxy {
std::shared_ptr<MockType<MockMigrationBackend>> backend =
std::shared_ptr<MockType<MockMigrationBackend>> backend_ =
std::make_shared<MockType<MockMigrationBackend>>(util::config::ClioConfigDefinition{});

public:
auto
operator->()
{
return backend.get();
return backend_.get();
}

operator std::shared_ptr<MockMigrationBackend>()
{
return backend;
return backend_;
}

operator std::shared_ptr<MockMigrationBackend const>() const
{
return backend;
return backend_;
}

MockType<MockMigrationBackend>&
operator*()
{
return *backend;
return *backend_;
}
};

Expand Down
Loading

0 comments on commit 04a6da8

Please sign in to comment.