From 29475c94c0fafd675aa25be12316769161a361ab Mon Sep 17 00:00:00 2001 From: proller Date: Mon, 16 Jan 2017 22:47:11 +0300 Subject: [PATCH] Reorganize includes, less depends in .h files --- CMakeLists.txt | 29 ++--------- cmake/dbms_include.cmake | 12 +++++ contrib/liblz4/CMakeLists.txt | 2 + contrib/libre2/CMakeLists.txt | 2 + dbms/CMakeLists.txt | 14 ++++- dbms/include/DB/Core/StringRef.h | 16 +++--- dbms/include/DB/IO/HashingReadBuffer.h | 1 - dbms/include/DB/IO/HashingWriteBuffer.h | 41 +-------------- .../DB/Interpreters/AggregationCommon.h | 1 - dbms/src/IO/HashingWriteBuffer.cpp | 52 +++++++++++++++++++ dbms/src/Server/CMakeLists.txt | 18 ++++--- libs/libcommon/CMakeLists.txt | 3 ++ libs/libdaemon/CMakeLists.txt | 3 ++ libs/libmysqlxx/CMakeLists.txt | 7 +++ .../libmysqlxx/cmake}/find_mysqlclient.cmake | 0 libs/libmysqlxx/include/mysqlxx/Types.h | 4 -- libs/libmysqlxx/include/mysqlxx/Value.h | 2 + libs/libpocoext/CMakeLists.txt | 3 ++ libs/libzkutil/CMakeLists.txt | 5 ++ utils/CMakeLists.txt | 2 + utils/compressor/CMakeLists.txt | 3 ++ utils/corrector_utf8/CMakeLists.txt | 2 + utils/iotest/CMakeLists.txt | 3 ++ 23 files changed, 134 insertions(+), 91 deletions(-) create mode 100644 cmake/dbms_include.cmake rename {cmake => libs/libmysqlxx/cmake}/find_mysqlclient.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2716a92725e..8026bf6b67f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,48 +154,25 @@ else () set (CLICKHOUSE_ETC_DIR ${CMAKE_INSTALL_PREFIX}/etc) endif () -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcityhash/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/liblz4/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdivide/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdouble-conversion/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libzstd/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libfarmhash/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libsparsehash/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libre2/) -include_directories (BEFORE ${ClickHouse_BINARY_DIR}/contrib/libre2/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libzookeeper/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libcommon/include/) -include_directories (BEFORE ${ClickHouse_BINARY_DIR}/libs/libcommon/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libpocoext/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libmysqlxx/include/) -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libzkutil/include/) - -include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/dbms/include) - include (cmake/find_openssl.cmake) include (cmake/find_icu4c.cmake) include (cmake/find_boost.cmake) include (cmake/find_poco.cmake) include (cmake/find_libtool.cmake) -include (cmake/find_mysqlclient.cmake) include (cmake/find_rt.cmake) if (ENABLE_LIBTCMALLOC) include (cmake/find_gperftools.cmake) endif () -# Directory for Yandex specific files -set (CLICKHOUSE_PRIVATE_DIR ${ClickHouse_SOURCE_DIR}/private/) - add_subdirectory (contrib) add_subdirectory (libs) add_subdirectory (utils) add_subdirectory (dbms) +# Directory for Yandex specific files +set (CLICKHOUSE_PRIVATE_DIR ${ClickHouse_SOURCE_DIR}/private/) if (EXISTS ${CLICKHOUSE_PRIVATE_DIR}) - add_subdirectory (private) + add_subdirectory (${CLICKHOUSE_PRIVATE_DIR}) endif () message (STATUS "C_FLAGS = ${CMAKE_C_FLAGS}") diff --git a/cmake/dbms_include.cmake b/cmake/dbms_include.cmake new file mode 100644 index 00000000000..44bbf0d164a --- /dev/null +++ b/cmake/dbms_include.cmake @@ -0,0 +1,12 @@ + +include_directories (${CMAKE_SOURCE_DIR}/dbms/include) + +# TODO: +# move code with incldes from .h to .cpp and clean this list: +include_directories (${CMAKE_SOURCE_DIR}/libs/libcommon/include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libpocoext/include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libzkutil/include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libmysqlxx/include) +include_directories (BEFORE ${CMAKE_SOURCE_DIR}/contrib/libzookeeper/include) +include_directories (BEFORE ${CMAKE_SOURCE_DIR}/contrib/libcityhash/include) +include_directories (BEFORE ${CMAKE_SOURCE_DIR}/contrib/libdouble-conversion) diff --git a/contrib/liblz4/CMakeLists.txt b/contrib/liblz4/CMakeLists.txt index 8022e02afde..bce214ca215 100644 --- a/contrib/liblz4/CMakeLists.txt +++ b/contrib/liblz4/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories (BEFORE include) + add_library (lz4 src/lz4.c src/lz4hc.c diff --git a/contrib/libre2/CMakeLists.txt b/contrib/libre2/CMakeLists.txt index a56b8f63f28..89e1890ab6d 100644 --- a/contrib/libre2/CMakeLists.txt +++ b/contrib/libre2/CMakeLists.txt @@ -38,6 +38,8 @@ set (re2_sources # In order to avoid redundant locks in some cases, we use not thread-safe version of the library (re2_st). add_definitions (-DNDEBUG) +include_directories (BEFORE .) + add_library (re2 ${re2_sources}) add_library (re2_st ${re2_sources}) diff --git a/dbms/CMakeLists.txt b/dbms/CMakeLists.txt index 687d1a157a4..906186f8674 100644 --- a/dbms/CMakeLists.txt +++ b/dbms/CMakeLists.txt @@ -1,5 +1,15 @@ -include_directories (BEFORE include) -#include_directories (/usr/include/mysql) +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) + +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/liblz4/include/) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdivide) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libzstd/include/) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libfarmhash) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libsparsehash) +include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libre2/) +include_directories (BEFORE ${ClickHouse_BINARY_DIR}/contrib/libre2/) +include_directories (${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/) add_subdirectory (src) diff --git a/dbms/include/DB/Core/StringRef.h b/dbms/include/DB/Core/StringRef.h index d1b3c5cfecc..6b8e34b2a29 100644 --- a/dbms/include/DB/Core/StringRef.h +++ b/dbms/include/DB/Core/StringRef.h @@ -1,11 +1,7 @@ #pragma once -#include -#include - #include #include - #include #include @@ -13,6 +9,8 @@ #include #endif +#include + #include #include @@ -215,11 +213,11 @@ inline size_t hashLessThan8(const char * data, size_t size) if (size > 0) { - uint8 a = data[0]; - uint8 b = data[size >> 1]; - uint8 c = data[size - 1]; - uint32 y = static_cast(a) + (static_cast(b) << 8); - uint32 z = size + (static_cast(c) << 2); + uint8_t a = data[0]; + uint8_t b = data[size >> 1]; + uint8_t c = data[size - 1]; + uint32_t y = static_cast(a) + (static_cast(b) << 8); + uint32_t z = size + (static_cast(c) << 2); return shiftMix(y * k2 ^ z * k3) * k2; } diff --git a/dbms/include/DB/IO/HashingReadBuffer.h b/dbms/include/DB/IO/HashingReadBuffer.h index 1f5aa8b0541..48ad7369885 100644 --- a/dbms/include/DB/IO/HashingReadBuffer.h +++ b/dbms/include/DB/IO/HashingReadBuffer.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/dbms/include/DB/IO/HashingWriteBuffer.h b/dbms/include/DB/IO/HashingWriteBuffer.h index 154debf418a..898ed64b212 100644 --- a/dbms/include/DB/IO/HashingWriteBuffer.h +++ b/dbms/include/DB/IO/HashingWriteBuffer.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -35,45 +34,7 @@ public: /// вычисление хэша зависит от разбиения по блокам /// поэтому нужно вычислить хэш от n полных кусочков и одного неполного - void calculateHash(DB::BufferBase::Position data, size_t len) - { - if (len) - { - /// если данных меньше, чем block_size то сложим их в свой буффер и посчитаем от них hash позже - if (block_pos + len < block_size) - { - memcpy(&BufferWithOwnMemory::memory[block_pos], data, len); - block_pos += len; - } - else - { - /// если в буффер уже что-то записано, то допишем его - if (block_pos) - { - size_t n = block_size - block_pos; - memcpy(&BufferWithOwnMemory::memory[block_pos], data, n); - append(&BufferWithOwnMemory::memory[0]); - len -= n; - data += n; - block_pos = 0; - } - - while (len >= block_size) - { - append(data); - len -= block_size; - data += block_size; - } - - /// запишем остаток в свой буфер - if (len) - { - memcpy(&BufferWithOwnMemory::memory[0], data, len); - block_pos = len; - } - } - } - } + void calculateHash(DB::BufferBase::Position data, size_t len); protected: size_t block_pos; diff --git a/dbms/include/DB/Interpreters/AggregationCommon.h b/dbms/include/DB/Interpreters/AggregationCommon.h index 87bb23fdc04..92f35184cc7 100644 --- a/dbms/include/DB/Interpreters/AggregationCommon.h +++ b/dbms/include/DB/Interpreters/AggregationCommon.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/dbms/src/IO/HashingWriteBuffer.cpp b/dbms/src/IO/HashingWriteBuffer.cpp index eac80a27bc1..0f290ce7ee7 100644 --- a/dbms/src/IO/HashingWriteBuffer.cpp +++ b/dbms/src/IO/HashingWriteBuffer.cpp @@ -1,5 +1,57 @@ #include #include +#include + +namespace DB +{ + +/// вычисление хэша зависит от разбиения по блокам +/// поэтому нужно вычислить хэш от n полных кусочков и одного неполного +template +void IHashingBuffer::calculateHash(DB::BufferBase::Position data, size_t len) +{ + if (len) + { + /// если данных меньше, чем block_size то сложим их в свой буффер и посчитаем от них hash позже + if (block_pos + len < block_size) + { + memcpy(&BufferWithOwnMemory::memory[block_pos], data, len); + block_pos += len; + } + else + { + /// если в буффер уже что-то записано, то допишем его + if (block_pos) + { + size_t n = block_size - block_pos; + memcpy(&BufferWithOwnMemory::memory[block_pos], data, n); + append(&BufferWithOwnMemory::memory[0]); + len -= n; + data += n; + block_pos = 0; + } + + while (len >= block_size) + { + append(data); + len -= block_size; + data += block_size; + } + + /// запишем остаток в свой буфер + if (len) + { + memcpy(&BufferWithOwnMemory::memory[0], data, len); + block_pos = len; + } + } + } +} + +template class IHashingBuffer; +template class IHashingBuffer; + +} /// UInt64 это 39 символов в 10 системе счисления static const size_t UINT64_DECIMAL_SIZE = 39; diff --git a/dbms/src/Server/CMakeLists.txt b/dbms/src/Server/CMakeLists.txt index d2ed386bd75..7d2ff372354 100644 --- a/dbms/src/Server/CMakeLists.txt +++ b/dbms/src/Server/CMakeLists.txt @@ -28,15 +28,17 @@ install_symlink_to_clickhouse(clickhouse-local) install_symlink_to_clickhouse(clickhouse-benchmark) INSTALL( - FILES config.xml users.xml - DESTINATION ${CLICKHOUSE_ETC_DIR}/clickhouse-server - COMPONENT clickhouse) + FILES config.xml users.xml + DESTINATION ${CLICKHOUSE_ETC_DIR}/clickhouse-server + COMPONENT clickhouse) -INSTALL( - FILES ${CLICKHOUSE_PRIVATE_DIR}/Server/metrika/config.xml ${CLICKHOUSE_PRIVATE_DIR}/Server/metrika/users.xml - DESTINATION ${CLICKHOUSE_ETC_DIR}/clickhouse-server/metrika - COMPONENT clickhouse - OPTIONAL) +if (EXISTS ${CLICKHOUSE_PRIVATE_DIR}) + INSTALL( + FILES ${CLICKHOUSE_PRIVATE_DIR}/Server/metrika/config.xml ${CLICKHOUSE_PRIVATE_DIR}/Server/metrika/users.xml + DESTINATION ${CLICKHOUSE_ETC_DIR}/clickhouse-server/metrika + COMPONENT clickhouse + OPTIONAL) +endif () if (NOT CMAKE_SYSTEM MATCHES "FreeBSD") INSTALL( diff --git a/libs/libcommon/CMakeLists.txt b/libs/libcommon/CMakeLists.txt index 3d0121c2856..b8cc9886162 100644 --- a/libs/libcommon/CMakeLists.txt +++ b/libs/libcommon/CMakeLists.txt @@ -9,7 +9,10 @@ set_source_files_properties( src/ClickHouseRevision.cpp PROPERTIES OBJECT_DEPENDS ${REVISIONFILE} ) +include_directories (include) +# for generated revision.h: include_directories (${CMAKE_CURRENT_BINARY_DIR}/src/) +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) if (APPLE) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT "${CMAKE_SYSTEM_VERSION}" VERSION_LESS "16.1.0") diff --git a/libs/libdaemon/CMakeLists.txt b/libs/libdaemon/CMakeLists.txt index 4f6871805d3..2add4e271dd 100644 --- a/libs/libdaemon/CMakeLists.txt +++ b/libs/libdaemon/CMakeLists.txt @@ -1,3 +1,6 @@ +include_directories (include) +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) + add_library (daemon src/BaseDaemon.cpp src/GraphiteWriter.cpp diff --git a/libs/libmysqlxx/CMakeLists.txt b/libs/libmysqlxx/CMakeLists.txt index e0cc3d4c5b2..ea0e6efc67d 100644 --- a/libs/libmysqlxx/CMakeLists.txt +++ b/libs/libmysqlxx/CMakeLists.txt @@ -1,3 +1,10 @@ + +include (cmake/find_mysqlclient.cmake) + +include_directories (include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libcommon/include) +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) + add_library (mysqlxx src/Connection.cpp src/Exception.cpp diff --git a/cmake/find_mysqlclient.cmake b/libs/libmysqlxx/cmake/find_mysqlclient.cmake similarity index 100% rename from cmake/find_mysqlclient.cmake rename to libs/libmysqlxx/cmake/find_mysqlclient.cmake diff --git a/libs/libmysqlxx/include/mysqlxx/Types.h b/libs/libmysqlxx/include/mysqlxx/Types.h index 3f7125b696a..c64487d126d 100644 --- a/libs/libmysqlxx/include/mysqlxx/Types.h +++ b/libs/libmysqlxx/include/mysqlxx/Types.h @@ -3,10 +3,6 @@ #include #include -#include -#include - - struct st_mysql; using MYSQL = st_mysql; diff --git a/libs/libmysqlxx/include/mysqlxx/Value.h b/libs/libmysqlxx/include/mysqlxx/Value.h index dd989c91c8a..4db7fa95ae3 100644 --- a/libs/libmysqlxx/include/mysqlxx/Value.h +++ b/libs/libmysqlxx/include/mysqlxx/Value.h @@ -13,6 +13,8 @@ #include #include +#include + /// Обрезать длинный запрос до указанной длины для текста исключения. #define MYSQLXX_QUERY_PREVIEW_LENGTH 1000 diff --git a/libs/libpocoext/CMakeLists.txt b/libs/libpocoext/CMakeLists.txt index 58926fff67e..25510e7e2c5 100644 --- a/libs/libpocoext/CMakeLists.txt +++ b/libs/libpocoext/CMakeLists.txt @@ -1,3 +1,6 @@ +include_directories (include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libcommon/include) + add_library (pocoext src/LevelFilterChannel.cpp src/ThreadNumber.cpp diff --git a/libs/libzkutil/CMakeLists.txt b/libs/libzkutil/CMakeLists.txt index 82a44067293..1e4a47bbf18 100644 --- a/libs/libzkutil/CMakeLists.txt +++ b/libs/libzkutil/CMakeLists.txt @@ -1,3 +1,8 @@ +include_directories (include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libcommon/include) + +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) + add_library(zkutil src/ZooKeeper.cpp src/Lock.cpp diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index ccffe702b1f..0aeb2228266 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,3 +1,5 @@ +include(${CMAKE_SOURCE_DIR}/cmake/dbms_include.cmake) + add_subdirectory (compressor) add_subdirectory (iotest) add_subdirectory (corrector_utf8) diff --git a/utils/compressor/CMakeLists.txt b/utils/compressor/CMakeLists.txt index 79f64a480e0..abbc3ce366f 100644 --- a/utils/compressor/CMakeLists.txt +++ b/utils/compressor/CMakeLists.txt @@ -1,3 +1,6 @@ + +include_directories (BEFORE ${CMAKE_SOURCE_DIR}/contrib/libzstd/include) + add_executable (compressor main.cpp) target_link_libraries (compressor dbms ${Boost_PROGRAM_OPTIONS_LIBRARY}) diff --git a/utils/corrector_utf8/CMakeLists.txt b/utils/corrector_utf8/CMakeLists.txt index e4dad21b84c..264ce770d6c 100644 --- a/utils/corrector_utf8/CMakeLists.txt +++ b/utils/corrector_utf8/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories (${CMAKE_SOURCE_DIR}/dbms/include) + add_executable(corrector_utf8 corrector_utf8.cpp) # Link the executable to the library. diff --git a/utils/iotest/CMakeLists.txt b/utils/iotest/CMakeLists.txt index 5a575dfbdcd..f1ce743a1bf 100644 --- a/utils/iotest/CMakeLists.txt +++ b/utils/iotest/CMakeLists.txt @@ -1,3 +1,6 @@ +include_directories (${CMAKE_SOURCE_DIR}/dbms/include) +include_directories (${CMAKE_SOURCE_DIR}/libs/libcommon/include) + add_executable (iotest iotest.cpp ${SRCS}) target_link_libraries (iotest dbms)