Merge pull request #10779 from ClickHouse/even-more-warnings

Enable extra warnings for base, utils, programs
This commit is contained in:
alexey-milovidov 2020-05-11 05:46:03 +03:00 committed by GitHub
commit d4ff187ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 396 additions and 497 deletions

View File

@ -103,16 +103,7 @@ endif ()
include (cmake/add_warning.cmake)
if (NOT MSVC)
set (COMMON_WARNING_FLAGS "${COMMON_WARNING_FLAGS} -Wall") # -Werror is also added inside directories with our own code.
endif ()
if (COMPILER_GCC OR COMPILER_CLANG)
set (CXX_WARNING_FLAGS "${CXX_WARNING_FLAGS} -Wnon-virtual-dtor")
endif ()
if (COMPILER_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "8.3.0")
# Warnings in protobuf generating
set (CXX_WARNING_FLAGS "${CXX_WARNING_FLAGS} -Wno-array-bounds")
set (COMMON_WARNING_FLAGS "${COMMON_WARNING_FLAGS} -Wall") # -Werror and many more is also added inside cmake/warnings.cmake
endif ()
if (COMPILER_CLANG)
@ -412,6 +403,9 @@ endmacro()
set(ConfigIncludePath ${CMAKE_CURRENT_BINARY_DIR}/includes/configs CACHE INTERNAL "Path to generated configuration files.")
include_directories(${ConfigIncludePath})
# Add as many warnings as possible for our own code.
include (cmake/warnings.cmake)
add_subdirectory (base)
add_subdirectory (programs)
add_subdirectory (src)

View File

@ -31,9 +31,8 @@ UInt8 getDayOfWeek(const cctz::civil_day & date)
case cctz::weekday::friday: return 5;
case cctz::weekday::saturday: return 6;
case cctz::weekday::sunday: return 7;
default:
throw Poco::Exception("Logical error: incorrect week day.");
}
__builtin_unreachable();
}
}

View File

@ -451,7 +451,10 @@ JSON JSON::operator[] (size_t n) const
size_t i = 0;
const_iterator it = begin();
while (i < n && it != end())
++it, ++i;
{
++it;
++i;
}
if (i != n)
throw JSONException("JSON: array index " + std::to_string(n) + " out of bounds.");
@ -626,7 +629,7 @@ std::string JSON::getString() const
{
unicode = Poco::NumberParser::parseHex(hex);
}
catch (const Poco::SyntaxException & e)
catch (const Poco::SyntaxException &)
{
throw JSONException("JSON: incorrect syntax: incorrect HEX code.");
}

View File

@ -3,14 +3,18 @@
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
#define MEMORY_SANITIZER 1
#else
#define MEMORY_SANITIZER 0
#endif
#elif defined(__MEMORY_SANITIZER__)
#define MEMORY_SANITIZER 1
#else
#define MEMORY_SANITIZER 0
#endif
#if _MSC_VER || MEMORY_SANITIZER
#if defined(_MSC_VER) || MEMORY_SANITIZER
DemangleResult tryDemangle(const char * name)
DemangleResult tryDemangle(const char *)
{
return DemangleResult{};
}

View File

