Merge pull request #6602 from amosbird/object-library

Split libdbms.so using object library
This commit is contained in:
alexey-milovidov 2019-09-11 02:00:13 +03:00 committed by GitHub
commit 254102c5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 341 additions and 200 deletions

View File

@ -1,3 +1,6 @@
project(ClickHouse)
cmake_minimum_required(VERSION 3.3)
foreach(policy
CMP0023
CMP0048 # CMake 3.0
@ -10,9 +13,6 @@ foreach(policy
endif()
endforeach()
project(ClickHouse)
cmake_minimum_required(VERSION 3.3)
# Ignore export() since we don't use it,
# but it gets broken with a global targets via link_libraries()
macro (export)
@ -152,6 +152,9 @@ if (LINKER_NAME)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${LINKER_NAME}")
endif ()
# Make sure the final executable has symbols exported
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
cmake_host_system_information(RESULT AVAILABLE_PHYSICAL_MEMORY QUERY AVAILABLE_PHYSICAL_MEMORY) # Not available under freebsd
if(NOT AVAILABLE_PHYSICAL_MEMORY OR AVAILABLE_PHYSICAL_MEMORY GREATER 8000)
option(COMPILER_PIPE "-pipe compiler option [less /tmp usage, more ram usage]" ON)
@ -227,7 +230,6 @@ endif ()
# Make this extra-checks for correct library dependencies.
if (NOT SANITIZE)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif ()
include(cmake/dbms_glob_sources.cmake)
@ -360,6 +362,29 @@ include (libs/libcommon/cmake/find_jemalloc.cmake)
include (libs/libcommon/cmake/find_cctz.cmake)
include (libs/libmysqlxx/cmake/find_mysqlclient.cmake)
# When testing for memory leaks with Valgrind, dont link tcmalloc or jemalloc.
if (USE_JEMALLOC)
message (STATUS "Link jemalloc: ${JEMALLOC_LIBRARIES}")
set (MALLOC_LIBRARIES ${JEMALLOC_LIBRARIES})
elseif (USE_TCMALLOC)
if (DEBUG_TCMALLOC AND NOT GPERFTOOLS_TCMALLOC_MINIMAL_DEBUG)
message (FATAL_ERROR "Requested DEBUG_TCMALLOC but debug library is not found. You should install Google Perftools. Example: sudo apt-get install libgoogle-perftools-dev")
endif ()
if (DEBUG_TCMALLOC AND GPERFTOOLS_TCMALLOC_MINIMAL_DEBUG)
message (STATUS "Link libtcmalloc_minimal_debug for testing: ${GPERFTOOLS_TCMALLOC_MINIMAL_DEBUG}")
set (MALLOC_LIBRARIES ${GPERFTOOLS_TCMALLOC_MINIMAL_DEBUG})
else ()
message (STATUS "Link libtcmalloc_minimal: ${GPERFTOOLS_TCMALLOC_MINIMAL}")
set (MALLOC_LIBRARIES ${GPERFTOOLS_TCMALLOC_MINIMAL})
endif ()
elseif (SANITIZE)
message (STATUS "Will use ${SANITIZE} sanitizer.")
else ()
message (WARNING "Non default allocator is disabled. This is not recommended for production Linux builds.")
endif ()
include (cmake/print_flags.cmake)
install (EXPORT global DESTINATION cmake)

View File

@ -101,28 +101,6 @@ add_headers_and_sources(clickhouse_common_io src/Common)
add_headers_and_sources(clickhouse_common_io src/Common/HashTable)
add_headers_and_sources(clickhouse_common_io src/IO)
add_headers_and_sources(dbms src/Core)
add_headers_and_sources(dbms src/Compression/)
add_headers_and_sources(dbms src/DataStreams)
add_headers_and_sources(dbms src/DataTypes)
add_headers_and_sources(dbms src/Databases)
add_headers_and_sources(dbms src/Interpreters)
add_headers_and_sources(dbms src/Interpreters/ClusterProxy)
add_headers_and_sources(dbms src/Columns)
add_headers_and_sources(dbms src/Storages)
add_headers_and_sources(dbms src/Storages/Distributed)
add_headers_and_sources(dbms src/Storages/MergeTree)
add_headers_and_sources(dbms src/Storages/LiveView)
add_headers_and_sources(dbms src/Client)
add_headers_and_sources(dbms src/Formats)
add_headers_and_sources(dbms src/Processors)
add_headers_and_sources(dbms src/Processors/Executors)
add_headers_and_sources(dbms src/Processors/Formats)
add_headers_and_sources(dbms src/Processors/Formats/Impl)
add_headers_and_sources(dbms src/Processors/Transforms)
add_headers_and_sources(dbms src/Processors/Sources)
add_headers_only(dbms src/Server)
if(USE_RDKAFKA)
add_headers_and_sources(dbms src/Storages/Kafka)
endif()
@ -160,23 +138,71 @@ if (OS_FREEBSD)
target_compile_definitions (clickhouse_common_io PUBLIC CLOCK_MONOTONIC_COARSE=CLOCK_MONOTONIC_FAST)
endif ()
if (USE_UNWIND)
target_link_libraries (clickhouse_common_io PRIVATE ${UNWIND_LIBRARIES})
endif ()
add_subdirectory(src/Common/ZooKeeper)
add_subdirectory(src/Common/Config)
set (all_modules)
macro(add_object_library name common_path)
list (APPEND all_modules ${name})
add_glob(${name}_headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${common_path}/*.h)
add_glob(${name}_sources ${common_path}/*.cpp ${common_path}/*.c ${common_path}/*.h)
if (MAKE_STATIC_LIBRARIES OR NOT SPLIT_SHARED_LIBRARIES)
add_library(${name} OBJECT ${${name}_sources} ${${name}_headers})
else ()
add_library(${name} SHARED ${${name}_sources} ${${name}_headers})
# force all split libs to be linked
target_link_options(${name} PUBLIC "-Wl,--no-as-needed")
endif ()
endmacro()
add_object_library(clickhouse_core src/Core)
add_object_library(clickhouse_compression src/Compression/)
add_object_library(clickhouse_datastreams src/DataStreams)
add_object_library(clickhouse_datatypes src/DataTypes)
add_object_library(clickhouse_databases src/Databases)
add_object_library(clickhouse_interpreters src/Interpreters)
add_object_library(clickhouse_interpreters_clusterproxy src/Interpreters/ClusterProxy)
add_object_library(clickhouse_columns src/Columns)
add_object_library(clickhouse_storages src/Storages)
add_object_library(clickhouse_storages_distributed src/Storages/Distributed)
add_object_library(clickhouse_storages_mergetree src/Storages/MergeTree)
add_object_library(clickhouse_storages_liveview src/Storages/LiveView)
add_object_library(clickhouse_client src/Client)
add_object_library(clickhouse_formats src/Formats)
add_object_library(clickhouse_processors src/Processors)
add_object_library(clickhouse_processors_executors src/Processors/Executors)
add_object_library(clickhouse_processors_formats src/Processors/Formats)
add_object_library(clickhouse_processors_formats_impl src/Processors/Formats/Impl)
add_object_library(clickhouse_processors_transforms src/Processors/Transforms)
add_object_library(clickhouse_processors_sources src/Processors/Sources)
if (MAKE_STATIC_LIBRARIES OR NOT SPLIT_SHARED_LIBRARIES)
add_library(dbms ${dbms_headers} ${dbms_sources})
else ()
foreach (module ${all_modules})
list (APPEND dbms_sources $<TARGET_OBJECTS:${module}>)
endforeach ()
add_library(dbms STATIC ${dbms_headers} ${dbms_sources})
else()
add_library(dbms SHARED ${dbms_headers} ${dbms_sources})
target_link_libraries (dbms PUBLIC ${all_modules})
endif ()
list (APPEND all_modules dbms)
macro (dbms_target_include_directories)
foreach (module ${all_modules})
target_include_directories (${module} ${ARGN})
endforeach ()
endmacro ()
macro (dbms_target_link_libraries)
foreach (module ${all_modules})
target_link_libraries (${module} ${ARGN})
endforeach ()
endmacro ()
if (USE_EMBEDDED_COMPILER)
llvm_libs_all(REQUIRED_LLVM_LIBRARIES)
target_link_libraries (dbms PRIVATE ${REQUIRED_LLVM_LIBRARIES})
target_include_directories (dbms SYSTEM BEFORE PUBLIC ${LLVM_INCLUDE_DIRS})
dbms_target_link_libraries (PRIVATE ${REQUIRED_LLVM_LIBRARIES})
dbms_target_include_directories (SYSTEM BEFORE PUBLIC ${LLVM_INCLUDE_DIRS})
endif ()
if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE_UC STREQUAL "RELWITHDEBINFO" OR CMAKE_BUILD_TYPE_UC STREQUAL "MINSIZEREL")
@ -245,9 +271,9 @@ target_link_libraries(clickhouse_common_io
)
if (USE_RDKAFKA)
target_link_libraries(dbms PRIVATE ${CPPKAFKA_LIBRARY} ${RDKAFKA_LIBRARY})
dbms_target_link_libraries(PRIVATE ${CPPKAFKA_LIBRARY} ${RDKAFKA_LIBRARY})
if(NOT USE_INTERNAL_RDKAFKA_LIBRARY)
target_include_directories(dbms SYSTEM BEFORE PRIVATE ${RDKAFKA_INCLUDE_DIR})
dbms_target_include_directories(SYSTEM BEFORE PRIVATE ${RDKAFKA_INCLUDE_DIR})
endif()
endif()
@ -264,7 +290,7 @@ if(CPUINFO_LIBRARY)
target_link_libraries(clickhouse_common_io PRIVATE ${CPUINFO_LIBRARY})
endif()
target_link_libraries (dbms
dbms_target_link_libraries (
PRIVATE
clickhouse_parsers
clickhouse_common_config
@ -285,21 +311,24 @@ target_link_libraries (dbms
${Boost_SYSTEM_LIBRARY}
)
target_include_directories(dbms PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/src/Core/include)
target_include_directories(clickhouse_common_io PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/src/Core/include) # uses some includes from core
target_include_directories(dbms SYSTEM BEFORE PUBLIC ${PDQSORT_INCLUDE_DIR})
target_include_directories(dbms SYSTEM PUBLIC ${PCG_RANDOM_INCLUDE_DIR})
dbms_target_include_directories(PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/src/Core/include)
target_include_directories(clickhouse_common_io SYSTEM PUBLIC ${PCG_RANDOM_INCLUDE_DIR})
dbms_target_include_directories(SYSTEM PUBLIC ${PCG_RANDOM_INCLUDE_DIR})
dbms_target_include_directories(SYSTEM BEFORE PUBLIC ${PDQSORT_INCLUDE_DIR})
if (NOT USE_INTERNAL_LZ4_LIBRARY)
target_include_directories(dbms SYSTEM BEFORE PRIVATE ${LZ4_INCLUDE_DIR})
dbms_target_include_directories(SYSTEM BEFORE PRIVATE ${LZ4_INCLUDE_DIR})
endif ()
if (ZSTD_LIBRARY)
target_link_libraries(dbms PRIVATE ${ZSTD_LIBRARY})
dbms_target_link_libraries(PRIVATE ${ZSTD_LIBRARY})
if (NOT USE_INTERNAL_ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)
dbms_target_include_directories(SYSTEM BEFORE PRIVATE ${ZSTD_INCLUDE_DIR})
endif ()
endif()
if (NOT USE_INTERNAL_ZSTD_LIBRARY AND ZSTD_INCLUDE_DIR)
target_include_directories(dbms SYSTEM BEFORE PRIVATE ${ZSTD_INCLUDE_DIR})
endif ()
if (NOT USE_INTERNAL_BOOST_LIBRARY)
target_include_directories (clickhouse_common_io SYSTEM BEFORE PUBLIC ${Boost_INCLUDE_DIRS})
@ -307,68 +336,68 @@ endif ()
if (Poco_SQL_FOUND AND NOT USE_INTERNAL_POCO_LIBRARY)
target_include_directories (clickhouse_common_io SYSTEM PRIVATE ${Poco_SQL_INCLUDE_DIR})
target_include_directories (dbms SYSTEM PRIVATE ${Poco_SQL_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM PRIVATE ${Poco_SQL_INCLUDE_DIR})
endif()
if (USE_POCO_SQLODBC)
target_link_libraries (clickhouse_common_io PRIVATE ${Poco_SQL_LIBRARY})
target_link_libraries (dbms PRIVATE ${Poco_SQLODBC_LIBRARY} ${Poco_SQL_LIBRARY})
dbms_target_link_libraries (PRIVATE ${Poco_SQLODBC_LIBRARY} ${Poco_SQL_LIBRARY})
if (NOT USE_INTERNAL_POCO_LIBRARY)
target_include_directories (clickhouse_common_io SYSTEM PRIVATE ${ODBC_INCLUDE_DIRS} ${Poco_SQL_INCLUDE_DIR})
target_include_directories (dbms SYSTEM PRIVATE ${ODBC_INCLUDE_DIRS} ${Poco_SQLODBC_INCLUDE_DIR} SYSTEM PUBLIC ${Poco_SQL_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM PRIVATE ${ODBC_INCLUDE_DIRS} ${Poco_SQLODBC_INCLUDE_DIR} SYSTEM PUBLIC ${Poco_SQL_INCLUDE_DIR})
endif()
endif()
if (Poco_Data_FOUND)
target_include_directories (clickhouse_common_io SYSTEM PRIVATE ${Poco_Data_INCLUDE_DIR})
target_include_directories (dbms SYSTEM PRIVATE ${Poco_Data_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM PRIVATE ${Poco_Data_INCLUDE_DIR})
endif()
if (USE_POCO_DATAODBC)
target_link_libraries (clickhouse_common_io PRIVATE ${Poco_Data_LIBRARY})
target_link_libraries (dbms PRIVATE ${Poco_DataODBC_LIBRARY})
dbms_target_link_libraries (PRIVATE ${Poco_DataODBC_LIBRARY})
if (NOT USE_INTERNAL_POCO_LIBRARY)
target_include_directories (dbms SYSTEM PRIVATE ${ODBC_INCLUDE_DIRS} ${Poco_DataODBC_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM PRIVATE ${ODBC_INCLUDE_DIRS} ${Poco_DataODBC_INCLUDE_DIR})
endif()
endif()
if (USE_POCO_MONGODB)
target_link_libraries (dbms PRIVATE ${Poco_MongoDB_LIBRARY})
dbms_target_link_libraries (PRIVATE ${Poco_MongoDB_LIBRARY})
endif()
if (USE_POCO_NETSSL)
target_link_libraries (clickhouse_common_io PRIVATE ${Poco_NetSSL_LIBRARY} ${Poco_Crypto_LIBRARY})
target_link_libraries (dbms PRIVATE ${Poco_NetSSL_LIBRARY} ${Poco_Crypto_LIBRARY})
dbms_target_link_libraries (PRIVATE ${Poco_NetSSL_LIBRARY} ${Poco_Crypto_LIBRARY})
endif()
target_link_libraries (dbms PRIVATE ${Poco_Foundation_LIBRARY})
dbms_target_link_libraries (PRIVATE ${Poco_Foundation_LIBRARY})
if (USE_ICU)
target_link_libraries (dbms PRIVATE ${ICU_LIBRARIES})
target_include_directories (dbms SYSTEM PRIVATE ${ICU_INCLUDE_DIRS})
dbms_target_link_libraries (PRIVATE ${ICU_LIBRARIES})
dbms_target_include_directories (SYSTEM PRIVATE ${ICU_INCLUDE_DIRS})
endif ()
if (USE_CAPNP)
target_link_libraries (dbms PRIVATE ${CAPNP_LIBRARIES})
dbms_target_link_libraries (PRIVATE ${CAPNP_LIBRARIES})
endif ()
if (USE_PARQUET)
target_link_libraries(dbms PRIVATE ${PARQUET_LIBRARY})
dbms_target_link_libraries(PRIVATE ${PARQUET_LIBRARY})
if (NOT USE_INTERNAL_PARQUET_LIBRARY OR USE_INTERNAL_PARQUET_LIBRARY_NATIVE_CMAKE)
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${PARQUET_INCLUDE_DIR} ${ARROW_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM BEFORE PRIVATE ${PARQUET_INCLUDE_DIR} ${ARROW_INCLUDE_DIR})
endif ()
endif ()
if(OPENSSL_CRYPTO_LIBRARY)
target_link_libraries(dbms PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
if (OPENSSL_CRYPTO_LIBRARY)
dbms_target_link_libraries(PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
endif ()
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${DIVIDE_INCLUDE_DIR})
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM BEFORE PRIVATE ${DIVIDE_INCLUDE_DIR})
dbms_target_include_directories (SYSTEM BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR})
if (USE_PROTOBUF)
target_link_libraries (dbms PRIVATE ${Protobuf_LIBRARY})
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${Protobuf_INCLUDE_DIR})
dbms_target_link_libraries (PRIVATE ${Protobuf_LIBRARY})
dbms_target_include_directories (SYSTEM BEFORE PRIVATE ${Protobuf_INCLUDE_DIR})
endif ()
if (USE_HDFS)
@ -382,13 +411,13 @@ if (USE_BROTLI)
endif()
if (USE_JEMALLOC)
target_include_directories (dbms SYSTEM BEFORE PRIVATE ${JEMALLOC_INCLUDE_DIR}) # used in Interpreters/AsynchronousMetrics.cpp
dbms_target_include_directories (SYSTEM BEFORE PRIVATE ${JEMALLOC_INCLUDE_DIR}) # used in Interpreters/AsynchronousMetrics.cpp
target_include_directories (clickhouse_common_io SYSTEM BEFORE PRIVATE ${JEMALLOC_INCLUDE_DIR}) # new_delete.cpp
endif ()
target_include_directories (dbms PUBLIC ${DBMS_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src/Formats/include)
dbms_target_include_directories (PUBLIC ${DBMS_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src/Formats/include)
target_include_directories (clickhouse_common_io PUBLIC ${DBMS_INCLUDE_DIR})
target_include_directories (clickhouse_common_io SYSTEM PUBLIC ${PCG_RANDOM_INCLUDE_DIR})
target_include_directories (clickhouse_common_io SYSTEM BEFORE PUBLIC ${DOUBLE_CONVERSION_INCLUDE_DIR})
# also for copy_headers.sh:

View File

@ -24,9 +24,9 @@ configure_file (config_tools.h.in ${CMAKE_CURRENT_BINARY_DIR}/config_tools.h)
macro(clickhouse_target_link_split_lib target name)
if(NOT CLICKHOUSE_ONE_SHARED)
target_link_libraries(${target} PRIVATE clickhouse-${name}-lib)
target_link_libraries(${target} PRIVATE clickhouse-${name}-lib ${MALLOC_LIBRARIES})
else()
target_link_libraries(${target} PRIVATE clickhouse-lib)
target_link_libraries(${target} PRIVATE clickhouse-lib ${MALLOC_LIBRARIES})
endif()
endmacro()
@ -111,7 +111,7 @@ if (CLICKHOUSE_SPLIT_BINARY)
install(PROGRAMS clickhouse-split-helper DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME clickhouse COMPONENT clickhouse)
else ()
add_executable (clickhouse main.cpp)
target_link_libraries (clickhouse PRIVATE clickhouse_common_io string_utils)
target_link_libraries (clickhouse PRIVATE clickhouse_common_io string_utils ${MALLOC_LIBRARIES})
target_include_directories (clickhouse BEFORE PRIVATE ${COMMON_INCLUDE_DIR})
target_include_directories (clickhouse PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

View File

@ -8,7 +8,6 @@
#include <vector>
#include <algorithm>
#include <ext/singleton.h>
#include <common/readline_use.h>
#include <Common/typeid_cast.h>
@ -25,7 +24,7 @@ namespace ErrorCodes
extern const int UNKNOWN_PACKET_FROM_SERVER;
}
class Suggest : public ext::singleton<Suggest>
class Suggest : private boost::noncopyable
{
private:
/// The vector will be filled with completion words from the server and sorted.
@ -161,6 +160,12 @@ private:
}
public:
static Suggest & instance()
{
static Suggest instance;
return instance;
}
/// More old server versions cannot execute the query above.
static constexpr int MIN_SERVER_REVISION = 54406;

View File

@ -35,8 +35,7 @@ clickhouse_program_add_library(odbc-bridge)
# clickhouse-odbc-bridge is always a separate binary.
# Reason: it must not export symbols from SSL, mariadb-client, etc. to not break ABI compatibility with ODBC drivers.
# For this reason, we disabling -rdynamic linker flag. But we do it in strange way:
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-export-dynamic")
add_executable(clickhouse-odbc-bridge odbc-bridge.cpp)
set_target_properties(clickhouse-odbc-bridge PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)

View File

@ -26,4 +26,10 @@ AggregateFunctionCombinatorPtr AggregateFunctionCombinatorFactory::tryFindSuffix
return {};
}
AggregateFunctionCombinatorFactory & AggregateFunctionCombinatorFactory::instance()
{
static AggregateFunctionCombinatorFactory ret;
return ret;
}
}

View File

@ -2,7 +2,6 @@
#include <AggregateFunctions/IAggregateFunctionCombinator.h>
#include <ext/singleton.h>
#include <string>
#include <unordered_map>
@ -13,13 +12,16 @@ namespace DB
/** Create aggregate function combinator by matching suffix in aggregate function name.
*/
class AggregateFunctionCombinatorFactory final: public ext::singleton<AggregateFunctionCombinatorFactory>
class AggregateFunctionCombinatorFactory final: private boost::noncopyable
{
private:
using Dict = std::unordered_map<std::string, AggregateFunctionCombinatorPtr>;
Dict dict;
public:
static AggregateFunctionCombinatorFactory & instance();
/// Not thread safe. You must register before using tryGet.
void registerCombinator(const AggregateFunctionCombinatorPtr & value);

View File

@ -160,4 +160,10 @@ bool AggregateFunctionFactory::isAggregateFunctionName(const String & name, int
return false;
}
AggregateFunctionFactory & AggregateFunctionFactory::instance()
{
static AggregateFunctionFactory ret;
return ret;
}
}

View File

@ -3,7 +3,6 @@
#include <AggregateFunctions/IAggregateFunction.h>
#include <Common/IFactoryWithAliases.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
@ -30,9 +29,12 @@ using AggregateFunctionCreator = std::function<AggregateFunctionPtr(const String
/** Creates an aggregate function by name.
*/
class AggregateFunctionFactory final : public ext::singleton<AggregateFunctionFactory>, public IFactoryWithAliases<AggregateFunctionCreator>
class AggregateFunctionFactory final : private boost::noncopyable, public IFactoryWithAliases<AggregateFunctionCreator>
{
public:
static AggregateFunctionFactory & instance();
/// Register a function by its name.
/// No locking, you must register all functions before usage of get.
void registerFunction(

View File

@ -223,5 +223,10 @@ void DNSResolver::addToNewHosts(const String & host)
DNSResolver::~DNSResolver() = default;
DNSResolver & DNSResolver::instance()
{
static DNSResolver ret;
return ret;
}
}

View File

@ -2,20 +2,21 @@
#include <Poco/Net/IPAddress.h>
#include <Poco/Net/SocketAddress.h>
#include <memory>
#include <ext/singleton.h>
#include <Core/Types.h>
#include <Core/Names.h>
#include <boost/noncopyable.hpp>
namespace DB
{
/// A singleton implementing DNS names resolving with optional DNS cache
/// The cache is being updated asynchronous in separate thread (see DNSCacheUpdater)
/// The cache is being updated asynchronous in separate thread (see DNSCacheUpdater)
/// or it could be updated manually via drop() method.
class DNSResolver : public ext::singleton<DNSResolver>
class DNSResolver : private boost::noncopyable
{
public:
static DNSResolver & instance();
DNSResolver(const DNSResolver &) = delete;
@ -46,8 +47,6 @@ private:
DNSResolver();
friend class ext::singleton<DNSResolver>;
struct Impl;
std::unique_ptr<Impl> impl;

View File

@ -361,6 +361,12 @@ const SymbolIndex::Object * SymbolIndex::findObject(const void * address) const
return find(address, data.objects);
}
SymbolIndex & SymbolIndex::instance()
{
static SymbolIndex instance;
return instance;
}
}
#endif

View File

@ -4,8 +4,8 @@
#include <vector>
#include <string>
#include <ext/singleton.h>
#include <Common/Elf.h>
#include <boost/noncopyable.hpp>
namespace DB
@ -15,13 +15,14 @@ namespace DB
* Used as a replacement for "dladdr" function which is extremely slow.
* It works better than "dladdr" because it also allows to search private symbols, that are not participated in shared linking.
*/
class SymbolIndex : public ext::singleton<SymbolIndex>
class SymbolIndex : private boost::noncopyable
{
protected:
friend class ext::singleton<SymbolIndex>;
SymbolIndex() { update(); }
public:
static SymbolIndex & instance();
struct Symbol
{
const void * address_begin;

View File

@ -287,3 +287,8 @@ ThreadPool::Job createExceptionHandledJob(ThreadPool::Job job, ExceptionHandler
};
}
GlobalThreadPool & GlobalThreadPool::instance()
{
static GlobalThreadPool ret;
return ret;
}

View File

@ -8,7 +8,6 @@
#include <queue>
#include <list>
#include <optional>
#include <ext/singleton.h>
#include <Poco/Event.h>
#include <Common/ThreadStatus.h>
@ -121,10 +120,11 @@ using FreeThreadPool = ThreadPoolImpl<std::thread>;
* - address sanitizer and thread sanitizer will not fail due to global limit on number of created threads.
* - program will work faster in gdb;
*/
class GlobalThreadPool : public FreeThreadPool, public ext::singleton<GlobalThreadPool>
class GlobalThreadPool : public FreeThreadPool, private boost::noncopyable
{
public:
GlobalThreadPool() : FreeThreadPool(10000, 1000, 10000) {}
static GlobalThreadPool & instance();
};

View File

@ -155,4 +155,10 @@ CompressionCodecFactory::CompressionCodecFactory()
registerCodecGorilla(*this);
}
CompressionCodecFactory & CompressionCodecFactory::instance()
{
static CompressionCodecFactory ret;
return ret;
}
}

View File

@ -6,8 +6,6 @@
#include <Parsers/IAST_fwd.h>
#include <Common/IFactoryWithAliases.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
#include <optional>
@ -24,7 +22,7 @@ using CodecNameWithLevel = std::pair<String, std::optional<int>>;
/** Creates a codec object by name of compression algorithm family and parameters.
*/
class CompressionCodecFactory final : public ext::singleton<CompressionCodecFactory>
class CompressionCodecFactory final : private boost::noncopyable
{
protected:
using Creator = std::function<CompressionCodecPtr(const ASTPtr & parameters)>;
@ -34,6 +32,8 @@ protected:
using CompressionCodecsCodeDictionary = std::unordered_map<UInt8, CreatorWithType>;
public:
static CompressionCodecFactory & instance();
/// Return default codec (currently LZ4)
CompressionCodecPtr getDefaultCodec() const;
@ -65,8 +65,6 @@ private:
CompressionCodecPtr default_codec;
CompressionCodecFactory();
friend class ext::singleton<CompressionCodecFactory>;
};
}

View File

@ -6,8 +6,8 @@
#include <common/StringRef.h>
#include <Common/SettingsChanges.h>
#include <Core/Types.h>
#include <ext/singleton.h>
#include <unordered_map>
#include <boost/noncopyable.hpp>
namespace DB
@ -329,14 +329,10 @@ private:
bool isChanged(const Derived & collection) const { return is_changed(collection); }
};
class MemberInfos
class MemberInfos : private boost::noncopyable
{
public:
static const MemberInfos & instance()
{
static const MemberInfos single_instance;
return single_instance;
}
static const MemberInfos & instance();
size_t size() const { return infos.size(); }
const MemberInfo & operator[](size_t index) const { return infos[index]; }
@ -630,6 +626,12 @@ public:
LIST_OF_SETTINGS_MACRO(IMPLEMENT_SETTINGS_COLLECTION_DEFINE_FUNCTIONS_HELPER_) \
}; \
LIST_OF_SETTINGS_MACRO(IMPLEMENT_SETTINGS_COLLECTION_ADD_MEMBER_INFO_HELPER_) \
} \
template <> \
const SettingsCollection<DERIVED_CLASS_NAME>::MemberInfos & SettingsCollection<DERIVED_CLASS_NAME>::MemberInfos::instance() \
{ \
static const SettingsCollection<DERIVED_CLASS_NAME>::MemberInfos single_instance; \
return single_instance; \
}

View File

@ -125,5 +125,4 @@ public:
using DataTypeEnum8 = DataTypeEnum<Int8>;
using DataTypeEnum16 = DataTypeEnum<Int16>;
}

