Skip to content

Commit

Permalink
feat: Support to build server binaries separately
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed May 20, 2024
1 parent 0ee404e commit 451a19c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 101 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
87 changes: 66 additions & 21 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
86 changes: 16 additions & 70 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
* under the License.
*/

#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <pegasus/git_commit.h>
#include <pegasus/version.h>
#include <unistd.h>
#include <cstdio>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include "backup_types.h"
#include "common/replication_common.h"
#include "compaction_operation.h"
#include "info_collector_app.h"
Expand All @@ -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<pegasus::server::pegasus_meta_service_app>("meta");
service_app::register_factory<pegasus::server::pegasus_replication_service_app>(
dsn::service_app::register_factory<pegasus::server::pegasus_meta_service_app>("meta");

// Register replica service.
dsn::service_app::register_factory<pegasus::server::pegasus_replication_service_app>(
dsn::replication::replication_options::kReplicaAppType.c_str());
service_app::register_factory<pegasus::server::info_collector_app>("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<pegasus::server::info_collector_app>("collector");

std::unique_ptr<command_deregister> server_info_cmd =
dsn::command_manager::instance().register_single_command(
"server-info",
"Query server information",
"",
[](const std::vector<std::string> &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);

Expand Down
8 changes: 0 additions & 8 deletions src/shell/command_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/shell/commands/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 451a19c

Please sign in to comment.