@ -1,9 +1,9 @@
#include <common/getThreadId.h>
#if OS_LINUX
#if defined(OS_LINUX)
#include <unistd.h>
#include <syscall.h>
#elif OS_FREEBSD
#elif defined(OS_FREEBSD)
#include <pthread_np.h>
#else
#include <pthread.h>
@ -16,9 +16,9 @@ uint64_t getThreadId()
{
if (!current_tid)
{
#if OS_LINUX
#if defined(OS_LINUX)
current_tid = syscall(SYS_gettid); /// This call is always successful. - man gettid
#elif OS_FREEBSD
#elif defined(OS_FREEBSD)
current_tid = pthread_getthreadid_np();
#else
if (0 != pthread_threadid_np(nullptr, &current_tid))

View File

@ -19,7 +19,7 @@ void * mremap_fallback(
return MAP_FAILED;
}
#if _MSC_VER
#if defined(_MSC_VER)
void * new_address = ::operator new(new_size);
#else
void * new_address = mmap(nullptr, new_size, mmap_prot, mmap_flags, mmap_fd, mmap_offset);
@ -29,7 +29,7 @@ void * mremap_fallback(
memcpy(new_address, old_address, old_size);
#if _MSC_VER
#if defined(_MSC_VER)
delete old_address;
#else
if (munmap(old_address, old_size))

View File

@ -20,6 +20,14 @@
#define USE_PHDR_CACHE 1
#endif
/// Thread Sanitizer uses dl_iterate_phdr function on initialization and fails if we provide our own.
#ifdef USE_PHDR_CACHE
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wreserved-id-macro"
# pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define __msan_unpoison(X, Y)
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
@ -28,9 +36,6 @@
# endif
#endif
/// Thread Sanitizer uses dl_iterate_phdr function on initialization and fails if we provide our own.
#ifdef USE_PHDR_CACHE
#include <link.h>
#include <dlfcn.h>
#include <vector>

View File

@ -22,7 +22,7 @@ void sleepForNanoseconds(uint64_t nanoseconds)
#if defined(OS_DARWIN)
//https://developer.apple.com/library/archive/technotes/tn2169/_index.html
//https://dshil.github.io/blog/missed-os-x-clock-guide/
static mach_timebase_info_data_t timebase_info = {0};
static mach_timebase_info_data_t timebase_info{};
if (timebase_info.denom == 0)
mach_timebase_info(&timebase_info);

View File

@ -1,5 +1,3 @@
#define BOOST_TEST_MODULE StrongTypedef
#include <common/strong_typedef.h>
#include <set>
#include <unordered_set>
@ -12,15 +10,15 @@
TEST(StrongTypedefSuite, TypedefsOfTheSameType)
{
/// check that strong typedefs of same type differ
STRONG_TYPEDEF(int, Int);
STRONG_TYPEDEF(int, AnotherInt);
STRONG_TYPEDEF(int, Int)
STRONG_TYPEDEF(int, AnotherInt)
EXPECT_TRUE(!(std::is_same<Int, AnotherInt>::value));
}
TEST(StrongTypedefSuite, Map)
{
STRONG_TYPEDEF(int, Int);
STRONG_TYPEDEF(int, Int)
/// check that this code compiles
std::set<Int> int_set;
@ -31,13 +29,13 @@ TEST(StrongTypedefSuite, Map)
TEST(StrongTypedefSuite, CopyAndMoveCtor)
{
STRONG_TYPEDEF(int, Int);
STRONG_TYPEDEF(int, Int)
Int a(1);
Int b(2);
a = b;
EXPECT_EQ(a.toUnderType(), 2);
STRONG_TYPEDEF(std::unique_ptr<int>, IntPtr);
STRONG_TYPEDEF(std::unique_ptr<int>, IntPtr)
{
IntPtr ptr;
ptr = IntPtr(std::make_unique<int>(3));
@ -57,6 +55,6 @@ TEST(StrongTypedefSuite, NoDefaultCtor)
NoDefaultCtor(int) {} // NOLINT
};
STRONG_TYPEDEF(NoDefaultCtor, MyStruct);
STRONG_TYPEDEF(NoDefaultCtor, MyStruct)
MyStruct m(1);
}

View File

@ -52,11 +52,12 @@
#include <Common/Config/ConfigProcessor.h>
#if !defined(ARCADIA_BUILD)
# include <Common/config_version.h>
# include <Common/config_version.h>
#endif
#if defined(OS_DARWIN)
# define _XOPEN_SOURCE 700 // ucontext is not available without _XOPEN_SOURCE
# pragma GCC diagnostic ignored "-Wunused-macros"
# define _XOPEN_SOURCE 700 // ucontext is not available without _XOPEN_SOURCE
#endif
#include <ucontext.h>
@ -76,7 +77,7 @@ static void call_default_signal_handler(int sig)
static constexpr size_t max_query_id_size = 127;
static const size_t buf_size =
static const size_t signal_pipe_buf_size =
sizeof(int)
+ sizeof(siginfo_t)
+ sizeof(ucontext_t)
@ -91,8 +92,8 @@ static void writeSignalIDtoSignalPipe(int sig)
{
auto saved_errno = errno; /// We must restore previous value of errno in signal handler.
char buf[buf_size];
DB::WriteBufferFromFileDescriptor out(signal_pipe.fds_rw[1], buf_size, buf);
char buf[signal_pipe_buf_size];
DB::WriteBufferFromFileDescriptor out(signal_pipe.fds_rw[1], signal_pipe_buf_size, buf);
DB::writeBinary(sig, out);
out.next();
@ -117,8 +118,8 @@ static void signalHandler(int sig, siginfo_t * info, void * context)
{
auto saved_errno = errno; /// We must restore previous value of errno in signal handler.
char buf[buf_size];
DB::WriteBufferFromFileDescriptorDiscardOnFailure out(signal_pipe.fds_rw[1], buf_size, buf);
char buf[signal_pipe_buf_size];
DB::WriteBufferFromFileDescriptorDiscardOnFailure out(signal_pipe.fds_rw[1], signal_pipe_buf_size, buf);
const ucontext_t signal_context = *reinterpret_cast<ucontext_t *>(context);
const StackTrace stack_trace(signal_context);
@ -166,10 +167,10 @@ public:
{
}
void run()
void run() override
{
char buf[buf_size];
DB::ReadBufferFromFileDescriptor in(signal_pipe.fds_rw[0], buf_size, buf);
char buf[signal_pipe_buf_size];
DB::ReadBufferFromFileDescriptor in(signal_pipe.fds_rw[0], signal_pipe_buf_size, buf);
while (!in.eof())
{
@ -287,14 +288,11 @@ private:
* and send it to pipe. Other thread will read this info from pipe and asynchronously write it to log.
* Look at libstdc++-v3/libsupc++/vterminate.cc for example.
*/
static void terminate_handler()
[[noreturn]] static void terminate_handler()
{
static thread_local bool terminating = false;
if (terminating)
{
abort();
return; /// Just for convenience.
}
terminating = true;
@ -524,12 +522,12 @@ void BaseDaemon::initialize(Application & self)
/// This must be done before any usage of DateLUT. In particular, before any logging.
if (config().has("timezone"))
{
const std::string timezone = config().getString("timezone");
if (0 != setenv("TZ", timezone.data(), 1))
const std::string config_timezone = config().getString("timezone");
if (0 != setenv("TZ", config_timezone.data(), 1))
throw Poco::Exception("Cannot setenv TZ variable");
tzset();
DateLUT::setDefaultTimezone(timezone);
DateLUT::setDefaultTimezone(config_timezone);
}
std::string log_path = config().getString("logger.log", "");
@ -636,12 +634,18 @@ void BaseDaemon::initializeTerminationAndSignalProcessing()
sa.sa_flags = SA_SIGINFO;
{
#if defined(OS_DARWIN)
sigemptyset(&sa.sa_mask);
for (auto signal : signals)
sigaddset(&sa.sa_mask, signal);
#else
if (sigemptyset(&sa.sa_mask))
throw Poco::Exception("Cannot set signal handler.");
for (auto signal : signals)
if (sigaddset(&sa.sa_mask, signal))
throw Poco::Exception("Cannot set signal handler.");
#endif
for (auto signal : signals)
if (sigaction(signal, &sa, nullptr))
@ -690,37 +694,37 @@ void BaseDaemon::handleNotification(Poco::TaskFailedNotification *_tfn)
ServerApplication::terminate();
}
void BaseDaemon::defineOptions(Poco::Util::OptionSet& _options)
void BaseDaemon::defineOptions(Poco::Util::OptionSet & new_options)
{
Poco::Util::ServerApplication::defineOptions (_options);
_options.addOption(
new_options.addOption(
Poco::Util::Option("config-file", "C", "load configuration from a given file")
.required(false)
.repeatable(false)
.argument("<file>")
.binding("config-file"));
_options.addOption(
new_options.addOption(
Poco::Util::Option("log-file", "L", "use given log file")
.required(false)
.repeatable(false)
.argument("<file>")
.binding("logger.log"));
_options.addOption(
new_options.addOption(
Poco::Util::Option("errorlog-file", "E", "use given log file for errors only")
.required(false)
.repeatable(false)
.argument("<file>")
.binding("logger.errorlog"));
_options.addOption(
new_options.addOption(
Poco::Util::Option("pid-file", "P", "use given pidfile")
.required(false)
.repeatable(false)
.argument("<file>")
.binding("pid"));
Poco::Util::ServerApplication::defineOptions(new_options);
}
bool isPidRunning(pid_t pid)

View File

@ -58,7 +58,7 @@ public:
void reloadConfiguration();
/// Определяет параметр командной строки
void defineOptions(Poco::Util::OptionSet & _options) override;
void defineOptions(Poco::Util::OptionSet & new_options) override;
/// Заставляет демон завершаться, если хотя бы одна задача завершилась неудачно
void exitOnTaskError();

View File

@ -18,8 +18,6 @@ std::string errorMessage(MYSQL * driver)
return res.str();
}
/// Для внутренних нужд библиотеки.
void checkError(MYSQL * driver)
{
unsigned num = mysql_errno(driver);
@ -28,8 +26,6 @@ void checkError(MYSQL * driver)
throw Exception(errorMessage(driver), num);
}
/// Для внутренних нужд библиотеки.
void onError(MYSQL * driver)
{
throw Exception(errorMessage(driver), mysql_errno(driver));

View File

@ -48,6 +48,6 @@ std::string errorMessage(MYSQL * driver);
/// For internal need of library.
void checkError(MYSQL * driver);
void onError(MYSQL * driver);
[[noreturn]] void onError(MYSQL * driver);
}

View File

@ -27,7 +27,7 @@ public:
Null() : is_null(true) {}
Null(const Null<T> &) = default;
Null(Null<T> &&) noexcept = default;
Null(NullType data) : is_null(true) {}
Null(NullType) : is_null(true) {}
explicit Null(const T & data_) : data(data_), is_null(false) {}
operator T & ()
@ -47,7 +47,7 @@ public:
Null<T> & operator= (Null<T> &&) noexcept = default;
Null<T> & operator= (const Null<T> &) = default;
Null<T> & operator= (const T & data_) { is_null = false; data = data_; return *this; }
Null<T> & operator= (const NullType other) { is_null = true; data = T(); return *this; }
Null<T> & operator= (const NullType) { is_null = true; data = T(); return *this; }
bool isNull() const { return is_null; }
@ -57,7 +57,7 @@ public:
|| (is_null == other.is_null && data < other.data);
}
bool operator< (const NullType other) const { return false; }
bool operator< (const NullType) const { return false; }
bool operator== (const Null<T> & other) const
{
@ -69,14 +69,14 @@ public:
return !is_null && data == other;
}
bool operator== (const NullType other) const { return is_null; }
bool operator== (const NullType) const { return is_null; }
bool operator!= (const Null<T> & other) const
{
return !(*this == other);
}
bool operator!= (const NullType other) const { return !is_null; }
bool operator!= (const NullType) const { return !is_null; }
bool operator!= (const T & other) const
{

View File

@ -10,46 +10,47 @@ static bool startsWith(const std::string & s, const char * prefix)
using namespace mysqlxx;
PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & config,
const std::string & config_name, const unsigned default_connections,
const unsigned max_connections, const size_t max_tries)
: max_tries(max_tries)
PoolWithFailover::PoolWithFailover(const Poco::Util::AbstractConfiguration & config_,
const std::string & config_name_, const unsigned default_connections_,
const unsigned max_connections_, const size_t max_tries_)
: max_tries(max_tries_)
{
shareable = config.getBool(config_name + ".share_connection", false);
if (config.has(config_name + ".replica"))
shareable = config_.getBool(config_name_ + ".share_connection", false);
if (config_.has(config_name_ + ".replica"))
{
Poco::Util::AbstractConfiguration::Keys replica_keys;
config.keys(config_name, replica_keys);
config_.keys(config_name_, replica_keys);
for (const auto & replica_config_key : replica_keys)
{
/// There could be another elements in the same level in configuration file, like "password", "port"...
if (startsWith(replica_config_key, "replica"))
{
std::string replica_name = config_name + "." + replica_config_key;
std::string replica_name = config_name_ + "." + replica_config_key;
int priority = config.getInt(replica_name + ".priority", 0);
int priority = config_.getInt(replica_name + ".priority", 0);
replicas_by_priority[priority].emplace_back(
std::make_shared<Pool>(config, replica_name, default_connections, max_connections, config_name.c_str()));
std::make_shared<Pool>(config_, replica_name, default_connections_, max_connections_, config_name_.c_str()));
}
}
}
else
{
replicas_by_priority[0].emplace_back(
std::make_shared<Pool>(config, config_name, default_connections, max_connections));
std::make_shared<Pool>(config_, config_name_, default_connections_, max_connections_));
}
}
PoolWithFailover::PoolWithFailover(const std::string & config_name, const unsigned default_connections,
const unsigned max_connections, const size_t max_tries)
PoolWithFailover::PoolWithFailover(const std::string & config_name_, const unsigned default_connections_,
const unsigned max_connections_, const size_t max_tries_)
: PoolWithFailover{
Poco::Util::Application::instance().config(), config_name,
default_connections, max_connections, max_tries}
{}
Poco::Util::Application::instance().config(), config_name_,
default_connections_, max_connections_, max_tries_}
{
}
PoolWithFailover::PoolWithFailover(const PoolWithFailover & other)
: max_tries{other.max_tries}, config_name{other.config_name}, shareable{other.shareable}
: max_tries{other.max_tries}, shareable{other.shareable}
{
if (shareable)
{

View File

@ -77,7 +77,6 @@ namespace mysqlxx
size_t max_tries;
/// Mutex for set of replicas.
std::mutex mutex;
std::string config_name;
/// Can the Pool be shared
bool shareable;
@ -91,16 +90,16 @@ namespace mysqlxx
* max_connections Maximum number of connections in pool to each replica.
* max_tries_ Max number of connection tries.
*/
PoolWithFailover(const std::string & config_name,
unsigned default_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
size_t max_tries = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES);
PoolWithFailover(const std::string & config_name_,
unsigned default_connections_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
size_t max_tries_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES);
PoolWithFailover(const Poco::Util::AbstractConfiguration & config,
const std::string & config_name,
unsigned default_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
size_t max_tries = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES);
PoolWithFailover(const Poco::Util::AbstractConfiguration & config_,
const std::string & config_name_,
unsigned default_connections_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_START_CONNECTIONS,
unsigned max_connections_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_CONNECTIONS,
size_t max_tries_ = MYSQLXX_POOL_WITH_FAILOVER_DEFAULT_MAX_TRIES);
PoolWithFailover(const PoolWithFailover & other);

View File

@ -11,29 +11,23 @@
namespace mysqlxx
{
Query::Query(Connection * conn_, const std::string & query_string) : std::ostream(nullptr), conn(conn_)
Query::Query(Connection * conn_, const std::string & query_string) : conn(conn_)
{
/// Важно в случае, если Query используется не из того же потока, что Connection.
mysql_thread_init();
init(&query_buf);
if (!query_string.empty())
{
query_buf.str(query_string);
seekp(0, std::ios::end);
}
query_buf << query_string;
imbue(std::locale::classic());
query_buf.imbue(std::locale::classic());
}
Query::Query(const Query & other) : std::ostream(nullptr), conn(other.conn)
Query::Query(const Query & other) : conn(other.conn)
{
/// Важно в случае, если Query используется не из того же потока, что Connection.
mysql_thread_init();
init(&query_buf);
imbue(std::locale::classic());
query_buf.imbue(std::locale::classic());
*this << other.str();
}
@ -45,9 +39,7 @@ Query & Query::operator= (const Query & other)
conn = other.conn;
seekp(0);
clear();
*this << other.str();
query_buf.str(other.str());
return *this;
}
@ -59,9 +51,7 @@ Query::~Query()
void Query::reset()
{
seekp(0);
clear();
query_buf.str("");
query_buf.str({});
}
void Query::executeImpl()

View File

@ -1,7 +1,6 @@
#pragma once
#include <sstream>
#include <ostream>
#include <mysqlxx/UseQueryResult.h>
#include <mysqlxx/StoreQueryResult.h>
@ -28,7 +27,7 @@ namespace mysqlxx
*
* Внимание! Один объект запроса можно использовать только из одного потока.
*/
class Query : public std::ostream
class Query
{
public:
Query(Connection * conn_, const std::string & query_string = "");
@ -64,9 +63,21 @@ public:
return query_buf.str();
}
auto rdbuf() const
{
return query_buf.rdbuf();
}
template <typename T>
inline Query & operator<< (T && x)
{
query_buf << std::forward<T>(x);
return *this;
}
private:
Connection * conn;
std::stringbuf query_buf;
std::ostringstream query_buf;
void executeImpl();
};

View File

@ -22,11 +22,11 @@ class ResultBase
public:
ResultBase(MYSQL_RES * res_, Connection * conn_, const Query * query_);
Connection * getConnection() { return conn; }
MYSQL_FIELDS getFields() { return fields; }
unsigned getNumFields() { return num_fields; }
MYSQL_RES * getRes() { return res; }
const Query * getQuery() const { return query; }
Connection * getConnection() { return conn; }
MYSQL_FIELDS getFields() { return fields; }
unsigned getNumFields() { return num_fields; }
MYSQL_RES * getRes() { return res; }
const Query * getQuery() const { return query; }
virtual ~ResultBase();

View File

@ -14,16 +14,15 @@ namespace mysqlxx
StoreQueryResult::StoreQueryResult(MYSQL_RES * res_, Connection * conn_, const Query * query_) : ResultBase(res_, conn_, query_)
{
UInt64 rows = mysql_num_rows(res);
UInt32 fields = getNumFields();
reserve(rows);
lengths.resize(rows * fields);
lengths.resize(rows * num_fields);
for (UInt64 i = 0; MYSQL_ROW row = mysql_fetch_row(res); ++i)
{
MYSQL_LENGTHS lengths_for_row = mysql_fetch_lengths(res);
memcpy(&lengths[i * fields], lengths_for_row, sizeof(lengths[0]) * fields);
memcpy(&lengths[i * num_fields], lengths_for_row, sizeof(lengths[0]) * num_fields);
push_back(Row(row, this, &lengths[i * fields]));
push_back(Row(row, this, &lengths[i * num_fields]));
}
checkError(conn->getDriver());
}

View File

@ -68,10 +68,10 @@ int main(int, char **)
Queries queries;
queries.push_back(query);
for (auto & query : queries)
for (auto & q : queries)
{
std::cerr << query.str() << std::endl;
std::cerr << query.store().at(0) << std::endl;
std::cerr << q.str() << std::endl;
std::cerr << q.store().at(0) << std::endl;
}
}

165
cmake/warnings.cmake Normal file
View File

@ -0,0 +1,165 @@
# Our principle is to enable as many warnings as possible and always do it with "warnings as errors" flag.
#
# But it comes with some cost:
# - we have to disable some warnings in 3rd party libraries (they are located in "contrib" directory)
# - we have to include headers of these libraries as -isystem to avoid warnings from headers
# (this is the same behaviour as if these libraries were located in /usr/include)
# - sometimes warnings from 3rd party libraries may come from macro substitutions in our code
# and we have to wrap them with #pragma GCC/clang diagnostic ignored
if (NOT MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif ()
if (USE_DEBUG_HELPERS)
set (INCLUDE_DEBUG_HELPERS "-I${ClickHouse_SOURCE_DIR}/base -include ${ClickHouse_SOURCE_DIR}/src/Core/iostream_debug_helpers.h")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${INCLUDE_DEBUG_HELPERS}")
endif ()
# Add some warnings that are not available even with -Wall -Wextra -Wpedantic.
option (WEVERYTHING "Enables -Weverything option with some exceptions. This is intended for exploration of new compiler warnings that may be found to be useful. Only makes sense for clang." ON)
if (COMPILER_CLANG)
add_warning(pedantic)
no_warning(vla-extension)
no_warning(zero-length-array)
add_warning(comma)
add_warning(conditional-uninitialized)
add_warning(covered-switch-default)
add_warning(deprecated)
add_warning(embedded-directive)
add_warning(empty-init-stmt) # linux-only
add_warning(extra-semi-stmt) # linux-only
add_warning(extra-semi)
add_warning(gnu-case-range)
add_warning(inconsistent-missing-destructor-override)
add_warning(newline-eof)
add_warning(old-style-cast)
add_warning(range-loop-analysis)
add_warning(redundant-parens)
add_warning(reserved-id-macro)
add_warning(shadow-field) # clang 8+
add_warning(shadow-uncaptured-local)
add_warning(shadow)
add_warning(string-plus-int) # clang 8+
add_warning(undef)
add_warning(unreachable-code-return)
add_warning(unreachable-code)
add_warning(unused-exception-parameter)
add_warning(unused-macros)
add_warning(unused-member-function)
add_warning(zero-as-null-pointer-constant)
if (WEVERYTHING)
add_warning(everything)
no_warning(c++98-compat-pedantic)
no_warning(c++98-compat)
no_warning(c99-extensions)
no_warning(conversion)
no_warning(ctad-maybe-unsupported) # clang 9+, linux-only
no_warning(deprecated-dynamic-exception-spec)
no_warning(disabled-macro-expansion)
no_warning(documentation-unknown-command)
no_warning(double-promotion)
no_warning(exit-time-destructors)
no_warning(float-equal)
no_warning(global-constructors)
no_warning(missing-prototypes)
no_warning(missing-variable-declarations)
no_warning(nested-anon-types)
no_warning(packed)
no_warning(padded)
no_warning(return-std-move-in-c++11) # clang 7+
no_warning(shift-sign-overflow)
no_warning(sign-conversion)
no_warning(switch-enum)
no_warning(undefined-func-template)
no_warning(unused-template)
no_warning(vla)
no_warning(weak-template-vtables)
no_warning(weak-vtables)
# TODO Enable conversion, sign-conversion, double-promotion warnings.
endif ()
elseif (COMPILER_GCC)
# Add compiler options only to c++ compiler
function(add_cxx_compile_options option)
add_compile_options("$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${option}>")
endfunction()
# Warn about boolean expression compared with an integer value different from true/false
add_cxx_compile_options(-Wbool-compare)
# Warn whenever a pointer is cast such that the required alignment of the target is increased.
add_cxx_compile_options(-Wcast-align)
# Warn whenever a pointer is cast so as to remove a type qualifier from the target type.
add_cxx_compile_options(-Wcast-qual)
# Warn when deleting a pointer to incomplete type, which may cause undefined behavior at runtime
add_cxx_compile_options(-Wdelete-incomplete)
# Warn if a requested optimization pass is disabled. Code is too big or too complex
add_cxx_compile_options(-Wdisabled-optimization)
# Warn about duplicated conditions in an if-else-if chain
add_cxx_compile_options(-Wduplicated-cond)
# Warn about a comparison between values of different enumerated types
add_cxx_compile_options(-Wenum-compare)
# Warn about uninitialized variables that are initialized with themselves
add_cxx_compile_options(-Winit-self)
# Warn about logical not used on the left hand side operand of a comparison
add_cxx_compile_options(-Wlogical-not-parentheses)
# Warn about suspicious uses of logical operators in expressions
add_cxx_compile_options(-Wlogical-op)
# Warn if there exists a path from the function entry to a use of the variable that is uninitialized.
add_cxx_compile_options(-Wmaybe-uninitialized)
# Warn when the indentation of the code does not reflect the block structure
add_cxx_compile_options(-Wmisleading-indentation)
# Warn if a global function is defined without a previous declaration - disabled because of build times
# add_cxx_compile_options(-Wmissing-declarations)
# Warn if a user-supplied include directory does not exist
add_cxx_compile_options(-Wmissing-include-dirs)
# Obvious
add_cxx_compile_options(-Wnon-virtual-dtor)
# Obvious
add_cxx_compile_options(-Wno-return-local-addr)
# This warning is disabled due to false positives if compiled with libc++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90037
#add_cxx_compile_options(-Wnull-dereference)
# Obvious
add_cxx_compile_options(-Wodr)
# Obvious
add_cxx_compile_options(-Wold-style-cast)
# Warn when a function declaration hides virtual functions from a base class
# add_cxx_compile_options(-Woverloaded-virtual)
# Warn about placement new expressions with undefined behavior
add_cxx_compile_options(-Wplacement-new=2)
# Warn about anything that depends on the size of a function type or of void
add_cxx_compile_options(-Wpointer-arith)
# Warn if anything is declared more than once in the same scope
add_cxx_compile_options(-Wredundant-decls)
# Member initialization reordering
add_cxx_compile_options(-Wreorder)
# Obvious
add_cxx_compile_options(-Wshadow)
# Warn if left shifting a negative value
add_cxx_compile_options(-Wshift-negative-value)
# Warn about a definition of an unsized deallocation function
add_cxx_compile_options(-Wsized-deallocation)
# Warn when the sizeof operator is applied to a parameter that is declared as an array in a function definition
add_cxx_compile_options(-Wsizeof-array-argument)
# Warn for suspicious length parameters to certain string and memory built-in functions if the argument uses sizeof
add_cxx_compile_options(-Wsizeof-pointer-memaccess)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
# Warn about overriding virtual functions that are not marked with the override keyword
add_cxx_compile_options(-Wsuggest-override)
endif ()
# Warn whenever a switch statement has an index of boolean type and the case values are outside the range of a boolean type
add_cxx_compile_options(-Wswitch-bool)
# Warn if a self-comparison always evaluates to true or false
add_cxx_compile_options(-Wtautological-compare)
# Warn about trampolines generated for pointers to nested functions
add_cxx_compile_options(-Wtrampolines)
# Obvious
add_cxx_compile_options(-Wunused)
# Warn if vector operation is not implemented via SIMD capabilities of the architecture
add_cxx_compile_options(-Wvector-operation-performance)
endif ()

View File

@ -20,14 +20,14 @@ if (ENABLE_REPLXX)
)
add_library (replxx ${SRCS})
target_include_directories(replxx PUBLIC ${LIBRARY_DIR}/include)
target_include_directories(replxx SYSTEM PUBLIC ${LIBRARY_DIR}/include)
else ()
find_library(LIBRARY_REPLXX NAMES replxx replxx-static)
find_path(INCLUDE_REPLXX replxx.hxx)
add_library(replxx UNKNOWN IMPORTED)
set_property(TARGET replxx PROPERTY IMPORTED_LOCATION ${LIBRARY_REPLXX})
target_include_directories(replxx PUBLIC ${INCLUDE_REPLXX})
target_include_directories(replxx SYSTEM PUBLIC ${INCLUDE_REPLXX})
set(CMAKE_REQUIRED_LIBRARIES replxx)
check_cxx_source_compiles(

View File

@ -1837,6 +1837,8 @@ UInt64 ClusterCopier::executeQueryOnCluster(
ClusterExecutionMode execution_mode,
UInt64 max_successful_executions_per_shard) const
{
Settings current_settings = settings ? *settings : task_cluster->settings_common;
auto num_shards = cluster->getShardsInfo().size();
std::vector<UInt64> per_shard_num_successful_replicas(num_shards, 0);
@ -1844,8 +1846,7 @@ UInt64 ClusterCopier::executeQueryOnCluster(
if (query_ast_ == nullptr)
{
ParserQuery p_query(query.data() + query.size());
const auto & settings = context.getSettingsRef();
query_ast = parseQuery(p_query, query, settings.max_query_size, settings.max_parser_depth);
query_ast = parseQuery(p_query, query, current_settings.max_query_size, current_settings.max_parser_depth);
}
else
query_ast = query_ast_;
@ -1888,7 +1889,6 @@ UInt64 ClusterCopier::executeQueryOnCluster(
/// Will try to make as many as possible queries
if (shard.hasRemoteConnections())
{
Settings current_settings = settings ? *settings : task_cluster->settings_common;
current_settings.max_parallel_replicas = num_remote_replicas ? num_remote_replicas : 1;
auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover(current_settings).getSaturated(current_settings.max_execution_time);

View File

@ -767,9 +767,9 @@ std::string DynamicQueryHandler::getQuery(Poco::Net::HTTPServerRequest & request
}
PredefinedQueryHandler::PredefinedQueryHandler(
IServer & server, const NameSet & receive_params_, const std::string & predefined_query_
IServer & server_, const NameSet & receive_params_, const std::string & predefined_query_
, const CompiledRegexPtr & url_regex_, const std::unordered_map<String, CompiledRegexPtr> & header_name_with_regex_)
: HTTPHandler(server, "PredefinedQueryHandler"), receive_params(receive_params_), predefined_query(predefined_query_)
: HTTPHandler(server_, "PredefinedQueryHandler"), receive_params(receive_params_), predefined_query(predefined_query_)
, url_regex(url_regex_), header_name_with_capture_regex(header_name_with_regex_)
{
}

View File

@ -106,8 +106,8 @@ private:
CompiledRegexPtr url_regex;
std::unordered_map<String, CompiledRegexPtr> header_name_with_capture_regex;
public:
explicit PredefinedQueryHandler(
IServer & server, const NameSet & receive_params_, const std::string & predefined_query_
PredefinedQueryHandler(
IServer & server_, const NameSet & receive_params_, const std::string & predefined_query_
, const CompiledRegexPtr & url_regex_, const std::unordered_map<String, CompiledRegexPtr> & header_name_with_regex_);
virtual void customizeContext(Poco::Net::HTTPServerRequest & request, Context & context) override;

View File

@ -24,7 +24,7 @@ private:
std::vector<Poco::Net::HTTPRequestHandlerFactory *> child_factories;
public:
~HTTPRequestHandlerFactoryMain();
~HTTPRequestHandlerFactoryMain() override;
HTTPRequestHandlerFactoryMain(const std::string & name_);

View File

@ -34,4 +34,4 @@ void NotFoundHandler::handleRequest(
}
}
}
}

View File

@ -15,4 +15,4 @@ public:
Poco::Net::HTTPServerResponse & response) override;
};
}
}

View File

@ -38,7 +38,7 @@ public:
LOG_TRACE(log, "TCP Request. Address: " << socket.peerAddress().toString());
return new TCPHandler(server, socket);
}
catch (const Poco::Net::NetException & e)
catch (const Poco::Net::NetException &)
{
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
return new DummyTCPHandler(socket);

View File

@ -11,10 +11,8 @@
// garbage that breaks the build (e.g. it changes _POSIX_C_SOURCE).
// TODO: find out what it is. On github, they have proper inteface headers like
// this one: https://github.com/RoaringBitmap/CRoaring/blob/master/include/roaring/roaring.h
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wold-style-cast"
#include <roaring/roaring.h>
#pragma GCC diagnostic pop
namespace DB
{

View File

@ -27,168 +27,6 @@ configure_file (Common/config.h.in ${CONFIG_COMMON})
configure_file (Common/config_version.h.in ${CONFIG_VERSION})
configure_file (Core/config_core.h.in ${CMAKE_CURRENT_BINARY_DIR}/Core/include/config_core.h)
if (NOT MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif ()
if (USE_DEBUG_HELPERS)
set (INCLUDE_DEBUG_HELPERS "-I${ClickHouse_SOURCE_DIR}/base -include ${ClickHouse_SOURCE_DIR}/src/Core/iostream_debug_helpers.h")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${INCLUDE_DEBUG_HELPERS}")
endif ()
# Add some warnings that are not available even with -Wall -Wextra -Wpedantic.
option (WEVERYTHING "Enables -Weverything option with some exceptions. This is intended for exploration of new compiler warnings that may be found to be useful. Only makes sense for clang." ON)
if (COMPILER_CLANG)
add_warning(pedantic)
no_warning(gnu-anonymous-struct)
no_warning(nested-anon-types)
no_warning(vla-extension)
no_warning(zero-length-array)
add_warning(comma)
add_warning(conditional-uninitialized)
add_warning(covered-switch-default)
add_warning(deprecated)
add_warning(embedded-directive)
add_warning(empty-init-stmt) # linux-only
add_warning(extra-semi-stmt) # linux-only
add_warning(extra-semi)
add_warning(gnu-case-range)
add_warning(inconsistent-missing-destructor-override)
add_warning(newline-eof)
add_warning(old-style-cast)
add_warning(range-loop-analysis)
add_warning(redundant-parens)
add_warning(reserved-id-macro)
add_warning(shadow-field) # clang 8+
add_warning(shadow-uncaptured-local)
add_warning(shadow)
add_warning(string-plus-int) # clang 8+
add_warning(undef)
add_warning(unreachable-code-return)
add_warning(unreachable-code)
add_warning(unused-exception-parameter)
add_warning(unused-macros)
add_warning(unused-member-function)
add_warning(zero-as-null-pointer-constant)
if (WEVERYTHING)
add_warning(everything)
no_warning(c++98-compat-pedantic)
no_warning(c++98-compat)
no_warning(c99-extensions)
no_warning(conversion)
no_warning(ctad-maybe-unsupported) # clang 9+, linux-only
no_warning(deprecated-dynamic-exception-spec)
no_warning(disabled-macro-expansion)
no_warning(documentation-unknown-command)
no_warning(double-promotion)
no_warning(exit-time-destructors)
no_warning(float-equal)
no_warning(global-constructors)
no_warning(gnu-anonymous-struct)
no_warning(missing-prototypes)
no_warning(missing-variable-declarations)
no_warning(nested-anon-types)
no_warning(packed)
no_warning(padded)
no_warning(return-std-move-in-c++11) # clang 7+
no_warning(shift-sign-overflow)
no_warning(sign-conversion)
no_warning(switch-enum)
no_warning(undefined-func-template)
no_warning(unused-template)
no_warning(vla-extension)
no_warning(vla)
no_warning(weak-template-vtables)
no_warning(weak-vtables)
no_warning(zero-length-array)
# TODO Enable conversion, sign-conversion, double-promotion warnings.
endif ()
elseif (COMPILER_GCC)
# Add compiler options only to c++ compiler
function(add_cxx_compile_options option)
add_compile_options("$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${option}>")
endfunction()
# Warn about boolean expression compared with an integer value different from true/false
add_cxx_compile_options(-Wbool-compare)
# Warn whenever a pointer is cast such that the required alignment of the target is increased.
add_cxx_compile_options(-Wcast-align)
# Warn whenever a pointer is cast so as to remove a type qualifier from the target type.
add_cxx_compile_options(-Wcast-qual)
# Warn when deleting a pointer to incomplete type, which may cause undefined behavior at runtime
add_cxx_compile_options(-Wdelete-incomplete)
# Warn if a requested optimization pass is disabled. Code is too big or too complex
add_cxx_compile_options(-Wdisabled-optimization)
# Warn about duplicated conditions in an if-else-if chain
add_cxx_compile_options(-Wduplicated-cond)
# Warn about a comparison between values of different enumerated types
add_cxx_compile_options(-Wenum-compare)
# Warn about uninitialized variables that are initialized with themselves
add_cxx_compile_options(-Winit-self)
# Warn about logical not used on the left hand side operand of a comparison
add_cxx_compile_options(-Wlogical-not-parentheses)
# Warn about suspicious uses of logical operators in expressions
add_cxx_compile_options(-Wlogical-op)
# Warn if there exists a path from the function entry to a use of the variable that is uninitialized.
add_cxx_compile_options(-Wmaybe-uninitialized)
# Warn when the indentation of the code does not reflect the block structure
add_cxx_compile_options(-Wmisleading-indentation)
# Warn if a global function is defined without a previous declaration - disabled because of build times
# add_cxx_compile_options(-Wmissing-declarations)
# Warn if a user-supplied include directory does not exist
add_cxx_compile_options(-Wmissing-include-dirs)
# Obvious
add_cxx_compile_options(-Wnon-virtual-dtor)
# Obvious
add_cxx_compile_options(-Wno-return-local-addr)
# This warning is disabled due to false positives if compiled with libc++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90037
#add_cxx_compile_options(-Wnull-dereference)
# Obvious
add_cxx_compile_options(-Wodr)
# Obvious
add_cxx_compile_options(-Wold-style-cast)
# Warn when a function declaration hides virtual functions from a base class
# add_cxx_compile_options(-Woverloaded-virtual)
# Warn about placement new expressions with undefined behavior
add_cxx_compile_options(-Wplacement-new=2)
# Warn about anything that depends on the size of a function type or of void
add_cxx_compile_options(-Wpointer-arith)
# Warn if anything is declared more than once in the same scope
add_cxx_compile_options(-Wredundant-decls)
# Member initialization reordering
add_cxx_compile_options(-Wreorder)
# Obvious
add_cxx_compile_options(-Wshadow)
# Warn if left shifting a negative value
add_cxx_compile_options(-Wshift-negative-value)
# Warn about a definition of an unsized deallocation function
add_cxx_compile_options(-Wsized-deallocation)
# Warn when the sizeof operator is applied to a parameter that is declared as an array in a function definition
add_cxx_compile_options(-Wsizeof-array-argument)
# Warn for suspicious length parameters to certain string and memory built-in functions if the argument uses sizeof
add_cxx_compile_options(-Wsizeof-pointer-memaccess)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
# Warn about overriding virtual functions that are not marked with the override keyword
add_cxx_compile_options(-Wsuggest-override)
endif ()
# Warn whenever a switch statement has an index of boolean type and the case values are outside the range of a boolean type
add_cxx_compile_options(-Wswitch-bool)
# Warn if a self-comparison always evaluates to true or false
add_cxx_compile_options(-Wtautological-compare)
# Warn about trampolines generated for pointers to nested functions
add_cxx_compile_options(-Wtrampolines)
# Obvious
add_cxx_compile_options(-Wunused)
# Warn if vector operation is not implemented via SIMD capabilities of the architecture
add_cxx_compile_options(-Wvector-operation-performance)
endif ()
if (COMPILER_GCC)
# If we leave this optimization enabled, gcc-7 replaces a pair of SSE intrinsics (16 byte load, store) with a call to memcpy.
# It leads to slow code. This is compiler bug. It looks like this:

View File

@ -98,13 +98,13 @@ union CpuInfo
{
UInt32 info[4];
struct
struct Registers
{
UInt32 eax;
UInt32 ebx;
UInt32 ecx;
UInt32 edx;
};
} registers;
inline CpuInfo(UInt32 op) noexcept { cpuid(op, info); }
@ -117,67 +117,67 @@ union CpuInfo
bool haveRDTSCP() noexcept
{
return (CpuInfo(0x80000001).edx >> 27) & 1u;
return (CpuInfo(0x80000001).registers.edx >> 27) & 1u;
}
bool haveSSE() noexcept
{
return (CpuInfo(0x1).edx >> 25) & 1u;
return (CpuInfo(0x1).registers.edx >> 25) & 1u;
}
bool haveSSE2() noexcept
{
return (CpuInfo(0x1).edx >> 26) & 1u;
return (CpuInfo(0x1).registers.edx >> 26) & 1u;
}
bool haveSSE3() noexcept
{
return CpuInfo(0x1).ecx & 1u;
return CpuInfo(0x1).registers.ecx & 1u;
}
bool havePCLMUL() noexcept
{
return (CpuInfo(0x1).ecx >> 1) & 1u;
return (CpuInfo(0x1).registers.ecx >> 1) & 1u;
}
bool haveSSSE3() noexcept
{
return (CpuInfo(0x1).ecx >> 9) & 1u;
return (CpuInfo(0x1).registers.ecx >> 9) & 1u;
}
bool haveSSE41() noexcept
{
return (CpuInfo(0x1).ecx >> 19) & 1u;
return (CpuInfo(0x1).registers.ecx >> 19) & 1u;
}
bool haveSSE42() noexcept
{
return (CpuInfo(0x1).ecx >> 20) & 1u;
return (CpuInfo(0x1).registers.ecx >> 20) & 1u;
}
bool haveF16C() noexcept
{
return (CpuInfo(0x1).ecx >> 29) & 1u;
return (CpuInfo(0x1).registers.ecx >> 29) & 1u;
}
bool havePOPCNT() noexcept
{
return (CpuInfo(0x1).ecx >> 23) & 1u;
return (CpuInfo(0x1).registers.ecx >> 23) & 1u;
}
bool haveAES() noexcept
{
return (CpuInfo(0x1).ecx >> 25) & 1u;
return (CpuInfo(0x1).registers.ecx >> 25) & 1u;
}
bool haveXSAVE() noexcept
{
return (CpuInfo(0x1).ecx >> 26) & 1u;
return (CpuInfo(0x1).registers.ecx >> 26) & 1u;
}
bool haveOSXSAVE() noexcept
{
return (CpuInfo(0x1).ecx >> 27) & 1u;
return (CpuInfo(0x1).registers.ecx >> 27) & 1u;
}
bool haveAVX() noexcept
@ -187,7 +187,7 @@ bool haveAVX() noexcept
// https://bugs.chromium.org/p/chromium/issues/detail?id=375968
return haveOSXSAVE() // implies haveXSAVE()
&& (our_xgetbv(0) & 6u) == 6u // XMM state and YMM state are enabled by OS
&& ((CpuInfo(0x1).ecx >> 28) & 1u); // AVX bit
&& ((CpuInfo(0x1).registers.ecx >> 28) & 1u); // AVX bit
#else
return false;
#endif
@ -195,22 +195,22 @@ bool haveAVX() noexcept
bool haveFMA() noexcept
{
return haveAVX() && ((CpuInfo(0x1).ecx >> 12) & 1u);
return haveAVX() && ((CpuInfo(0x1).registers.ecx >> 12) & 1u);
}
bool haveAVX2() noexcept
{
return haveAVX() && ((CpuInfo(0x7, 0).ebx >> 5) & 1u);
return haveAVX() && ((CpuInfo(0x7, 0).registers.ebx >> 5) & 1u);
}
bool haveBMI1() noexcept
{
return (CpuInfo(0x7, 0).ebx >> 3) & 1u;
return (CpuInfo(0x7, 0).registers.ebx >> 3) & 1u;
}
bool haveBMI2() noexcept
{
return (CpuInfo(0x7, 0).ebx >> 8) & 1u;
return (CpuInfo(0x7, 0).registers.ebx >> 8) & 1u;
}
bool haveAVX512F() noexcept
@ -220,8 +220,8 @@ bool haveAVX512F() noexcept
return haveOSXSAVE() // implies haveXSAVE()
&& (our_xgetbv(0) & 6u) == 6u // XMM state and YMM state are enabled by OS
&& ((our_xgetbv(0) >> 5) & 7u) == 7u // ZMM state is enabled by OS
&& CpuInfo(0x0).eax >= 0x7 // leaf 7 is present
&& ((CpuInfo(0x7).ebx >> 16) & 1u); // AVX512F bit
&& CpuInfo(0x0).registers.eax >= 0x7 // leaf 7 is present
&& ((CpuInfo(0x7).registers.ebx >> 16) & 1u); // AVX512F bit
#else
return false;
#endif
@ -229,82 +229,82 @@ bool haveAVX512F() noexcept
bool haveAVX512DQ() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 17) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 17) & 1u);
}
bool haveRDSEED() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 18) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 18) & 1u);
}
bool haveADX() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 19) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 19) & 1u);
}
bool haveAVX512IFMA() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 21) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 21) & 1u);
}
bool havePCOMMIT() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 22) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 22) & 1u);
}
bool haveCLFLUSHOPT() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 23) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 23) & 1u);
}
bool haveCLWB() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 24) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 24) & 1u);
}
bool haveAVX512PF() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 26) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 26) & 1u);
}
bool haveAVX512ER() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 27) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 27) & 1u);
}
bool haveAVX512CD() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 28) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 28) & 1u);
}
bool haveSHA() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ebx >> 29) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ebx >> 29) & 1u);
}
bool haveAVX512BW() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 30) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 30) & 1u);
}
bool haveAVX512VL() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ebx >> 31) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ebx >> 31) & 1u);
}
bool havePREFETCHWT1() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x7, 0).ecx >> 0) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x7, 0).registers.ecx >> 0) & 1u);
}
bool haveAVX512VBMI() noexcept
{
return haveAVX512F() && ((CpuInfo(0x7, 0).ecx >> 1) & 1u);
return haveAVX512F() && ((CpuInfo(0x7, 0).registers.ecx >> 1) & 1u);
}
bool haveRDRAND() noexcept
{
return CpuInfo(0x0).eax >= 0x7 && ((CpuInfo(0x1).ecx >> 30) & 1u);
return CpuInfo(0x0).registers.eax >= 0x7 && ((CpuInfo(0x1).registers.ecx >> 30) & 1u);
}
struct CpuFlagsCache