View File

@ -202,4 +202,10 @@ DataTypeFactory::DataTypeFactory()
DataTypeFactory::~DataTypeFactory()
{}
DataTypeFactory & DataTypeFactory::instance()
{
static DataTypeFactory ret;
return ret;
}
}

View File

@ -4,7 +4,6 @@
#include <Parsers/IAST_fwd.h>
#include <Common/IFactoryWithAliases.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
@ -20,7 +19,7 @@ using DataTypePtr = std::shared_ptr<const IDataType>;
/** Creates a data type by name of data type family and parameters.
*/
class DataTypeFactory final : public ext::singleton<DataTypeFactory>, public IFactoryWithAliases<std::function<DataTypePtr(const ASTPtr & parameters)>>
class DataTypeFactory final : private boost::noncopyable, public IFactoryWithAliases<std::function<DataTypePtr(const ASTPtr & parameters)>>
{
private:
using SimpleCreator = std::function<DataTypePtr()>;
@ -29,6 +28,8 @@ private:
using SimpleCreatorWithCustom = std::function<std::pair<DataTypePtr,DataTypeCustomDescPtr>()>;
public:
static DataTypeFactory & instance();
DataTypePtr get(const String & full_name) const;
DataTypePtr get(const String & family_name, const ASTPtr & parameters) const;
DataTypePtr get(const ASTPtr & ast) const;
@ -62,8 +63,6 @@ private:
const DataTypesDictionary & getCaseInsensitiveCreatorMap() const override { return case_insensitive_data_types; }
String getFactoryName() const override { return "DataTypeFactory"; }
friend class ext::singleton<DataTypeFactory>;
};
}

