Skip to content

Commit

Permalink
clear clang-tidy error
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <[email protected]>
  • Loading branch information
Lloyd-Pottiger committed Jun 9, 2022
1 parent 5394c4b commit 247ae77
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/workload/DTWorkload.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ThreadStat
class Statistics
{
public:
Statistics(int write_thread_count = 0, int read_thread_count = 0)
explicit Statistics(int write_thread_count = 0, int read_thread_count = 0)
: init_ms(0)
, write_stats(write_thread_count)
, read_stats(read_thread_count)
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Storages/DeltaMerge/workload/DataGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RandomDataGenerator : public DataGenerator
, rand_gen(std::random_device()())
{}

virtual std::tuple<Block, uint64_t> get(uint64_t key) override
std::tuple<Block, uint64_t> get(uint64_t key) override
{
Block block;
// Generate 'rowkeys'.
Expand Down Expand Up @@ -227,7 +227,9 @@ class RandomDataGenerator : public DataGenerator
struct tm randomLocalTime()
{
time_t t = randomUTCTimestamp();
struct tm res;
struct tm res
{
};
if (localtime_r(&t, &res) == nullptr)
{
throw std::invalid_argument(fmt::format("localtime_r({}) ret {}", t, strerror(errno)));
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/workload/DataGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DataGenerator
public:
static std::unique_ptr<DataGenerator> create(const WorkloadOptions & opts, const TableInfo & table_info, TimestampGenerator & ts_gen);
virtual std::tuple<Block, uint64_t> get(uint64_t key) = 0;
virtual ~DataGenerator() {}
virtual ~DataGenerator() = default;
};

std::string blockToString(const Block & block);
Expand Down
16 changes: 8 additions & 8 deletions dbms/src/Storages/DeltaMerge/workload/Handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HandleLock
static constexpr uint64_t default_lock_count = 4096;

static std::unique_ptr<HandleLock> create(const TableInfo & table_info);
HandleLock(uint64_t lock_count = default_lock_count)
explicit HandleLock(uint64_t lock_count = default_lock_count)
: rmtxs(lock_count)
{}

Expand All @@ -51,14 +51,14 @@ class HandleLock

std::vector<std::unique_lock<std::recursive_mutex>> getLocks(const std::vector<uint64_t> & handles)
{
std::vector<uint64_t> indexes;
std::vector<uint64_t> indexes(handles.size());
for (const auto & h : handles)
{
indexes.push_back(index(h));
}
// Sort mutex indexes to avoid dead lock.
sort(indexes.begin(), indexes.end());
std::vector<std::unique_lock<std::recursive_mutex>> locks;
std::vector<std::unique_lock<std::recursive_mutex>> locks(indexes.size());
for (auto i : indexes)
{
locks.push_back(getLockByIndex(i));
Expand Down Expand Up @@ -105,7 +105,7 @@ class HandleTable
std::lock_guard lock(mtx);
handle_to_ts[handle] = ts;
Record r{handle, ts};
if (wal != nullptr && wal->write((char *)&r, sizeof(r)) != sizeof(r))
if (wal != nullptr && wal->write(reinterpret_cast<char *>(&r), sizeof(r)) != sizeof(r))
{
throw std::runtime_error(fmt::format("write ret {}", strerror(errno)));
}
Expand Down Expand Up @@ -134,8 +134,8 @@ class HandleTable
try
{
PosixRandomAccessFile f(fname, -1);
Record r;
while (f.read((char *)&r, sizeof(r)) == sizeof(r))
Record r{};
while (f.read(reinterpret_cast<char *>(&r), sizeof(r)) == sizeof(r))
{
handle_to_ts[r.handle] = r.ts;
}
Expand All @@ -156,7 +156,7 @@ class HandleTable
for (const auto & pa : handle_to_ts)
{
Record r{pa.first, pa.second};
if (f.write((char *)&r, sizeof(r)) != sizeof(r))
if (f.write(reinterpret_cast<char *>(&r), sizeof(r)) != sizeof(r))
{
throw std::runtime_error(fmt::format("write ret {}", strerror(errno)));
}
Expand Down Expand Up @@ -191,7 +191,7 @@ class SharedHandleTable
public:
static constexpr uint64_t default_shared_count = 4096;

SharedHandleTable(uint64_t max_key_count, const std::string & waldir = "", uint64_t shared_cnt = default_shared_count)
explicit SharedHandleTable(uint64_t max_key_count, const std::string & waldir = "", uint64_t shared_cnt = default_shared_count)
: tables(shared_cnt)
{
uint64_t max_key_count_per_shared = max_key_count / default_shared_count + 1;
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Storages/DeltaMerge/workload/KeyGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IncrementalKeyGenerator : public KeyGenerator
, key(0)
{}

virtual uint64_t get64() override
uint64_t get64() override
{
return key.fetch_add(1, std::memory_order_relaxed) % key_count + start_key;
}
Expand All @@ -54,7 +54,7 @@ class UniformDistributionKeyGenerator : public KeyGenerator
, uniform_dist(0, key_count)
{}

virtual uint64_t get64() override
uint64_t get64() override
{
std::lock_guard lock(mtx);
return uniform_dist(rand_gen);
Expand All @@ -78,7 +78,7 @@ class NormalDistributionKeyGenerator : public KeyGenerator
, normal_dist(key_count / 2.0, key_count / 20.0)
{}

virtual uint64_t get64() override
uint64_t get64() override
{
std::lock_guard lock(mtx);
return normal_dist(rand_gen);
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/DeltaMerge/workload/KeyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class KeyGenerator
public:
static std::unique_ptr<KeyGenerator> create(const WorkloadOptions & opts);

KeyGenerator() {}
virtual ~KeyGenerator() {}
KeyGenerator() = default;
virtual ~KeyGenerator() = default;

virtual uint64_t get64() = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Storages/DeltaMerge/workload/Limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace DB::DM::tests
class ConstantLimiter : public Limiter
{
public:
ConstantLimiter(uint64_t rate_per_sec)
explicit ConstantLimiter(uint64_t rate_per_sec)
: limiter(rate_per_sec, LimiterType::UNKNOW)
{}
virtual void request() override
void request() override
{
limiter.request(1);
}
Expand All @@ -38,7 +38,7 @@ class ConstantLimiter : public Limiter

std::unique_ptr<Limiter> Limiter::create(const WorkloadOptions & opts)
{
uint64_t per_sec = std::ceil(static_cast<double>(opts.max_write_per_sec / opts.write_thread_count));
uint64_t per_sec = std::ceil(opts.max_write_per_sec * 1.0 / opts.write_thread_count);
return std::make_unique<ConstantLimiter>(per_sec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ReadColumnsGenerator
return std::make_unique<ReadColumnsGenerator>(table_info);
}

ReadColumnsGenerator(const TableInfo & table_info_)
explicit ReadColumnsGenerator(const TableInfo & table_info_)
: table_info(table_info_)
, rand_gen(std::random_device()())
, uniform_dist(0, table_info_.columns->size() - 1)
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/DeltaMerge/workload/TableGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class RandomTableGenerator : public TableGenerator
, rand_gen(std::random_device()())
{}

virtual TableInfo get(int64_t table_id, std::string table_name) override
TableInfo get(int64_t table_id, std::string table_name) override
{
TableInfo table_info;

Expand Down Expand Up @@ -293,7 +293,7 @@ class RandomTableGenerator : public TableGenerator

class ConstantTableGenerator : public TableGenerator
{
virtual TableInfo get(int64_t table_id, std::string table_name) override
TableInfo get(int64_t table_id, std::string table_name) override
{
TableInfo table_info;

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/workload/TableGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ class TableGenerator

virtual TableInfo get(int64_t table_id, std::string table_name) = 0;

virtual ~TableGenerator() {}
virtual ~TableGenerator() = default;
};
} // namespace DB::DM::tests
6 changes: 3 additions & 3 deletions dbms/src/Storages/DeltaMerge/workload/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::string fieldToString(const DataTypePtr & data_type, const Field & f)
}
else if (t == Field::Types::Which::Decimal256)
{
auto i = f.get<Decimal256>();
const auto & i = f.get<Decimal256>();
auto scale = dynamic_cast<const DataTypeDecimal256 *>(data_type.get())->getScale();
return i.toString(scale);
}
Expand All @@ -105,8 +105,8 @@ std::vector<std::string> colToVec(const DataTypePtr & data_type, const ColumnPtr
std::string blockToString(const Block & block)
{
std::string s = "id name type values\n";
auto & cols = block.getColumnsWithTypeAndName();
for (auto & col : cols)
const auto & cols = block.getColumnsWithTypeAndName();
for (const auto & col : cols)
{
s += fmt::format("{} {} {} {}\n", col.column_id, col.name, col.type->getFamilyName(), colToVec(col.type, col.column));
}
Expand Down

0 comments on commit 247ae77

Please sign in to comment.