diff --git a/src/daemons/StandAloneDaemon.cpp b/src/daemons/StandAloneDaemon.cpp index cd5c005e0ff..c24e0095e54 100644 --- a/src/daemons/StandAloneDaemon.cpp +++ b/src/daemons/StandAloneDaemon.cpp @@ -24,6 +24,7 @@ #include "daemons/SetupLogging.h" #include "folly/ScopeGuard.h" #include "graph/service/GraphFlags.h" +#include "graph/service/GraphServer.h" #include "graph/service/GraphService.h" #include "graph/stats/GraphStats.h" #include "meta/MetaServiceHandler.h" @@ -58,7 +59,7 @@ extern Status setupBreakpad(); #endif std::unique_ptr gStorageServer; -static std::unique_ptr gServer; +static std::unique_ptr gServer; static std::unique_ptr gMetaServer; static std::unique_ptr gMetaKVStore; std::mutex gServerGuard; @@ -311,34 +312,13 @@ int main(int argc, char *argv[]) { auto threadFactory = std::make_shared("graph-netio"); auto ioThreadPool = std::make_shared(FLAGS_num_netio_threads, std::move(threadFactory)); - gServer = std::make_unique(); - gServer->setIOThreadPool(ioThreadPool); - - auto interface = std::make_shared(); - status = interface->init(ioThreadPool, localhost); - if (!status.ok()) { - LOG(ERROR) << status; + gServer = std::make_unique(localhost); + if (!gServer->start()) { + LOG(ERROR) << "The graph server start failed"; return; } - gServer->setPort(localhost.port); - gServer->setInterface(std::move(interface)); - gServer->setReusePort(FLAGS_reuse_port); - gServer->setIdleTimeout(std::chrono::seconds(FLAGS_client_idle_timeout_secs)); - gServer->setNumAcceptThreads(FLAGS_num_accept_threads); - gServer->setListenBacklog(FLAGS_listen_backlog); - if (FLAGS_enable_ssl || FLAGS_enable_graph_ssl) { - gServer->setSSLConfig(nebula::sslContextConfig()); - } - setupThreadManager(); - // Modify two blocking service - FLOG_INFO("Starting nebula-graphd on %s:%d\n", localhost.host.c_str(), localhost.port); - try { - gServer->serve(); // Blocking wait until shut down via gServer->stop() - } catch (const std::exception &e) { - FLOG_ERROR("Exception thrown while starting the RPC server: %s", e.what()); - return; - } + gServer->waitUntilStop(); FLOG_INFO("nebula-graphd on %s:%d has been stopped", localhost.host.c_str(), localhost.port); graphRet = EXIT_SUCCESS; return; @@ -398,7 +378,7 @@ Status setupSignalHandler() { void stopAllDaemon() { std::lock_guard guard(gServerGuard); if (gServer) { - gServer->stop(); + gServer->notifyStop(); gServer.reset(); } if (gStorageServer) { @@ -436,13 +416,3 @@ void signalHandler(int sig) { void printHelp(const char *prog) { fprintf(stderr, "%s --flagfile \n", prog); } - -void setupThreadManager() { - int numThreads = - FLAGS_num_worker_threads > 0 ? FLAGS_num_worker_threads : gServer->getNumIOWorkerThreads(); - std::shared_ptr threadManager( - PriorityThreadManager::newPriorityThreadManager(numThreads)); - threadManager->setNamePrefix("executor"); - threadManager->start(); - gServer->setThreadManager(threadManager); -}