Enable clang-tidy for programs and utils

This commit is contained in:
Alexey Milovidov 2020-05-18 04:19:50 +03:00
parent 073dc2e1e3
commit b0a5ce7743
13 changed files with 48 additions and 43 deletions

View File

@ -1,3 +1,7 @@
if (USE_CLANG_TIDY)
set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
endif ()
# 'clickhouse' binary is a multi purpose tool,
# that contain multiple execution modes (client, server, etc.)
# each of them is built and linked as a separate library, defined below.

View File

@ -24,8 +24,8 @@ namespace
query.table_id.table_name = table_name;
query.columns = std::make_shared<ASTExpressionList>(',');
query.children.push_back(query.columns);
for (size_t i = 0; i < columns.size(); ++i)
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(columns[i].name));
for (const auto & column : columns)
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
std::stringstream ss;
IAST::FormatSettings settings(ss, true);

View File

@ -56,8 +56,8 @@ int main(int, char **)
MutableColumnPtr mut = IColumn::mutate(std::move(y));
mut->set(2);
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
y = std::move(mut);
}
@ -75,8 +75,8 @@ int main(int, char **)
MutableColumnPtr mut = IColumn::mutate(std::move(y));
mut->set(3);
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
y = std::move(mut);
}

View File

@ -75,8 +75,8 @@ int main(int, char **)
MutableColumnPtr mut = IColumn::mutate(std::move(y));
mut->set(2);
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << mut.get() << "\n";
y = std::move(mut);
}
@ -94,8 +94,8 @@ int main(int, char **)
MutableColumnPtr mut = IColumn::mutate(std::move(y));
mut->set(3);
std::cerr << "refcounts: " << x->use_count() << ", " << y->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << y.get() << ", " << mut.get() << "\n";
std::cerr << "refcounts: " << x->use_count() << ", " << mut->use_count() << "\n";
std::cerr << "addresses: " << x.get() << ", " << ", " << mut.get() << "\n";
y = std::move(mut);
}

View File

@ -1,3 +1,7 @@
if (USE_CLANG_TIDY)
set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
endif ()
if(MAKE_STATIC_LIBRARIES)
set(MAX_LINKER_MEMORY 3500)
else()

View File

@ -30,7 +30,7 @@ void run(String part_path, String date_column, String dest_path)
{
std::shared_ptr<IDisk> disk = std::make_shared<DiskLocal>("local", "/", 0);
auto old_part_path = Poco::Path::forDirectory(part_path);
String old_part_name = old_part_path.directory(old_part_path.depth() - 1);
const String & old_part_name = old_part_path.directory(old_part_path.depth() - 1);
String old_part_path_str = old_part_path.toString();
auto part_info = MergeTreePartInfo::fromPartName(old_part_name, MergeTreeDataFormatVersion(0));

View File

@ -59,9 +59,9 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
for (size_t i = 0; i < count; ++i)
{
long rand_result1 = rng();
long rand_result2 = rng();
long rand_result3 = rng();
uint64_t rand_result1 = rng();
uint64_t rand_result2 = rng();
uint64_t rand_result3 = rng();
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
size_t offset;
@ -152,7 +152,7 @@ int mainImpl(int argc, char ** argv)
Stopwatch watch;
for (size_t i = 0; i < threads; ++i)
pool.scheduleOrThrowOnError(std::bind(thread, fd, mode, min_offset, max_offset, block_size, count));
pool.scheduleOrThrowOnError([=]{ thread(fd, mode, min_offset, max_offset, block_size, count); });
pool.wait();
fsync(fd);

View File

@ -13,6 +13,8 @@ int main(int, char **) { return 0; }
#include <Common/Exception.h>
#include <Common/ThreadPool.h>
#include <Common/Stopwatch.h>
#include <Common/randomSeed.h>
#include <pcg_random.hpp>
#include <IO/BufferWithOwnMemory.h>
#include <IO/ReadHelpers.h>
#include <stdio.h>
@ -52,10 +54,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
for (size_t i = 0; i < buffers_count; ++i)
buffers[i] = Memory<>(block_size, sysconf(_SC_PAGESIZE));
drand48_data rand_data;
timespec times;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &times);
srand48_r(times.tv_nsec, &rand_data);
pcg64_fast rng(randomSeed());
size_t in_progress = 0;
size_t blocks_sent = 0;
@ -82,12 +81,9 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
char * buf = buffers[i].data();
long rand_result1 = 0;
long rand_result2 = 0;
long rand_result3 = 0;
lrand48_r(&rand_data, &rand_result1);
lrand48_r(&rand_data, &rand_result2);
lrand48_r(&rand_data, &rand_result3);
uint64_t rand_result1 = rng();
uint64_t rand_result2 = rng();
uint64_t rand_result3 = rng();
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
size_t offset = min_offset + rand_result % ((max_offset - min_offset) / block_size) * block_size;
@ -172,7 +168,7 @@ int mainImpl(int argc, char ** argv)
Stopwatch watch;
for (size_t i = 0; i < threads_count; ++i)
pool.scheduleOrThrowOnError(std::bind(thread, fd, mode, min_offset, max_offset, block_size, buffers_count, count));
pool.scheduleOrThrowOnError([=]{ thread(fd, mode, min_offset, max_offset, block_size, buffers_count, count); });
pool.wait();
watch.stop();

View File

@ -113,9 +113,9 @@ int mainImpl(int argc, char ** argv)
polls[i].revents = 0;
++ops;
long rand_result1 = rng();
long rand_result2 = rng();
long rand_result3 = rng();
uint64_t rand_result1 = rng();
uint64_t rand_result2 = rng();
uint64_t rand_result3 = rng();
size_t rand_result = rand_result1 ^ (rand_result2 << 22) ^ (rand_result3 << 43);
size_t offset;

View File

@ -1,3 +1,6 @@
# Disable clang-tidy for protobuf generated files
set (CMAKE_CXX_CLANG_TIDY "")
add_compile_options(-Wno-zero-as-null-pointer-constant -Wno-array-bounds) # Protobuf generated files
if (USE_PROTOBUF)

View File

@ -102,7 +102,7 @@ std::unordered_map<std::string, Int64> getPartitionsNeedAdjustingBlockNumbers(
std::cout << "Shard: " << shard << std::endl;
std::vector<std::string> use_tables = tables.empty() ? getAllTables(zk, root, shard) : removeNotExistingTables(zk, root, shard, tables);
for (auto table : use_tables)
for (const auto & table : use_tables)
{
std::cout << "\tTable: " << table << std::endl;
std::string table_path = root + "/" + shard + "/" + table;
@ -121,7 +121,7 @@ std::unordered_map<std::string, Int64> getPartitionsNeedAdjustingBlockNumbers(
continue;
}
for (auto partition : partitions)
for (const auto & partition : partitions)
{
try
{

View File

@ -97,10 +97,8 @@ int main(int argc, char ** argv)
bool watch = w == "w";
zkutil::EventPtr event = watch ? std::make_shared<Poco::Event>() : nullptr;
std::vector<std::string> v = zk.getChildren(path, nullptr, event);
for (size_t i = 0; i < v.size(); ++i)
{
std::cout << v[i] << std::endl;
}
for (const auto & child : v)
std::cout << child << std::endl;
if (watch)
waitForWatch(event);
}
@ -193,7 +191,7 @@ int main(int argc, char ** argv)
zk.set(path, data, version, &stat);
printStat(stat);
}
else if (cmd != "")
else if (!cmd.empty())
{
std::cout << "commands:\n";
std::cout << " q\n";