View File

@ -47,4 +47,10 @@ DictionaryPtr DictionaryFactory::create(
throw Exception{name + ": unknown dictionary layout type: " + layout_type, ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG};
}
DictionaryFactory & DictionaryFactory::instance()
{
static DictionaryFactory ret;
return ret;
}
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <ext/singleton.h>
#include "IDictionary.h"
@ -22,9 +21,12 @@ namespace DB
class Context;
class DictionaryFactory : public ext::singleton<DictionaryFactory>
class DictionaryFactory : private boost::noncopyable
{
public:
static DictionaryFactory & instance();
DictionaryPtr create(const std::string & name, const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix, Context & context) const;
using Creator = std::function<DictionaryPtr(

View File

@ -101,4 +101,10 @@ DictionarySourcePtr DictionarySourceFactory::create(
throw Exception{name + ": unknown dictionary source type: " + source_type, ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG};
}
DictionarySourceFactory & DictionarySourceFactory::instance()
{
static DictionarySourceFactory instance;
return instance;
}
}

View File

@ -4,7 +4,6 @@
#include <Core/Block.h>
#include <unordered_map>
#include <ext/singleton.h>
namespace Poco
{
@ -22,9 +21,11 @@ class Context;
struct DictionaryStructure;
/// creates IDictionarySource instance from config and DictionaryStructure
class DictionarySourceFactory : public ext::singleton<DictionarySourceFactory>
class DictionarySourceFactory : private boost::noncopyable
{
public:
static DictionarySourceFactory & instance();
using Creator = std::function<DictionarySourcePtr(
const DictionaryStructure & dict_struct,
const Poco::Util::AbstractConfiguration & config,

View File

@ -4,7 +4,6 @@
#include <Poco/Exception.h>
#include <Poco/Util/Application.h>
#include <common/logger_useful.h>
#include <ext/singleton.h>
#include "GeodataProviders/IHierarchiesProvider.h"

View File

@ -315,4 +315,10 @@ FormatFactory::FormatFactory()
registerOutputFormatProcessorMySQLWrite(*this);
}
FormatFactory & FormatFactory::instance()
{
static FormatFactory ret;
return ret;
}
}

View File

@ -2,11 +2,11 @@
#include <Core/Types.h>
#include <DataStreams/IBlockStream_fwd.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
#include <unordered_map>
#include <boost/noncopyable.hpp>
namespace DB
@ -34,7 +34,7 @@ using OutputFormatPtr = std::shared_ptr<IOutputFormat>;
/** Allows to create an IBlockInputStream or IBlockOutputStream by the name of the format.
* Note: format and compression are independent things.
*/
class FormatFactory final : public ext::singleton<FormatFactory>
class FormatFactory final : private boost::noncopyable
{
public:
/// This callback allows to perform some additional actions after reading a single row.
@ -87,6 +87,9 @@ private:
using FormatsDictionary = std::unordered_map<String, Creators>;
public:
static FormatFactory & instance();
BlockInputStreamPtr getInput(
const String & name,
ReadBuffer & buf,
@ -128,7 +131,6 @@ private:
FormatsDictionary dict;
FormatFactory();
friend class ext::singleton<FormatFactory>;
const Creators & getCreators(const String & name) const;
};

View File

@ -15,6 +15,11 @@ namespace ErrorCodes
extern const int CANNOT_PARSE_PROTOBUF_SCHEMA;
}
ProtobufSchemas & ProtobufSchemas::instance()
{
static ProtobufSchemas instance;
return instance;
}
class ProtobufSchemas::ImporterWithSourceTree : public google::protobuf::compiler::MultiFileErrorCollector
{

View File

@ -6,7 +6,7 @@
#include <memory>
#include <unordered_map>
#include <Core/Types.h>
#include <ext/singleton.h>
#include <boost/noncopyable.hpp>
namespace google
@ -24,9 +24,11 @@ class FormatSchemaInfo;
/** Keeps parsed google protobuf schemas parsed from files.
* This class is used to handle the "Protobuf" input/output formats.
*/
class ProtobufSchemas : public ext::singleton<ProtobufSchemas>
class ProtobufSchemas : private boost::noncopyable
{
public:
static ProtobufSchemas & instance();
ProtobufSchemas();
~ProtobufSchemas();

View File

@ -73,4 +73,10 @@ FunctionBuilderPtr FunctionFactory::tryGet(
return {};
}
FunctionFactory & FunctionFactory::instance()
{
static FunctionFactory ret;
return ret;
}
}

View File

@ -3,7 +3,6 @@
#include <Functions/IFunction.h>
#include <Common/IFactoryWithAliases.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
@ -21,10 +20,12 @@ class Context;
* Function could use for initialization (take ownership of shared_ptr, for example)
* some dictionaries from Context.
*/
class FunctionFactory : public ext::singleton<FunctionFactory>, public IFactoryWithAliases<std::function<FunctionBuilderPtr(const Context &)>>
class FunctionFactory : private boost::noncopyable, public IFactoryWithAliases<std::function<FunctionBuilderPtr(const Context &)>>
{
public:
static FunctionFactory & instance();
template <typename Function>
void registerFunction(CaseSensitiveness case_sensitiveness = CaseSensitive)
{

View File

@ -158,6 +158,12 @@ std::future<AIOContextPool::BytesRead> AIOContextPool::post(struct iocb & iocb)
return promises[request_id].get_future();
}
AIOContextPool & AIOContextPool::instance()
{
static AIOContextPool instance;
return instance;
}
}
#endif

View File

@ -2,7 +2,6 @@
#if defined(__linux__) || defined(__FreeBSD__)
#include <ext/singleton.h>
#include <condition_variable>
#include <future>
#include <mutex>
@ -14,10 +13,8 @@
namespace DB
{
class AIOContextPool : public ext::singleton<AIOContextPool>
class AIOContextPool : private boost::noncopyable
{
friend class ext::singleton<AIOContextPool>;
static const auto max_concurrent_events = 128;
static const auto timeout_sec = 1;
@ -45,6 +42,8 @@ class AIOContextPool : public ext::singleton<AIOContextPool>
void reportExceptionToAnyProducer();
public:
static AIOContextPool & instance();
/// Request AIO read operation for iocb, returns a future with number of bytes read
std::future<BytesRead> post(struct iocb & iocb);
};

View File

@ -0,0 +1,16 @@
#include <IO/DoubleConverter.h>
namespace DB
{
template <bool emit_decimal_point>
const double_conversion::DoubleToStringConverter & DoubleConverter<emit_decimal_point>::instance()
{
static const double_conversion::DoubleToStringConverter instance{
DoubleToStringConverterFlags<emit_decimal_point>::flags, "inf", "nan", 'e', -6, 21, 6, 1};
return instance;
}
template class DoubleConverter<true>;
template class DoubleConverter<false>;
}

View File

@ -6,6 +6,7 @@
#endif
#include <double-conversion/double-conversion.h>
#include <boost/noncopyable.hpp>
#ifdef __clang__
#pragma clang diagnostic pop
@ -26,7 +27,7 @@ template <> struct DoubleToStringConverterFlags<true>
};
template <bool emit_decimal_point>
class DoubleConverter
class DoubleConverter : private boost::noncopyable
{
DoubleConverter(const DoubleConverter &) = delete;
DoubleConverter & operator=(const DoubleConverter &) = delete;
@ -41,14 +42,7 @@ public:
1 + double_conversion::DoubleToStringConverter::kMaxFixedDigitsAfterPoint + 1;
using BufferType = char[MAX_REPRESENTATION_LENGTH];
static const auto & instance()
{
static const double_conversion::DoubleToStringConverter instance{
DoubleToStringConverterFlags<emit_decimal_point>::flags, "inf", "nan", 'e', -6, 21, 6, 1
};
return instance;
}
static const double_conversion::DoubleToStringConverter & instance();
};
}

View File

@ -112,15 +112,13 @@ void setTimeouts(Poco::Net::HTTPClientSession & session, const ConnectionTimeout
}
};
class HTTPSessionPool : public ext::singleton<HTTPSessionPool>
class HTTPSessionPool : private boost::noncopyable
{
private:
using Key = std::tuple<std::string, UInt16, bool>;
using PoolPtr = std::shared_ptr<SingleEndpointHTTPSessionPool>;
using Entry = SingleEndpointHTTPSessionPool::Entry;
friend class ext::singleton<HTTPSessionPool>;
struct Hasher
{
size_t operator()(const Key & k) const
@ -140,6 +138,12 @@ void setTimeouts(Poco::Net::HTTPClientSession & session, const ConnectionTimeout
HTTPSessionPool() = default;
public:
static auto & instance()
{
static HTTPSessionPool instance;
return instance;
}
Entry getSession(
const Poco::URI & uri,
const ConnectionTimeouts & timeouts,

View File

@ -83,4 +83,5 @@ public:
return IHashingBuffer<WriteBuffer>::getHash();
}
};
}

View File

@ -86,4 +86,10 @@ MergeTreeIndexFactory::MergeTreeIndexFactory()
registerIndex("bloom_filter", bloomFilterIndexCreatorNew);
}
MergeTreeIndexFactory & MergeTreeIndexFactory::instance()
{
static MergeTreeIndexFactory instance;
return instance;
}
}

