Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix service crash #3616

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/daemons/GraphDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ using nebula::fs::FileUtils;
using nebula::graph::GraphService;
using nebula::network::NetworkUtils;

static void signalHandler(int sig);
static Status setupSignalHandler();
static void signalHandler(nebula::graph::GraphServer *graphServer, int sig);
static Status setupSignalHandler(nebula::graph::GraphServer *graphServer);
static void printHelp(const char *prog);
#if defined(__x86_64__)
extern Status setupBreakpad();
Expand All @@ -40,8 +40,6 @@ extern Status setupBreakpad();
DECLARE_string(flagfile);
DECLARE_bool(containerized);

std::unique_ptr<nebula::graph::GraphServer> gServer;

int main(int argc, char *argv[]) {
google::SetVersionString(nebula::versionString());
if (argc == 1) {
Expand Down Expand Up @@ -153,37 +151,37 @@ int main(int argc, char *argv[]) {
}
LOG(INFO) << "Number of worker threads: " << FLAGS_num_worker_threads;

auto graphServer = std::make_unique<nebula::graph::GraphServer>(localhost);
// Setup the signal handlers
status = setupSignalHandler();
status = setupSignalHandler(graphServer.get());
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

gServer = std::make_unique<nebula::graph::GraphServer>(localhost);

if (!gServer->start()) {
if (!graphServer->start()) {
LOG(ERROR) << "The graph server start failed";
return EXIT_FAILURE;
}

gServer->waitUntilStop();
graphServer->waitUntilStop();
LOG(INFO) << "The graph Daemon stopped";
return EXIT_SUCCESS;
}

Status setupSignalHandler() {
Status setupSignalHandler(nebula::graph::GraphServer *graphServer) {
return nebula::SignalHandler::install(
{SIGINT, SIGTERM},
[](nebula::SignalHandler::GeneralSignalInfo *info) { signalHandler(info->sig()); });
{SIGINT, SIGTERM}, [graphServer](nebula::SignalHandler::GeneralSignalInfo *info) {
signalHandler(graphServer, info->sig());
});
}

void signalHandler(int sig) {
void signalHandler(nebula::graph::GraphServer *graphServer, int sig) {
switch (sig) {
case SIGINT:
case SIGTERM:
FLOG_INFO("Signal %d(%s) received, stopping this server", sig, ::strsignal(sig));
gServer->notifyStop();
graphServer->notifyStop();
break;
default:
FLOG_ERROR("Signal %d(%s) received but ignored", sig, ::strsignal(sig));
Expand Down
32 changes: 16 additions & 16 deletions src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ DEFINE_int32(meta_http_thread_num, 3, "Number of meta daemon's http thread");
DEFINE_string(pid_file, "pids/nebula-metad.pid", "File to hold the process id");
DEFINE_bool(daemonize, true, "Whether run as a daemon process");

static std::unique_ptr<apache::thrift::ThriftServer> gServer;
static std::unique_ptr<nebula::kvstore::KVStore> gKVStore;

static void signalHandler(int sig);
static void signalHandler(apache::thrift::ThriftServer* metaServer, int sig);
static void waitForStop();
static Status setupSignalHandler();
static Status setupSignalHandler(apache::thrift::ThriftServer* metaServer);
#if defined(__x86_64__)
extern Status setupBreakpad();
#endif
Expand Down Expand Up @@ -189,8 +188,9 @@ int main(int argc, char* argv[]) {
}
}

auto metaServer = std::make_unique<apache::thrift::ThriftServer>();
// Setup the signal handlers
status = setupSignalHandler();
status = setupSignalHandler(metaServer.get());
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
Expand All @@ -215,14 +215,13 @@ int main(int argc, char* argv[]) {
std::make_shared<nebula::meta::MetaServiceHandler>(gKVStore.get(), metaClusterId());
LOG(INFO) << "The meta daemon start on " << localhost;
try {
gServer = std::make_unique<apache::thrift::ThriftServer>();
gServer->setPort(FLAGS_port);
gServer->setIdleTimeout(std::chrono::seconds(0)); // No idle timeout on client connection
gServer->setInterface(std::move(handler));
metaServer->setPort(FLAGS_port);
metaServer->setIdleTimeout(std::chrono::seconds(0)); // No idle timeout on client connection
metaServer->setInterface(std::move(handler));
if (FLAGS_enable_ssl || FLAGS_enable_meta_ssl) {
gServer->setSSLConfig(nebula::sslContextConfig());
metaServer->setSSLConfig(nebula::sslContextConfig());
}
gServer->serve(); // Will wait until the server shuts down
metaServer->serve(); // Will wait until the server shuts down
waitForStop();
} catch (const std::exception& e) {
LOG(ERROR) << "Exception thrown: " << e.what();
Expand All @@ -233,19 +232,20 @@ int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}

Status setupSignalHandler() {
Status setupSignalHandler(apache::thrift::ThriftServer* metaServer) {
return nebula::SignalHandler::install(
{SIGINT, SIGTERM},
[](nebula::SignalHandler::GeneralSignalInfo* info) { signalHandler(info->sig()); });
{SIGINT, SIGTERM}, [metaServer](nebula::SignalHandler::GeneralSignalInfo* info) {
signalHandler(metaServer, info->sig());
});
}

void signalHandler(int sig) {
void signalHandler(apache::thrift::ThriftServer* metaServer, int sig) {
switch (sig) {
case SIGINT:
case SIGTERM:
FLOG_INFO("Signal %d(%s) received, stopping this server", sig, ::strsignal(sig));
if (gServer) {
gServer->stop();
if (metaServer) {
metaServer->stop();
}
break;
default:
Expand Down
31 changes: 15 additions & 16 deletions src/daemons/StorageDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ using nebula::Status;
using nebula::StatusOr;
using nebula::network::NetworkUtils;

static void signalHandler(int sig);
static Status setupSignalHandler();
static void signalHandler(nebula::storage::StorageServer *storageServer, int sig);
static Status setupSignalHandler(nebula::storage::StorageServer *storageServer);
#if defined(__x86_64__)
extern Status setupBreakpad();
#endif

std::unique_ptr<nebula::storage::StorageServer> gStorageServer;

int main(int argc, char *argv[]) {
google::SetVersionString(nebula::versionString());
// Detect if the server has already been started
Expand Down Expand Up @@ -150,8 +148,10 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

auto storageServer = std::make_unique<nebula::storage::StorageServer>(
localhost, metaAddrsRet.value(), paths, FLAGS_wal_path, FLAGS_listener_path);
// Setup the signal handlers
status = setupSignalHandler();
status = setupSignalHandler(storageServer.get());
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
Expand All @@ -172,32 +172,31 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

gStorageServer = std::make_unique<nebula::storage::StorageServer>(
localhost, metaAddrsRet.value(), paths, FLAGS_wal_path, FLAGS_listener_path);
if (!gStorageServer->start()) {
if (!storageServer->start()) {
LOG(ERROR) << "Storage server start failed";
gStorageServer->stop();
storageServer->stop();
return EXIT_FAILURE;
}

gStorageServer->waitUntilStop();
storageServer->waitUntilStop();
LOG(INFO) << "The storage Daemon stopped";
return EXIT_SUCCESS;
}

Status setupSignalHandler() {
Status setupSignalHandler(nebula::storage::StorageServer *storageServer) {
return nebula::SignalHandler::install(
{SIGINT, SIGTERM},
[](nebula::SignalHandler::GeneralSignalInfo *info) { signalHandler(info->sig()); });
{SIGINT, SIGTERM}, [storageServer](nebula::SignalHandler::GeneralSignalInfo *info) {
signalHandler(storageServer, info->sig());
});
}

void signalHandler(int sig) {
void signalHandler(nebula::storage::StorageServer *storageServer, int sig) {
switch (sig) {
case SIGINT:
case SIGTERM:
FLOG_INFO("Signal %d(%s) received, stopping this server", sig, ::strsignal(sig));
if (gStorageServer) {
gStorageServer->notifyStop();
if (storageServer) {
storageServer->notifyStop();
}
break;
default:
Expand Down