View File

@ -19,6 +19,9 @@
#include <linux/taskstats.h>
#include <linux/capability.h>
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
#endif
/// Basic idea is motivated by "iotop" tool.
/// More info: https://www.kernel.org/doc/Documentation/accounting/taskstats.txt

View File

@ -107,20 +107,31 @@ static inline T ALWAYS_INLINE packFixed(
switch (key_sizes[j])
{
case 1:
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<1>() + index, 1);
offset += 1;
{
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<1>() + index, 1);
offset += 1;
}
break;
case 2:
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<2>() + index * 2, 2);
offset += 2;
if constexpr (sizeof(T) >= 2) /// To avoid warning about memcpy exceeding object size.
{
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<2>() + index * 2, 2);
offset += 2;
}
break;
case 4:
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<4>() + index * 4, 4);
offset += 4;
if constexpr (sizeof(T) >= 4)
{
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<4>() + index * 4, 4);
offset += 4;
}
break;
case 8:
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<8>() + index * 8, 8);
offset += 8;
if constexpr (sizeof(T) >= 8)
{
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<8>() + index * 8, 8);
offset += 8;
}
break;
default:
memcpy(bytes + offset, static_cast<const ColumnVectorHelper *>(column)->getRawDataBegin<1>() + index * key_sizes[j], key_sizes[j]);

