mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
refactor eden stop during graceful takeover request to remove usage of some thrift functions
Summary: The thrift team is looking to retire `stopWorkers()` and `stopListening()`, so this refactors our code to stop using both of those methods. Differential Revision: D21851442 fbshipit-source-id: 6d63d435cbd4a51c855bf71a3b2165e35431a4d7
This commit is contained in:
parent
967f470a0d
commit
2dba19bf43
@ -1532,6 +1532,11 @@ Future<Unit> EdenServer::createThriftServer() {
|
||||
server_->setNumIOWorkerThreads(FLAGS_thrift_num_workers);
|
||||
server_->setEnableCodel(FLAGS_thrift_enable_codel);
|
||||
server_->setMinCompressBytes(FLAGS_thrift_min_compress_bytes);
|
||||
// Setting this allows us to to only do stopListening() on the stop() call
|
||||
// and delay thread-pool join (stop cpu workers + stop workers) untill
|
||||
// server object destruction. This specifically matters in the takeover
|
||||
// shutdown code path.
|
||||
server_->setStopWorkersOnStopListening(false);
|
||||
|
||||
handler_ = make_shared<EdenServiceHandler>(originalCommandLine_, this);
|
||||
server_->setInterface(handler_);
|
||||
@ -1671,14 +1676,11 @@ folly::Future<TakeoverData> EdenServer::startTakeoverShutdown() {
|
||||
|
||||
shutdownSubscribers();
|
||||
|
||||
// Stop listening on the thrift socket. This call will wait for in
|
||||
// process thrift requests to finish. We would like to wait for in
|
||||
// process thrift calls to finish here in order to let calls like
|
||||
// checkout still write to the overlay. In the future, we'd like to
|
||||
// Stop the thrift server. In the future, we'd like to
|
||||
// keep listening and instead start internally queueing thrift calls
|
||||
// to pass with the takeover data below, while waiting here for
|
||||
// currently processing thrift calls to finish.
|
||||
server_->stopListening();
|
||||
server_->stop();
|
||||
})
|
||||
.thenTry([this, takeoverPromise = std::move(takeoverPromise)](
|
||||
auto&& t) mutable {
|
||||
@ -1694,10 +1696,6 @@ folly::Future<TakeoverData> EdenServer::startTakeoverShutdown() {
|
||||
|
||||
takeover.thriftSocket = std::move(socket);
|
||||
|
||||
// Stop the thrift server.
|
||||
server_->stopWorkers();
|
||||
server_->stop();
|
||||
|
||||
return std::move(takeover);
|
||||
});
|
||||
#else
|
||||
|
@ -5,15 +5,45 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include "eden/fs/testharness/TestServer.h"
|
||||
#include <folly/io/async/EventBase.h>
|
||||
#include <thrift/lib/cpp2/server/ThriftServer.h>
|
||||
|
||||
#include "eden/fs/service/EdenServer.h"
|
||||
#include "eden/fs/testharness/TestServer.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace facebook::eden;
|
||||
|
||||
TEST(TestServerTest, returnsVersionNumber) {
|
||||
TestServer test;
|
||||
auto& server = test.getServer();
|
||||
EXPECT_EQ(server.getVersion(), "test server");
|
||||
namespace {
|
||||
class TestServerTest : public ::testing::Test {
|
||||
protected:
|
||||
EdenServer& getServer() {
|
||||
return testServer_.getServer();
|
||||
}
|
||||
|
||||
void runServer() {
|
||||
auto& thriftServer = getServer().getServer();
|
||||
thriftServer->serve();
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void runOnServerStart(F&& fn) {
|
||||
auto cb = std::make_unique<folly::EventBase::FunctionLoopCallback>(
|
||||
std::forward<F>(fn));
|
||||
folly::EventBaseManager::get()->getEventBase()->runInLoop(cb.release());
|
||||
}
|
||||
|
||||
TestServer testServer_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_F(TestServerTest, returnsVersionNumber) {
|
||||
runOnServerStart([&] {
|
||||
EXPECT_EQ(getServer().getVersion(), "test server");
|
||||
getServer().stop();
|
||||
});
|
||||
|
||||
// Run the server.
|
||||
runServer();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user