-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 crash problem when stop process. #705
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,14 +100,16 @@ int main(int argc, char *argv[]) { | |
// The meta server has only one space, one part. | ||
partMan->addPart(0, 0, std::move(peersRet.value())); | ||
|
||
// folly IOThreadPoolExecutor | ||
// notice: ioThreadPool and acceptThreadPool will stopped when NebulaStore free raftservice | ||
auto ioPool = std::make_shared<folly::IOThreadPoolExecutor>(FLAGS_num_io_threads); | ||
auto acceptThreadPool = std::make_shared<folly::IOThreadPoolExecutor>(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
nebula::kvstore::KVOptions options; | ||
options.dataPaths_ = {FLAGS_data_path}; | ||
options.partMan_ = std::move(partMan); | ||
auto kvstore = std::make_unique<nebula::kvstore::NebulaStore>(std::move(options), | ||
ioPool, | ||
auto kvstore = std::make_unique<nebula::kvstore::NebulaStore>(std::move(options), | ||
ioPool, | ||
acceptThreadPool, | ||
localhost); | ||
if (!(kvstore->init())) { | ||
LOG(ERROR) << "nebula store init failed"; | ||
|
@@ -154,7 +156,15 @@ int main(int argc, char *argv[]) { | |
gServer->setReusePort(FLAGS_reuse_port); | ||
gServer->setIdleTimeout(std::chrono::seconds(0)); // No idle timeout on client connection | ||
gServer->setIOThreadPool(ioPool); | ||
gServer->setAcceptExecutor(acceptThreadPool); | ||
|
||
// set false to stop that gServer stop all io thread when call gServer->stop(); | ||
// because NebulaStore's raft part dependencies the io thread pool. | ||
gServer->setStopWorkersOnStopListening(false); | ||
gServer->serve(); // Will wait until the server shuts down | ||
|
||
// must stop the cpu worker first, because kvstore will free before gServer. | ||
gServer->getThreadManager()->join(); | ||
} catch (const std::exception &e) { | ||
nebula::WebService::stop(); | ||
LOG(ERROR) << "Exception thrown: " << e.what(); | ||
|
@@ -169,7 +179,7 @@ int main(int argc, char *argv[]) { | |
|
||
Status setupSignalHandler() { | ||
return nebula::SignalHandler::install( | ||
{SIGINT, SIGTERM}, | ||
{SIGINT, SIGTERM}, | ||
[](nebula::SignalHandler::GeneralSignalInfo *info) { | ||
signalHandler(info->sig()); | ||
}); | ||
|
@@ -181,7 +191,9 @@ void signalHandler(int sig) { | |
case SIGINT: | ||
case SIGTERM: | ||
FLOG_INFO("Signal %d(%s) received, stopping this server", sig, ::strsignal(sig)); | ||
gServer->stop(); | ||
if (gServer) { | ||
gServer->stop(); | ||
} | ||
break; | ||
default: | ||
FLOG_ERROR("Signal %d(%s) received but ignored", sig, ::strsignal(sig)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ namespace raftex { | |
* | ||
******************************************************/ | ||
std::shared_ptr<RaftexService> RaftexService::createService( | ||
std::shared_ptr<folly::IOThreadPoolExecutor> pool, | ||
std::shared_ptr<folly::IOThreadPoolExecutor> ioPool, | ||
std::shared_ptr<folly::IOThreadPoolExecutor> acceptPool, | ||
uint16_t port) { | ||
auto svc = std::shared_ptr<RaftexService>(new RaftexService()); | ||
CHECK(svc != nullptr) << "Failed to create a raft service"; | ||
|
@@ -27,7 +28,7 @@ std::shared_ptr<RaftexService> RaftexService::createService( | |
CHECK(svc->server_ != nullptr) << "Failed to create a thrift server"; | ||
svc->server_->setInterface(svc); | ||
|
||
svc->initThriftServer(pool, port); | ||
svc->initThriftServer(ioPool, acceptPool, port); | ||
return svc; | ||
} | ||
|
||
|
@@ -58,12 +59,15 @@ void RaftexService::waitUntilReady() { | |
} | ||
|
||
|
||
void RaftexService::initThriftServer(std::shared_ptr<folly::IOThreadPoolExecutor> pool, | ||
uint16_t port) { | ||
void RaftexService::initThriftServer(std::shared_ptr<folly::IOThreadPoolExecutor> ioPool, | ||
std::shared_ptr<folly::IOThreadPoolExecutor> acceptPool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alignment |
||
uint16_t port) { | ||
LOG(INFO) << "Init thrift server for raft service."; | ||
server_->setPort(port); | ||
if (pool != nullptr) { | ||
server_->setIOThreadPool(pool); | ||
if (ioPool != nullptr && acceptPool != nullptr) { | ||
server_->setIOThreadPool(ioPool); | ||
server_->setAcceptExecutor(acceptPool); | ||
server_->setStopWorkersOnStopListening(false); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,18 @@ | |
|
||
DEFINE_int32(load_data_interval_secs, 2 * 60, "Load data interval"); | ||
DEFINE_int32(heartbeat_interval_secs, 10, "Heartbeat interval"); | ||
DEFINE_int32(meta_client_io_thread_num, 2, "meta client io thread number"); | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
MetaClient::MetaClient(std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool, | ||
std::vector<HostAddr> addrs, | ||
MetaClient::MetaClient(std::vector<HostAddr> addrs, | ||
HostAddr localHost, | ||
bool sendHeartBeat) | ||
: ioThreadPool_(ioThreadPool) | ||
, addrs_(std::move(addrs)) | ||
: addrs_(std::move(addrs)) | ||
, localHost_(localHost) | ||
, sendHeartBeat_(sendHeartBeat) { | ||
ioThreadPool_ = std::make_unique<folly::IOThreadPoolExecutor>(FLAGS_meta_client_io_thread_num); | ||
CHECK(ioThreadPool_ != nullptr) << "IOThreadPool is required"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seems necessary anymore. |
||
CHECK(!addrs_.empty()) | ||
<< "No meta server address is specified. Meta server is required"; | ||
|
@@ -37,6 +37,8 @@ MetaClient::MetaClient(std::shared_ptr<folly::IOThreadPoolExecutor> ioThreadPool | |
MetaClient::~MetaClient() { | ||
bgThread_.stop(); | ||
bgThread_.wait(); | ||
|
||
ioThreadPool_->stop(); | ||
VLOG(3) << "~MetaClient"; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I think about this problem, but I get the result is there is no need configure, 1 thread is too much, because accept thread pool just accept connection from client which is our process like graphd or meta, and they a long connection, so the performance is not high, what do you think about?