View File

@ -20,6 +20,10 @@
#include <Common/HashTable/HashMap.h>
#include <Interpreters/AggregationCommon.h>
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
#endif
struct CompactStringRef
{

View File

@ -20,7 +20,6 @@ if (NOT DEFINED ENABLE_UTILS OR ENABLE_UTILS)
add_subdirectory (zookeeper-create-entry-to-download-part)
add_subdirectory (zookeeper-adjust-block-numbers-to-parts)
add_subdirectory (wikistat-loader)
add_subdirectory (fill-factor)
add_subdirectory (check-marks)
add_subdirectory (test-data-generator)
add_subdirectory (convert-month-partitioned-parts)

View File

@ -16,64 +16,7 @@
/** This program checks correctness of .mrk (marks) file for corresponding compressed .bin file.
*/
namespace DB
{
namespace ErrorCodes
{
extern const int TOO_LARGE_SIZE_COMPRESSED;
}
}
/// Read and check header of compressed block. Print size of decompressed and compressed data.
std::pair<UInt32, UInt32> stat(DB::ReadBuffer & in, DB::WriteBuffer & out)
{
if (in.eof())
return {};
in.ignore(16); /// checksum
char header[COMPRESSED_BLOCK_HEADER_SIZE];
in.readStrict(header, COMPRESSED_BLOCK_HEADER_SIZE);
UInt32 size_compressed = unalignedLoad<UInt32>(&header[1]);
if (size_compressed > DBMS_MAX_COMPRESSED_SIZE)
throw DB::Exception("Too large size_compressed. Most likely corrupted data.", DB::ErrorCodes::TOO_LARGE_SIZE_COMPRESSED);
UInt32 size_decompressed = unalignedLoad<UInt32>(&header[5]);
return {size_compressed, size_decompressed};
}
void checkCompressedHeaders(const std::string & mrk_path, const std::string & bin_path)
{
DB::ReadBufferFromFile mrk_in(mrk_path);
DB::ReadBufferFromFile bin_in(bin_path, 4096); /// Small buffer size just to check header of compressed block.
DB::WriteBufferFromFileDescriptor out(STDOUT_FILENO);
for (size_t mark_num = 0; !mrk_in.eof(); ++mark_num)
{
UInt64 offset_in_compressed_file = 0;
UInt64 offset_in_decompressed_block = 0;
DB::readBinary(offset_in_compressed_file, mrk_in);
DB::readBinary(offset_in_decompressed_block, mrk_in);
out << "Mark " << mark_num << ", points to " << offset_in_compressed_file << ", " << offset_in_decompressed_block << ". ";
bin_in.seek(offset_in_compressed_file, SEEK_SET);
auto sizes = stat(bin_in, out);
out << "Block sizes: " << sizes.first << ", " << sizes.second << '\n' << DB::flush;
}
}
void checkByCompressedReadBuffer(const std::string & mrk_path, const std::string & bin_path)
static void checkByCompressedReadBuffer(const std::string & mrk_path, const std::string & bin_path)
{
DB::ReadBufferFromFile mrk_in(mrk_path);
DB::CompressedReadBufferFromFile bin_in(bin_path, 0, 0, 0);
@ -125,7 +68,6 @@ int main(int argc, char ** argv)
try
{
/// checkCompressedHeaders(argv[1], argv[2]);
checkByCompressedReadBuffer(argv[1], argv[2]);
}
catch (const DB::Exception & e)

View File

@ -119,8 +119,8 @@ protected:
public:
/// 'compressed_in' could be initialized lazily, but before first call of 'readCompressedData'.
FasterCompressedReadBufferBase(ReadBuffer * in, ssize_t variant)
: compressed_in(in), own_compressed_buffer(COMPRESSED_BLOCK_HEADER_SIZE), variant(variant), perf_stat(variant)
FasterCompressedReadBufferBase(ReadBuffer * in, ssize_t variant_)
: compressed_in(in), own_compressed_buffer(COMPRESSED_BLOCK_HEADER_SIZE), variant(variant_), perf_stat(variant)
{
}

View File

@ -5,11 +5,12 @@
#include <IO/WriteBufferValidUTF8.h>
#include <IO/copyData.h>
int main(int argc, char **argv)
int main(int, char **)
{
DB::ReadBufferFromFileDescriptor rb(STDIN_FILENO);
DB::WriteBufferFromFileDescriptor wb(STDOUT_FILENO);
DB::WriteBufferValidUTF8 utf8_b(wb);
DB::copyData(rb, utf8_b);
using namespace DB;
ReadBufferFromFileDescriptor rb(STDIN_FILENO);
WriteBufferFromFileDescriptor wb(STDOUT_FILENO);
WriteBufferValidUTF8 utf8_b(wb);
copyData(rb, utf8_b);
return 0;
}

View File

@ -1,2 +0,0 @@
add_executable (fill-factor main.cpp)
target_link_libraries(fill-factor PRIVATE clickhouse_common_io)

View File

@ -1,65 +0,0 @@
#include <iostream>
#include <iomanip>
#if __SSE2__
#include <emmintrin.h>
#endif
#include <common/types.h>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromFileDescriptor.h>
/** Counts number of 0 in a file.
* Outputs "fullness" of file - ration of non-0 bytes to the expected number of non-0 bytes in file with random bytes.
*/
int main(int argc, char ** argv)
{
#if __SSE2__
try
{
DB::ReadBufferFromFileDescriptor in(STDIN_FILENO);
size_t zeros = 0;
UInt64 limit = 0;
if (argc == 2)
limit = DB::parse<UInt64>(argv[1]);
while (!in.eof())
{
const __m128i zero = {0};
for (; in.position() + 15 < in.buffer().end(); in.position() += 16)
{
__m128i bytes = *reinterpret_cast<const __m128i *>(in.position());
__m128i byte_mask = _mm_cmpeq_epi8(bytes, zero);
UInt16 bit_mask = _mm_movemask_epi8(byte_mask);
zeros += __builtin_popcount(bit_mask);
}
for (; in.position() < in.buffer().end(); ++in.position())
if (*in.position() == 0)
++zeros;
if (limit && in.count() >= limit)
break;
}
std::cout << std::fixed
<< 1 - std::max(0.0, static_cast<double>(zeros) / in.count() - 1.0 / 256)
<< std::endl;
}
catch (const DB::Exception & e)
{
std::cerr << e.what() << ", " << e.message() << std::endl
<< std::endl
<< "Stack trace:" << std::endl
<< e.getStackTraceString()
<< std::endl;
throw;
}
#else
std::cerr << "Only for x86_64 arch " << std::endl;
#endif
return 0;
}

View File

@ -88,7 +88,7 @@ int mainImpl(int argc, char ** argv)
{
using namespace DB;
const char * file_name = 0;
const char * file_name = nullptr;
int mode = MODE_NONE;
UInt64 min_offset = 0;
UInt64 max_offset = 0;

View File

@ -1,4 +1,4 @@
#if __APPLE__ || __FreeBSD__
#if !defined(OS_LINUX)
int main(int, char **) { return 0; }
#else
@ -138,7 +138,7 @@ int mainImpl(int argc, char ** argv)
{
using namespace DB;
const char * file_name = 0;
const char * file_name = nullptr;
int mode = MODE_READ;
UInt64 min_offset = 0;
UInt64 max_offset = 0;

View File

@ -47,7 +47,7 @@ int mainImpl(int argc, char ** argv)
{
using namespace DB;
const char * file_name = 0;
const char * file_name = nullptr;
Mode mode = MODE_READ;
UInt64 min_offset = 0;
UInt64 max_offset = 0;

View File

@ -1,4 +1,6 @@
if(USE_PROTOBUF)
add_compile_options(-Wno-zero-as-null-pointer-constant -Wno-array-bounds) # Protobuf generated files
if (USE_PROTOBUF)
protobuf_generate_cpp(ProtobufDelimitedMessagesSerializer_Srcs ProtobufDelimitedMessagesSerializer_Hdrs ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/queries/0_stateless/00825_protobuf_format.proto)
protobuf_generate_cpp(ProtobufDelimitedMessagesSerializer_Srcs2 ProtobufDelimitedMessagesSerializer_Hdrs2 ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/queries/0_stateless/00825_protobuf_format_syntax2.proto)
add_executable (ProtobufDelimitedMessagesSerializer ProtobufDelimitedMessagesSerializer.cpp ${ProtobufDelimitedMessagesSerializer_Srcs} ${ProtobufDelimitedMessagesSerializer_Hdrs} ${ProtobufDelimitedMessagesSerializer_Srcs2} ${ProtobufDelimitedMessagesSerializer_Hdrs2})
@ -6,4 +8,4 @@ if(USE_PROTOBUF)
target_link_libraries (ProtobufDelimitedMessagesSerializer PRIVATE ${Protobuf_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY})
get_filename_component(ProtobufDelimitedMessagesSerializer_OutputDir "${CMAKE_CURRENT_LIST_DIR}/../../tests/queries/0_stateless" REALPATH)
target_compile_definitions(ProtobufDelimitedMessagesSerializer PRIVATE OUTPUT_DIR="${ProtobufDelimitedMessagesSerializer_OutputDir}")
endif()
endif ()

View File

@ -279,7 +279,7 @@ try
return 0;
}
catch (const Poco::Exception & e)
catch (...)
{
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
throw;

View File

@ -108,13 +108,13 @@ int main(int argc, char ** argv)
{
DB::ReadBufferFromString in(line);
std::string path;
std::string path_ignored;
std::string data;
std::string mode;
DB::assertString("create", in);
DB::skipWhitespaceIfAny(in);
readMaybeQuoted(path, in);
readMaybeQuoted(path_ignored, in);
DB::skipWhitespaceIfAny(in);
readMaybeQuoted(data, in);
DB::skipWhitespaceIfAny(in);

View File

@ -40,7 +40,7 @@ try
zookeeper.create(path + "/queue-", entry.toString(), zkutil::CreateMode::PersistentSequential);
return 0;
}
catch (const Poco::Exception & e)
catch (...)
{
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
throw;

View File

@ -59,7 +59,7 @@ try
return 0;
}
catch (const Poco::Exception & e)
catch (...)
{
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
throw;