View File

@ -5,7 +5,6 @@
#include <vector>
#include <memory>
#include <Core/Block.h>
#include <ext/singleton.h>
#include <Storages/MergeTree/MergeTreeDataPartChecksum.h>
#include <Storages/SelectQueryInfo.h>
#include <Storages/MergeTree/MarkRange.h>
@ -129,11 +128,11 @@ public:
using MergeTreeIndices = std::vector<MutableMergeTreeIndexPtr>;
class MergeTreeIndexFactory : public ext::singleton<MergeTreeIndexFactory>
class MergeTreeIndexFactory : private boost::noncopyable
{
friend class ext::singleton<MergeTreeIndexFactory>;
public:
static MergeTreeIndexFactory & instance();
using Creator = std::function<
std::unique_ptr<IMergeTreeIndex>(
const NamesAndTypesList & columns,

View File

@ -163,4 +163,10 @@ StoragePtr StorageFactory::get(
return it->second(arguments);
}
StorageFactory & StorageFactory::instance()
{
static StorageFactory ret;
return ret;
}
}

View File

@ -5,7 +5,6 @@
#include <Storages/ColumnsDescription.h>
#include <Storages/ConstraintsDescription.h>
#include <Storages/IStorage_fwd.h>
#include <ext/singleton.h>
#include <unordered_map>
@ -21,9 +20,12 @@ class ASTStorage;
* In 'columns' Nested data structures must be flattened.
* You should subsequently call IStorage::startup method to work with table.
*/
class StorageFactory : public ext::singleton<StorageFactory>, public IHints<1, StorageFactory>
class StorageFactory : private boost::noncopyable, public IHints<1, StorageFactory>
{
public:
static StorageFactory & instance();
struct Arguments
{
const String & engine_name;

View File

@ -70,4 +70,10 @@ bool TableFunctionFactory::isTableFunctionName(const std::string & name) const
return table_functions.count(name);
}
TableFunctionFactory & TableFunctionFactory::instance()
{
static TableFunctionFactory ret;
return ret;
}
}

View File

@ -4,12 +4,12 @@
#include <Common/IFactoryWithAliases.h>
#include <Common/NamePrompter.h>
#include <ext/singleton.h>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <boost/noncopyable.hpp>
namespace DB
@ -21,10 +21,12 @@ using TableFunctionCreator = std::function<TableFunctionPtr()>;
/** Lets you get a table function by its name.
*/
class TableFunctionFactory final: public ext::singleton<TableFunctionFactory>, public IFactoryWithAliases<TableFunctionCreator>
class TableFunctionFactory final: private boost::noncopyable, public IFactoryWithAliases<TableFunctionCreator>
{
public:
static TableFunctionFactory & instance();
/// Register a function by its name.
/// No locking, you must register all functions before usage of get.
void registerFunction(const std::string & name, Creator creator, CaseSensitiveness case_sensitiveness = CaseSensitive);

View File

@ -62,7 +62,6 @@ add_library (common
include/ext/scope_guard.h
include/ext/size.h
include/ext/unlock_guard.h
include/ext/singleton.h
${CONFIG_COMMON})

View File

@ -1,11 +1,11 @@
#pragma once
#include "DateLUTImpl.h"
#include <ext/singleton.h>
#include <unordered_map>
#include <atomic>
#include <mutex>
#include <memory>
#include <boost/noncopyable.hpp>
// Also defined in Core/Defines.h
#if !defined(ALWAYS_INLINE)
@ -18,25 +18,20 @@
/// This class provides lazy initialization and lookup of singleton DateLUTImpl objects for a given timezone.
class DateLUT : public ext::singleton<DateLUT>
class DateLUT : private boost::noncopyable
{
friend class ext::singleton<DateLUT>;
public:
DateLUT(const DateLUT &) = delete;
DateLUT & operator=(const DateLUT &) = delete;
/// Return singleton DateLUTImpl instance for the default time zone.
static ALWAYS_INLINE const DateLUTImpl & instance()
{
const auto & date_lut = ext::singleton<DateLUT>::instance();
const auto & date_lut = getInstance();
return *date_lut.default_impl.load(std::memory_order_acquire);
}
/// Return singleton DateLUTImpl instance for a given time zone.
static ALWAYS_INLINE const DateLUTImpl & instance(const std::string & time_zone)
{
const auto & date_lut = ext::singleton<DateLUT>::instance();
const auto & date_lut = getInstance();
if (time_zone.empty())
return *date_lut.default_impl.load(std::memory_order_acquire);
@ -45,7 +40,7 @@ public:
static void setDefaultTimezone(const std::string & time_zone)
{
auto & date_lut = ext::singleton<DateLUT>::instance();
auto & date_lut = getInstance();
const auto & impl = date_lut.getImplementation(time_zone);
date_lut.default_impl.store(&impl, std::memory_order_release);
}
@ -54,6 +49,8 @@ protected:
DateLUT();
private:
static DateLUT & getInstance();
const DateLUTImpl & getImplementation(const std::string & time_zone) const;
using DateLUTImplPtr = std::unique_ptr<DateLUTImpl>;

View File

@ -1,44 +0,0 @@
#pragma once
namespace ext
{
/** Example (1):
*
* class Derived : public ext::singleton<Derived>
* {
* friend class ext::singleton<Derived>;
* ...
* protected:
* Derived() {};
* };
*
* Example (2):
*
* class Some
* {
* ...
* };
*
* class SomeSingleton : public Some, public ext::singleton<SomeSingleton> {}
*/
template <typename T> class singleton
{
public:
static T & instance()
{
/// C++11 has thread safe statics. GCC and Clang have thread safe statics by default even before C++11.
static T instance;
return instance;
}
protected:
singleton() {}
private:
singleton(const singleton &);
singleton & operator=(const singleton &);
};
}

View File

@ -155,3 +155,9 @@ const DateLUTImpl & DateLUT::getImplementation(const std::string & time_zone) co
return *it->second;
}
DateLUT & DateLUT::getInstance()
{
static DateLUT ret;
return ret;
}

View File

@ -5,7 +5,6 @@
#include <Poco/Util/Application.h>
#include <ext/singleton.h>
#include <mysqlxx/Query.h>
#include <mysqlxx/Exception.h>
@ -26,9 +25,11 @@ namespace mysqlxx
* Usage:
* LibrarySingleton::instance();
*/
class LibrarySingleton : public ext::singleton<LibrarySingleton>
class LibrarySingleton : private boost::noncopyable
{
friend class ext::singleton<LibrarySingleton>;
public:
static auto & instance();
private:
LibrarySingleton();
~LibrarySingleton();

View File

@ -26,6 +26,11 @@ LibrarySingleton::~LibrarySingleton()
mysql_library_end();
}
auto & LibrarySingleton::instance()
{
static LibrarySingleton instance;
return instance;
}
Connection::Connection()
: driver(std::make_unique<MYSQL>())