Skip to content

Commit

Permalink
feat: Support to build server binaries separately (#2009)
Browse files Browse the repository at this point in the history
This patch adds a new flag `--separate_servers` to indicate whether to build
`pegasus_collector`,`pegasus_meta_server` and `pegasus_replica_server` binaries
separately, otherwise a combined `pegasus_server` binary will be built. The
corresponding option in CMake is `SEPARATE_SERVERS`.
  • Loading branch information
acelyc111 authored May 22, 2024
1 parent 0ee404e commit d7087b6
Show file tree
Hide file tree
Showing 28 changed files with 595 additions and 189 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ if(USE_JEMALLOC)
set(JEMALLOC_LIB_TYPE "SHARED")
endif()

option(SEPARATE_SERVERS "Whether to build pegasus_collector,pegasus_meta_server and pegasus_replica_server binaries separately, otherwise a combined pegasus_server binary will be built" OFF)
message(STATUS "SEPARATE_SERVERS = ${SEPARATE_SERVERS}")

add_subdirectory(src)
8 changes: 7 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function usage_build()
echo " --disable_gperf build without gperftools, this flag is mainly used"
echo " to enable valgrind memcheck, default no"
echo " --use_jemalloc build with jemalloc"
echo " --separate_servers whether to build pegasus_collector,pegasus_meta_server and pegasus_replica_server binaries separately, otherwise a combined pegasus_server binary will be built"
echo " --sanitizer <type> build with sanitizer to check potential problems,
type: address|leak|thread|undefined"
echo " --skip_thirdparty whether to skip building thirdparties, default no"
Expand Down Expand Up @@ -130,6 +131,7 @@ function run_build()
SANITIZER=""
ROCKSDB_PORTABLE=0
USE_JEMALLOC=OFF
SEPARATE_SERVERS=OFF
BUILD_TEST=OFF
IWYU=""
BUILD_MODULES=""
Expand Down Expand Up @@ -198,6 +200,9 @@ function run_build()
ENABLE_GPERF=OFF
USE_JEMALLOC=ON
;;
--separate_servers)
SEPARATE_SERVERS=ON
;;
--test)
BUILD_TEST=ON
;;
Expand Down Expand Up @@ -230,7 +235,8 @@ function run_build()

CMAKE_OPTIONS="-DCMAKE_C_COMPILER=${C_COMPILER}
-DCMAKE_CXX_COMPILER=${CXX_COMPILER}
-DUSE_JEMALLOC=${USE_JEMALLOC}"
-DUSE_JEMALLOC=${USE_JEMALLOC}
-DSEPARATE_SERVERS=${SEPARATE_SERVERS}"

echo "BUILD_TYPE=$BUILD_TYPE"
if [ "$BUILD_TYPE" == "debug" ]
Expand Down
12 changes: 8 additions & 4 deletions src/base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ set(MY_PROJ_SRC "")
set(MY_SRC_SEARCH_MODE "GLOB")

set(MY_PROJ_LIBS
dsn_runtime
dsn_utils
pegasus_base
gtest)
dsn_runtime
dsn_utils
pegasus_base
rocksdb
lz4
zstd
snappy
gtest)

set(MY_BOOST_LIBS Boost::system Boost::filesystem)

Expand Down
4 changes: 4 additions & 0 deletions src/geo/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ set(MY_PROJ_LIBS
s2
pegasus_client_static
dsn_utils
rocksdb
lz4
zstd
snappy
gtest)

set(MY_BOOST_LIBS Boost::system Boost::filesystem)
Expand Down
20 changes: 12 additions & 8 deletions src/redis_protocol/proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ set(MY_PROJ_SRC "")
# "GLOB" for non-recursive search
set(MY_SRC_SEARCH_MODE "GLOB")

set(MY_PROJ_LIBS pegasus.rproxylib
absl::flat_hash_set
absl::strings
pegasus_geo_lib
event
s2
pegasus_client_static
)
set(MY_PROJ_LIBS
pegasus.rproxylib
absl::flat_hash_set
absl::strings
pegasus_geo_lib
event
s2
pegasus_client_static
rocksdb
lz4
zstd
snappy)

set(MY_BINPLACES "config.ini")

Expand Down
22 changes: 13 additions & 9 deletions src/redis_protocol/proxy_ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ set(MY_SRC_SEARCH_MODE "GLOB")

set(MY_BOOST_LIBS Boost::system Boost::filesystem)

set(MY_PROJ_LIBS pegasus.rproxylib
pegasus_base
absl::flat_hash_set
absl::strings
pegasus_geo_lib
s2
pegasus_client_static
gtest
)
set(MY_PROJ_LIBS
pegasus.rproxylib
pegasus_base
absl::flat_hash_set
absl::strings
pegasus_geo_lib
s2
pegasus_client_static
rocksdb
lz4
zstd
snappy
gtest)

