Merge pull request #18491 from ClickHouse/add_nuraft

Add NuRaft to contrib
This commit is contained in:
alesapin 2020-12-26 16:19:05 +03:00 committed by GitHub
commit e81485653b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 105 additions and 2 deletions

3
.gitmodules vendored
View File

@ -212,3 +212,6 @@
[submodule "contrib/boringssl"]
path = contrib/boringssl
url = https://github.com/ClickHouse-Extras/boringssl.git
[submodule "contrib/NuRaft"]
path = contrib/NuRaft
url = https://github.com/eBay/NuRaft.git

View File

@ -468,6 +468,7 @@ include (cmake/find/rapidjson.cmake)
include (cmake/find/fastops.cmake)
include (cmake/find/odbc.cmake)
include (cmake/find/rocksdb.cmake)
include (cmake/find/nuraft.cmake)
if(NOT USE_INTERNAL_PARQUET_LIBRARY)

24
cmake/find/nuraft.cmake Normal file
View File

@ -0,0 +1,24 @@
option(ENABLE_NURAFT "Enable NuRaft" ${ENABLE_LIBRARIES})
if (NOT ENABLE_NURAFT)
return()
endif()
if (NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/NuRaft/CMakeLists.txt")
message (WARNING "submodule contrib/NuRaft is missing. to fix try run: \n git submodule update --init --recursive")
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find internal NuRaft library")
set (USE_NURAFT 0)
return()
endif ()
if (NOT OS_FREEBSD)
set (USE_NURAFT 1)
set (NURAFT_LIBRARY nuraft)
set (NURAFT_INCLUDE_DIR "${ClickHouse_SOURCE_DIR}/contrib/NuRaft/include")
message (STATUS "Using NuRaft=${USE_NURAFT}: ${NURAFT_INCLUDE_DIR} : ${NURAFT_LIBRARY}")
else()
set (USE_NURAFT 0)
message (STATUS "Using internal NuRaft library on FreeBSD is not supported")
endif()

View File

@ -307,5 +307,9 @@ if (USE_INTERNAL_ROCKSDB_LIBRARY)
add_subdirectory(rocksdb-cmake)
endif()
if (USE_NURAFT)
add_subdirectory(nuraft-cmake)
endif()
add_subdirectory(fast_float)

1
contrib/NuRaft vendored Submodule

@ -0,0 +1 @@
Subproject commit 410bd149da84cdde60b4436b02b738749f4e87e1

2
contrib/boost vendored

@ -1 +1 @@
Subproject commit 0b98b443aa7bb77d65efd7b23b3b8c8a0ab5f1f3
Subproject commit 8e259cd2a6b60d75dd17e73432f11bb7b9351bb1

View File

@ -12,10 +12,12 @@ if (NOT USE_INTERNAL_BOOST_LIBRARY)
program_options
regex
context
coroutine
)
if(Boost_INCLUDE_DIR AND Boost_FILESYSTEM_LIBRARY AND Boost_FILESYSTEM_LIBRARY AND
Boost_PROGRAM_OPTIONS_LIBRARY AND Boost_REGEX_LIBRARY AND Boost_SYSTEM_LIBRARY AND Boost_CONTEXT_LIBRARY)
Boost_PROGRAM_OPTIONS_LIBRARY AND Boost_REGEX_LIBRARY AND Boost_SYSTEM_LIBRARY AND Boost_CONTEXT_LIBRARY AND
Boost_COROUTINE_LIBRARY)
set(EXTERNAL_BOOST_FOUND 1)
@ -29,6 +31,7 @@ if (NOT USE_INTERNAL_BOOST_LIBRARY)
add_library (_boost_regex INTERFACE)
add_library (_boost_system INTERFACE)
add_library (_boost_context INTERFACE)
add_library (_boost_coroutine INTERFACE)
target_link_libraries (_boost_filesystem INTERFACE ${Boost_FILESYSTEM_LIBRARY})
target_link_libraries (_boost_iostreams INTERFACE ${Boost_IOSTREAMS_LIBRARY})
@ -36,6 +39,7 @@ if (NOT USE_INTERNAL_BOOST_LIBRARY)
target_link_libraries (_boost_regex INTERFACE ${Boost_REGEX_LIBRARY})
target_link_libraries (_boost_system INTERFACE ${Boost_SYSTEM_LIBRARY})
target_link_libraries (_boost_context INTERFACE ${Boost_CONTEXT_LIBRARY})
target_link_libraries (_boost_coroutine INTERFACE ${Boost_COROUTINE_LIBRARY})
add_library (boost::filesystem ALIAS _boost_filesystem)
add_library (boost::iostreams ALIAS _boost_iostreams)
@ -43,6 +47,7 @@ if (NOT USE_INTERNAL_BOOST_LIBRARY)
add_library (boost::regex ALIAS _boost_regex)
add_library (boost::system ALIAS _boost_system)
add_library (boost::context ALIAS _boost_context)
add_library (boost::coroutine ALIAS _boost_coroutine)
else()
set(EXTERNAL_BOOST_FOUND 0)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system boost")
@ -76,6 +81,10 @@ if (NOT EXTERNAL_BOOST_FOUND)
add_library (boost::headers_only ALIAS _boost_headers_only)
target_include_directories (_boost_headers_only SYSTEM BEFORE INTERFACE ${LIBRARY_DIR})
# asio
target_compile_definitions (_boost_headers_only INTERFACE BOOST_ASIO_STANDALONE=1)
# iostreams
set (SRCS_IOSTREAMS
@ -199,4 +208,16 @@ if (NOT EXTERNAL_BOOST_FOUND)
add_library (_boost_context ${SRCS_CONTEXT})
add_library (boost::context ALIAS _boost_context)
target_include_directories (_boost_context PRIVATE ${LIBRARY_DIR})
# coroutine
set (SRCS_COROUTINE
${LIBRARY_DIR}/libs/coroutine/detail/coroutine_context.cpp
${LIBRARY_DIR}/libs/coroutine/exceptions.cpp
${LIBRARY_DIR}/libs/coroutine/posix/stack_traits.cpp
)
add_library (_boost_coroutine ${SRCS_COROUTINE})
add_library (boost::coroutine ALIAS _boost_coroutine)
target_include_directories (_boost_coroutine PRIVATE ${LIBRARY_DIR})
target_link_libraries(_boost_coroutine PRIVATE _boost_context)
endif ()

View File

@ -0,0 +1,45 @@
set(LIBRARY_DIR ${ClickHouse_SOURCE_DIR}/contrib/NuRaft)
set(SRCS
${LIBRARY_DIR}/src/handle_priority.cxx
${LIBRARY_DIR}/src/buffer_serializer.cxx
${LIBRARY_DIR}/src/peer.cxx
${LIBRARY_DIR}/src/global_mgr.cxx
${LIBRARY_DIR}/src/buffer.cxx
${LIBRARY_DIR}/src/asio_service.cxx
${LIBRARY_DIR}/src/handle_client_request.cxx
${LIBRARY_DIR}/src/raft_server.cxx
${LIBRARY_DIR}/src/snapshot.cxx
${LIBRARY_DIR}/src/handle_commit.cxx
${LIBRARY_DIR}/src/error_code.cxx
${LIBRARY_DIR}/src/crc32.cxx
${LIBRARY_DIR}/src/handle_snapshot_sync.cxx
${LIBRARY_DIR}/src/stat_mgr.cxx
${LIBRARY_DIR}/src/handle_join_leave.cxx
${LIBRARY_DIR}/src/handle_user_cmd.cxx
${LIBRARY_DIR}/src/handle_custom_notification.cxx
${LIBRARY_DIR}/src/handle_vote.cxx
${LIBRARY_DIR}/src/launcher.cxx
${LIBRARY_DIR}/src/srv_config.cxx
${LIBRARY_DIR}/src/snapshot_sync_req.cxx
${LIBRARY_DIR}/src/handle_timeout.cxx
${LIBRARY_DIR}/src/handle_append_entries.cxx
${LIBRARY_DIR}/src/cluster_config.cxx
)
add_library(nuraft ${SRCS})
target_compile_definitions(nuraft PRIVATE USE_BOOST_ASIO=1 BOOST_ASIO_STANDALONE=1)
target_include_directories (nuraft SYSTEM PRIVATE ${LIBRARY_DIR}/include/libnuraft)
# for some reason include "asio.h" directly without "boost/" prefix.
target_include_directories (nuraft SYSTEM PRIVATE ${ClickHouse_SOURCE_DIR}/contrib/boost/boost)
target_link_libraries (nuraft PRIVATE boost::headers_only boost::coroutine)
if(OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPTO_LIBRARY)
target_link_libraries (nuraft PRIVATE ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
endif()
target_include_directories (nuraft SYSTEM PUBLIC ${LIBRARY_DIR}/include)

View File

@ -22,6 +22,7 @@ RUN apt-get update \
libboost-iostreams-dev \
libboost-regex-dev \
libboost-context-dev \
libboost-coroutine-dev \
zlib1g-dev \
liblz4-dev \
libdouble-conversion-dev \

View File

@ -307,6 +307,9 @@ if (USE_KRB5)
dbms_target_link_libraries(PRIVATE ${KRB5_LIBRARY})
endif()
if (USE_NURAFT)
dbms_target_link_libraries(PRIVATE ${NURAFT_LIBRARY})
endif()
if(RE2_INCLUDE_DIR)
target_include_directories(clickhouse_common_io SYSTEM BEFORE PUBLIC ${RE2_INCLUDE_DIR})