2016-05-12 23:43:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <folly/File.h>
|
|
|
|
#include <folly/Range.h>
|
|
|
|
#include <folly/SocketAddress.h>
|
|
|
|
#include <folly/Synchronized.h>
|
|
|
|
#include <folly/experimental/StringKeyedMap.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace apache {
|
|
|
|
namespace thrift {
|
|
|
|
class ThriftServer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
2016-05-24 07:32:12 +03:00
|
|
|
class ClientConfig;
|
2016-05-20 20:33:42 +03:00
|
|
|
class EdenMount;
|
2016-05-12 23:43:17 +03:00
|
|
|
class EdenServiceHandler;
|
|
|
|
class LocalStore;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EdenServer contains logic for running the Eden main loop.
|
|
|
|
*
|
|
|
|
* It performs locking to ensure only a single EdenServer instance is running
|
|
|
|
* for a particular location, then starts the thrift management server
|
|
|
|
* and the fuse session.
|
|
|
|
*/
|
|
|
|
class EdenServer {
|
|
|
|
public:
|
2016-05-20 20:33:42 +03:00
|
|
|
using MountList = std::vector<std::shared_ptr<EdenMount>>;
|
|
|
|
using MountMap = folly::StringKeyedMap<std::shared_ptr<EdenMount>>;
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
EdenServer(folly::StringPiece edenDir, folly::StringPiece rocksPath);
|
|
|
|
virtual ~EdenServer();
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
2016-05-24 07:32:12 +03:00
|
|
|
void mount(
|
|
|
|
std::shared_ptr<EdenMount> edenMount,
|
|
|
|
std::unique_ptr<ClientConfig> config);
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
void unmount(folly::StringPiece mountPath);
|
|
|
|
|
|
|
|
const std::shared_ptr<EdenServiceHandler>& getHandler() const {
|
|
|
|
return handler_;
|
|
|
|
}
|
|
|
|
const std::shared_ptr<apache::thrift::ThriftServer>& getServer() const {
|
|
|
|
return server_;
|
|
|
|
}
|
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
MountList getMountPoints() const;
|
|
|
|
std::shared_ptr<EdenMount> getMount(folly::StringPiece mountPath) const;
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
std::shared_ptr<LocalStore> getLocalStore() const {
|
|
|
|
return localStore_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Forbidden copy constructor and assignment operator
|
|
|
|
EdenServer(EdenServer const&) = delete;
|
|
|
|
EdenServer& operator=(EdenServer const&) = delete;
|
|
|
|
|
|
|
|
void runThriftServer();
|
|
|
|
void createThriftServer();
|
|
|
|
void acquireEdenLock();
|
|
|
|
void prepareThriftAddress();
|
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
// Called when a mount has been unmounted and has stopped.
|
|
|
|
void mountFinished(EdenMount* mountPoint);
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
std::string edenDir_;
|
|
|
|
std::string rocksPath_;
|
|
|
|
std::shared_ptr<EdenServiceHandler> handler_;
|
|
|
|
std::shared_ptr<apache::thrift::ThriftServer> server_;
|
|
|
|
folly::File lockFile_;
|
|
|
|
|
|
|
|
std::shared_ptr<LocalStore> localStore_;
|
2016-05-20 20:33:42 +03:00
|
|
|
folly::Synchronized<MountMap> mountPoints_;
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // facebook::eden
|