diff --git a/CMakeLists.txt b/CMakeLists.txt index 48a9da2457..5cc4c70044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/run.sh b/run.sh index a8ec64edd7..903e059ba9 100755 --- a/run.sh +++ b/run.sh @@ -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 build with sanitizer to check potential problems, type: address|leak|thread|undefined" echo " --skip_thirdparty whether to skip building thirdparties, default no" @@ -130,6 +131,7 @@ function run_build() SANITIZER="" ROCKSDB_PORTABLE=0 USE_JEMALLOC=OFF + SEPARATE_SERVERS=OFF BUILD_TEST=OFF IWYU="" BUILD_MODULES="" @@ -198,6 +200,9 @@ function run_build() ENABLE_GPERF=OFF USE_JEMALLOC=ON ;; + --separate_servers) + SEPARATE_SERVERS=ON + ;; --test) BUILD_TEST=ON ;; @@ -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" ] diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 11673f6930..f4a0f0bab3 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -15,33 +15,78 @@ # 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 () \ No newline at end of file diff --git a/src/server/main.cpp b/src/server/main.cpp index 3aefd1329d..0a5df8b44b 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -17,18 +17,10 @@ * under the License. */ -#include -#include -#include -#include #include -#include -#include #include #include -#include -#include "backup_types.h" #include "common/replication_common.h" #include "compaction_operation.h" #include "info_collector_app.h" @@ -37,77 +29,31 @@ #include "pegasus_service_app.h" #include "runtime/app_model.h" #include "runtime/service_app.h" -#include "utils/command_manager.h" +#include "server/server_utils.h" #include "utils/fmt_logging.h" -#include "utils/process_utils.h" -#include "utils/strings.h" -#include "utils/time_utils.h" -#include "utils/utils.h" -#define STR_I(var) #var -#define STR(var) STR_I(var) -#ifndef DSN_BUILD_TYPE -#define PEGASUS_BUILD_TYPE "" -#else -#define PEGASUS_BUILD_TYPE STR(DSN_BUILD_TYPE) -#endif - -static char const rcsid[] = - "$Version: Pegasus Server " PEGASUS_VERSION " (" PEGASUS_GIT_COMMIT ")" -#if defined(DSN_BUILD_TYPE) - " " STR(DSN_BUILD_TYPE) -#endif - ", built by gcc " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) -#if defined(DSN_BUILD_HOSTNAME) - ", built on " STR(DSN_BUILD_HOSTNAME) -#endif - ", built at " __DATE__ " " __TIME__ " $"; - -const char *pegasus_server_rcsid() { return rcsid; } - -using namespace dsn; -using namespace dsn::replication; - -void dsn_app_registration_pegasus() +int main(int argc, char **argv) { + static const char server_name[] = "Pegasus server"; + if (help(argc, argv, server_name)) { + dsn_exit(0); + } + LOG_INFO("{} starting, pid({}), version({})", server_name, getpid(), pegasus_server_rcsid()); + + // Register meta service. dsn::service::meta_service_app::register_components(); - service_app::register_factory("meta"); - service_app::register_factory( + dsn::service_app::register_factory("meta"); + + // Register replica service. + dsn::service_app::register_factory( dsn::replication::replication_options::kReplicaAppType.c_str()); - service_app::register_factory("collector"); pegasus::server::pegasus_server_impl::register_service(); pegasus::server::register_compaction_operations(); -} -int main(int argc, char **argv) -{ - for (int i = 1; i < argc; ++i) { - if (utils::equals(argv[i], "-v") || utils::equals(argv[i], "-version") || - utils::equals(argv[i], "--version")) { - printf("Pegasus Server %s (%s) %s\n", - PEGASUS_VERSION, - PEGASUS_GIT_COMMIT, - PEGASUS_BUILD_TYPE); - dsn_exit(0); - } - } - LOG_INFO("pegasus server starting, pid({}), version({})", getpid(), pegasus_server_rcsid()); - dsn_app_registration_pegasus(); + // Register collector service. + dsn::service_app::register_factory("collector"); - std::unique_ptr server_info_cmd = - dsn::command_manager::instance().register_single_command( - "server-info", - "Query server information", - "", - [](const std::vector &args) { - nlohmann::json info; - info["version"] = PEGASUS_VERSION; - info["build_type"] = PEGASUS_BUILD_TYPE; - info["git_SHA"] = PEGASUS_GIT_COMMIT; - info["start_time"] = - ::dsn::utils::time_s_to_date_time(dsn::utils::process_start_millis() / 1000); - return info.dump(); - }); + auto server_info_cmd = register_server_info_cmd(); dsn_run(argc, argv, true); diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h index 70fc62119f..e4e16f6218 100644 --- a/src/shell/command_helper.h +++ b/src/shell/command_helper.h @@ -66,14 +66,6 @@ using namespace dsn::replication; -#define STR_I(var) #var -#define STR(var) STR_I(var) -#ifndef DSN_BUILD_TYPE -#define PEGASUS_BUILD_TYPE "" -#else -#define PEGASUS_BUILD_TYPE STR(DSN_BUILD_TYPE) -#endif - DEFINE_TASK_CODE(LPC_SCAN_DATA, TASK_PRIORITY_COMMON, ::dsn::THREAD_POOL_DEFAULT) DEFINE_TASK_CODE(LPC_GET_METRICS, TASK_PRIORITY_COMMON, ::dsn::THREAD_POOL_DEFAULT) diff --git a/src/shell/commands/misc.cpp b/src/shell/commands/misc.cpp index 4d5cec745c..e45b1442e9 100644 --- a/src/shell/commands/misc.cpp +++ b/src/shell/commands/misc.cpp @@ -23,8 +23,8 @@ #include "pegasus/git_commit.h" #include "pegasus/version.h" #include "runtime/app_model.h" +#include "server/server_utils.h" #include "shell/command_executor.h" -#include "shell/command_helper.h" #include "shell/commands.h" bool version(command_executor *e, shell_context *sc, arguments args)