define constants for several files in the .eden directory

Summary:
Define constants at the top of EdenServer.cpp for the names of the main lock
file, the thrift socket, and the takeover socket.

Reviewed By: bolinfest

Differential Revision: D6295040

fbshipit-source-id: 8605840a50c84bc89b798123d1063bbb11ff2502
This commit is contained in:
Adam Simpkins 2017-11-20 11:34:38 -08:00 committed by Facebook Github Bot
parent e64baf16db
commit 7d98d9cfc4
2 changed files with 19 additions and 20 deletions

View File

@ -9,8 +9,6 @@
*/
#include "eden/fs/service/EdenServer.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <folly/Exception.h>
#include <folly/FileUtil.h>
#include <folly/SocketAddress.h>
@ -78,10 +76,15 @@ using std::string;
using std::unique_ptr;
namespace {
using namespace facebook::eden;
constexpr StringPiece kLockFileName{"lock"};
constexpr StringPiece kThriftSocketName{"socket"};
constexpr StringPiece kTakeoverSocketName{"takeover"};
folly::SocketAddress getThriftAddress(
StringPiece argument,
StringPiece edenDir);
std::string getPathToUnixDomainSocket(StringPiece edenDir);
AbsolutePathPiece edenDir);
} // namespace
namespace facebook {
@ -298,6 +301,12 @@ void EdenServer::run() {
// Acquire the eden lock, prepare the thrift server, and start our mounts
prepare();
// Start listening for graceful takeover requests
auto takeoverPath = edenDir_ + PathComponentPiece{kTakeoverSocketName};
takeoverServer_.reset(
new TakeoverServer(getMainEventBase(), takeoverPath, this));
takeoverServer_->start();
// Run the thrift server
state_.wlock()->state = State::RUNNING;
runServer(*this);
@ -604,7 +613,7 @@ shared_ptr<BackingStore> EdenServer::createBackingStore(
}
void EdenServer::createThriftServer() {
auto address = getThriftAddress(FLAGS_thrift_address, edenDir_.stringPiece());
auto address = getThriftAddress(FLAGS_thrift_address, edenDir_);
server_ = make_shared<ThriftServer>();
server_->setMaxRequests(FLAGS_thrift_max_requests);
@ -621,9 +630,8 @@ void EdenServer::createThriftServer() {
}
bool EdenServer::acquireEdenLock() {
boost::filesystem::path edenPath{edenDir_.stringPiece().str()};
boost::filesystem::path lockPath = edenPath / "lock";
lockFile_ = folly::File(lockPath.string(), O_WRONLY | O_CREAT);
auto lockPath = edenDir_ + PathComponentPiece{kLockFileName};
lockFile_ = folly::File(lockPath.value(), O_WRONLY | O_CREAT);
if (!lockFile_.try_lock()) {
lockFile_.close();
return false;
@ -723,14 +731,14 @@ namespace {
*/
folly::SocketAddress getThriftAddress(
StringPiece argument,
StringPiece edenDir) {
AbsolutePathPiece edenDir) {
folly::SocketAddress addr;
// If the argument is empty, default to a Unix socket placed next
// to the mount point
if (argument.empty()) {
auto socketPath = getPathToUnixDomainSocket(edenDir);
addr.setFromPath(socketPath);
auto socketPath = edenDir + PathComponentPiece{kThriftSocketName};
addr.setFromPath(socketPath.stringPiece());
return addr;
}
@ -755,10 +763,4 @@ folly::SocketAddress getThriftAddress(
return addr;
}
std::string getPathToUnixDomainSocket(StringPiece edenDir) {
boost::filesystem::path edenPath{edenDir.str()};
boost::filesystem::path socketPath = edenPath / "socket";
return socketPath.string();
}
} // unnamed namespace

View File

@ -62,9 +62,6 @@ cpp_library(
"@/thrift/lib/cpp/concurrency:thread_manager",
"@/thrift/lib/cpp2:server",
],
external_deps = [
("boost", None, "boost_filesystem"),
],
)
# The eden.thrift interface.