set(MY_BINPLACES "config.ini" "run.sh")

Expand Down
7 changes: 5 additions & 2 deletions src/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ set(MY_PROJ_NAME "sample")
set(MY_SRC_SEARCH_MODE "GLOB")

set(MY_PROJ_LIBS
pegasus_client_static
)
pegasus_client_static
rocksdb
lz4
zstd
snappy)

set(MY_BOOST_LIBS Boost::filesystem Boost::system)

Expand Down
88 changes: 66 additions & 22 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,77 @@
# specific language governing permissions and limitations
# under the License.

set(MY_PROJ_NAME pegasus_server)
set(MY_PROJ_SRC "")
set(MY_SRC_SEARCH_MODE "GLOB")
set(MY_PROJ_LIBS
dsn_replica_server
set(SERVER_COMMON_SRC
${CMAKE_CURRENT_SOURCE_DIR}/server_utils.cpp)
set(COLLECTOR_SRC
${SERVER_COMMON_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/available_detector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/info_collector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/info_collector_app.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hotspot_partition_calculator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/result_writer.cpp)
set(META_SERVER_SRC
${SERVER_COMMON_SRC})
set(REPLICA_SERVER_SRC
${SERVER_COMMON_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/capacity_unit_calculator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/compaction_filter_rule.cpp
${CMAKE_CURRENT_SOURCE_DIR}/compaction_operation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hotkey_collector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_event_listener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_manual_compact_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_mutation_duplicator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_server_impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_server_impl_init.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_server_write.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pegasus_write_service.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rocksdb_wrapper.cpp)

set(SERVER_COMMON_LIBS
dsn_utils)
set(COLLECTOR_LIBS
${SERVER_COMMON_LIBS}
dsn_meta_server
pegasus_client_static
event)
set(META_SERVER_LIBS
${SERVER_COMMON_LIBS}
dsn_meta_server
dsn_ranger
dsn.failure_detector
dsn.replication.zookeeper_provider
dsn.block_service
event
zookeeper
hashtable)
set(REPLICA_SERVER_LIBS
${SERVER_COMMON_LIBS}
dsn_replica_server
dsn_replication_common
dsn_client
dsn.block_service.local
dsn.block_service
dsn.failure_detector
dsn.replication.zookeeper_provider
dsn_utils
rocksdb
lz4
zstd
snappy
pegasus_base
pegasus_client_static
event
hashtable)
set(MY_BOOST_LIBS Boost::system Boost::filesystem)
set(MY_BINPLACES
config.ini)
add_definitions(-Wno-attributes)
SET(CMAKE_INSTALL_RPATH ".")
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
dsn_add_executable()
dsn_install_executable()
event)

if (SEPARATE_SERVERS)
add_subdirectory(collector)
add_subdirectory(meta_server)
add_subdirectory(replica_server)
else ()
set(MY_PROJ_NAME pegasus_server)
set(MY_PROJ_SRC "")
set(MY_SRC_SEARCH_MODE "GLOB")
set(MY_PROJ_LIBS
${SERVER_COMMON_LIBS}
${COLLECTOR_LIBS}
${META_SERVER_LIBS}
${REPLICA_SERVER_LIBS})
set(MY_BOOST_LIBS Boost::system Boost::filesystem)
set(MY_BINPLACES config.ini)
SET(CMAKE_INSTALL_RPATH ".")
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
dsn_add_executable()
dsn_install_executable()
endif ()
29 changes: 29 additions & 0 deletions src/server/collector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set(MY_PROJ_NAME "pegasus_collector")

set(MY_PROJ_SRC ${COLLECTOR_SRC})
set(MY_SRC_SEARCH_MODE "GLOB")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../")
set(MY_PROJ_LIBS ${COLLECTOR_LIBS})
set(MY_BOOST_LIBS Boost::system Boost::filesystem)
SET(CMAKE_INSTALL_RPATH ".")
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

dsn_add_executable()
dsn_install_executable()
50 changes: 50 additions & 0 deletions src/server/collector/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <unistd.h>
#include <memory>

#include "info_collector_app.h"
#include "pegasus_service_app.h"
#include "runtime/app_model.h"
#include "runtime/service_app.h"
#include "server/server_utils.h"
#include "utils/fmt_logging.h"

namespace dsn {
class command_deregister;
} // namespace dsn

int main(int argc, char **argv)
{
static const char server_name[] = "Collector";
if (help(argc, argv, server_name)) {
dsn_exit(0);
}
LOG_INFO("{} starting, pid({}), version({})", server_name, getpid(), pegasus_server_rcsid());

// Register collector service.
dsn::service_app::register_factory<pegasus::server::info_collector_app>("collector");

auto server_info_cmd = register_server_info_cmd();

dsn_run(argc, argv, true);

return 0;
}
Loading

0 comments on commit d7087b6

Please sign in to comment.