2016-05-12 23:43:17 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-05-12 23:43:17 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2016-05-12 23:43:17 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 18:26:52 +03:00
|
|
|
#include <folly/Executor.h>
|
2016-05-12 23:43:17 +03:00
|
|
|
#include <folly/File.h>
|
2017-11-20 22:34:37 +03:00
|
|
|
#include <folly/Portability.h>
|
2016-05-12 23:43:17 +03:00
|
|
|
#include <folly/Range.h>
|
|
|
|
#include <folly/SocketAddress.h>
|
|
|
|
#include <folly/Synchronized.h>
|
2017-03-31 21:23:02 +03:00
|
|
|
#include <folly/ThreadLocal.h>
|
2016-05-12 23:43:17 +03:00
|
|
|
#include <folly/experimental/StringKeyedMap.h>
|
2017-08-01 06:48:19 +03:00
|
|
|
#include <folly/futures/SharedPromise.h>
|
2016-07-01 07:00:01 +03:00
|
|
|
#include <condition_variable>
|
2016-05-12 23:43:17 +03:00
|
|
|
#include <memory>
|
2016-07-01 07:00:01 +03:00
|
|
|
#include <mutex>
|
2018-10-24 04:48:38 +03:00
|
|
|
#include <optional>
|
2016-06-14 01:15:31 +03:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
2016-05-12 23:43:17 +03:00
|
|
|
#include <vector>
|
2018-07-10 02:53:17 +03:00
|
|
|
#include "eden/fs/config/EdenConfig.h"
|
2019-04-17 07:14:33 +03:00
|
|
|
#include "eden/fs/inodes/ServerState.h"
|
|
|
|
#include "eden/fs/service/EdenStateDir.h"
|
2019-05-31 01:08:02 +03:00
|
|
|
#include "eden/fs/service/PeriodicTask.h"
|
2019-04-17 07:14:33 +03:00
|
|
|
#include "eden/fs/takeover/TakeoverHandler.h"
|
2019-10-15 23:37:04 +03:00
|
|
|
#include "eden/fs/telemetry/EdenStats.h"
|
2019-04-17 07:14:33 +03:00
|
|
|
#include "eden/fs/utils/PathFuncs.h"
|
|
|
|
|
2019-05-10 02:28:23 +03:00
|
|
|
#ifdef _WIN32
|
2019-05-10 02:28:23 +03:00
|
|
|
#include "eden/fs/win/mount/EdenMount.h" // @manual
|
|
|
|
#include "eden/fs/win/utils/Stub.h" // @manual
|
|
|
|
#include "eden/fs/win/utils/UserInfo.h" // @manual
|
2018-10-21 03:33:33 +03:00
|
|
|
#else
|
2018-01-10 09:00:50 +03:00
|
|
|
#include "eden/fs/fuse/FuseTypes.h"
|
2018-01-10 09:01:00 +03:00
|
|
|
#include "eden/fs/inodes/EdenMount.h"
|
2018-01-10 09:00:58 +03:00
|
|
|
#include "eden/fs/takeover/TakeoverData.h"
|
2018-10-21 03:33:33 +03:00
|
|
|
#endif
|
|
|
|
|
2017-08-25 22:41:41 +03:00
|
|
|
constexpr folly::StringPiece kPeriodicUnloadCounterKey{"PeriodicUnloadCounter"};
|
2020-02-18 19:03:48 +03:00
|
|
|
DECLARE_bool(takeover);
|
2017-08-25 22:41:41 +03:00
|
|
|
|
2019-08-29 03:11:37 +03:00
|
|
|
namespace cpptoml {
|
|
|
|
class table;
|
|
|
|
} // namespace cpptoml
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
namespace apache {
|
|
|
|
namespace thrift {
|
|
|
|
class ThriftServer;
|
|
|
|
}
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace apache
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2017-09-01 04:58:48 +03:00
|
|
|
namespace folly {
|
|
|
|
class EventBase;
|
|
|
|
}
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
2016-06-14 01:15:31 +03:00
|
|
|
class BackingStore;
|
2020-03-06 20:25:21 +03:00
|
|
|
class HgBackingStore;
|
2018-11-26 22:08:10 +03:00
|
|
|
class BlobCache;
|
2016-11-26 23:00:16 +03:00
|
|
|
class Dirstate;
|
2016-05-12 23:43:17 +03:00
|
|
|
class EdenServiceHandler;
|
2019-11-14 02:21:37 +03:00
|
|
|
struct SessionInfo;
|
2016-05-12 23:43:17 +03:00
|
|
|
class LocalStore;
|
2017-09-13 18:26:53 +03:00
|
|
|
class MountInfo;
|
2018-06-26 22:05:27 +03:00
|
|
|
class StartupLogger;
|
2019-05-10 02:28:23 +03:00
|
|
|
#ifndef _WIN32
|
2017-11-20 02:18:29 +03:00
|
|
|
class TakeoverServer;
|
2018-10-21 03:33:33 +03:00
|
|
|
#endif
|
2020-02-10 19:27:04 +03:00
|
|
|
class Notifications;
|
2019-07-17 23:43:32 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
2019-03-16 04:10:28 +03:00
|
|
|
*
|
|
|
|
* The general usage model to run an EdenServer is:
|
|
|
|
* - Call prepare().
|
|
|
|
* - Run the thrift server. The server object can be obtained by calling
|
|
|
|
* getServer(). When the thrift server stops this indicates the EdenServer
|
|
|
|
* is done and should be shut down.
|
|
|
|
* - Call performCleanup() to let the EdenServer shut down. This includes
|
|
|
|
* unmounting FUSE mounts or, if a graceful restart was requested,
|
|
|
|
* transferring state to the new process.
|
|
|
|
*
|
|
|
|
* These are 3 separate steps to provide the caller with flexibility around
|
|
|
|
* exactly how they drive the thrift server object.
|
2016-05-12 23:43:17 +03:00
|
|
|
*/
|
2017-11-20 02:18:29 +03:00
|
|
|
class EdenServer : private TakeoverHandler {
|
2016-05-12 23:43:17 +03:00
|
|
|
public:
|
2019-01-25 00:44:49 +03:00
|
|
|
enum class RunState {
|
|
|
|
STARTING,
|
|
|
|
RUNNING,
|
|
|
|
SHUTTING_DOWN,
|
|
|
|
};
|
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
using MountList = std::vector<std::shared_ptr<EdenMount>>;
|
2016-11-26 23:00:16 +03:00
|
|
|
using DirstateMap = folly::StringKeyedMap<std::shared_ptr<Dirstate>>;
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2016-07-26 20:15:43 +03:00
|
|
|
EdenServer(
|
2019-07-17 23:43:32 +03:00
|
|
|
std::vector<std::string> originalCommandLine,
|
2018-02-09 03:33:32 +03:00
|
|
|
UserInfo userInfo,
|
2019-11-14 02:21:37 +03:00
|
|
|
SessionInfo sessionInfo,
|
2018-02-09 06:31:59 +03:00
|
|
|
std::unique_ptr<PrivHelper> privHelper,
|
2019-10-24 22:46:59 +03:00
|
|
|
std::shared_ptr<const EdenConfig> edenConfig,
|
|
|
|
std::string version = "");
|
2018-01-18 00:29:59 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
virtual ~EdenServer();
|
|
|
|
|
2019-01-25 00:44:49 +03:00
|
|
|
/**
|
|
|
|
* Get the server's current status.
|
|
|
|
*
|
|
|
|
* This is primarily used for diagnostic purposes.
|
|
|
|
* Note that the status may change immediately after this method returns, so
|
|
|
|
* the value may be out of date by the time the caller can use it.
|
|
|
|
*/
|
|
|
|
RunState getStatus() const {
|
|
|
|
return runningState_.rlock()->state;
|
|
|
|
}
|
|
|
|
|
2017-03-21 22:57:07 +03:00
|
|
|
/**
|
2017-04-14 21:31:49 +03:00
|
|
|
* Prepare to run the EdenServer.
|
2017-03-21 22:57:07 +03:00
|
|
|
*
|
2018-06-12 03:54:24 +03:00
|
|
|
* This acquires the lock on the eden directory, prepares the thrift server to
|
|
|
|
* run, and begins remounting configured mount points.
|
2017-03-21 22:57:07 +03:00
|
|
|
*
|
2018-06-26 22:05:27 +03:00
|
|
|
* Most of the preparation occurs synchronously before prepare() returns,
|
|
|
|
* however a few steps complete asynchronously. The status of the
|
|
|
|
* asynchronous preparation steps is tracked in the returned Future object.
|
|
|
|
*
|
2019-03-07 07:30:45 +03:00
|
|
|
* The returned future will complete until the EdenServer is running
|
|
|
|
* successfully and accepting thrift connections.
|
|
|
|
*
|
|
|
|
* If waitForMountCompletion is true the returned future will also not
|
|
|
|
* become ready until all configured mount points have been remounted.
|
2018-06-26 22:05:27 +03:00
|
|
|
* If an error occurs remounting some mount points the Future will complete
|
|
|
|
* with an exception, but the server will still continue to run. Everything
|
|
|
|
* will be running normally except for the mount points that failed to be
|
|
|
|
* remounted.
|
|
|
|
*/
|
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> prepare(
|
2019-03-07 07:30:45 +03:00
|
|
|
std::shared_ptr<StartupLogger> logger,
|
|
|
|
bool waitForMountCompletion = true);
|
2018-06-26 22:05:27 +03:00
|
|
|
|
|
|
|
/**
|
2019-03-16 04:10:28 +03:00
|
|
|
* Shut down the EdenServer after it has stopped running.
|
2018-06-12 03:54:24 +03:00
|
|
|
*
|
2019-03-16 04:10:28 +03:00
|
|
|
* This should be called after the EdenServer's thrift server has returned
|
|
|
|
* from its serve loop.
|
|
|
|
*
|
|
|
|
* If a graceful restart has been triggered performCleanup() will stop
|
|
|
|
* processing new FUSE requests and transfer state to the new process.
|
|
|
|
* Otherwise performCleanup() will unmount and shutdown all currently running
|
|
|
|
* mounts.
|
2017-03-21 22:57:07 +03:00
|
|
|
*/
|
2019-03-16 04:10:28 +03:00
|
|
|
void performCleanup();
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2016-06-11 00:15:26 +03:00
|
|
|
/**
|
|
|
|
* Stops this server, which includes the underlying Thrift server.
|
2017-03-21 22:57:07 +03:00
|
|
|
*
|
|
|
|
* This may be called from any thread while a call to run() is outstanding,
|
|
|
|
* and will cause run() to return.
|
2016-06-11 00:15:26 +03:00
|
|
|
*/
|
2018-07-17 01:59:23 +03:00
|
|
|
void stop();
|
2016-06-11 00:15:26 +03:00
|
|
|
|
2017-11-20 02:18:29 +03:00
|
|
|
/**
|
|
|
|
* Request to shutdown the server for a graceful restart operation,
|
|
|
|
* allowing a remote process to take over the existing mount points.
|
|
|
|
*
|
|
|
|
* This pauses FUSE I/O processing, writes filesystem state to disk,
|
|
|
|
* and returns the FUSE file descriptors for each mount. This allows the
|
|
|
|
* FUSE FDs to be handed off to a new eden instance so it can take over
|
|
|
|
* existing mount points with minimal disruption to other processes using the
|
|
|
|
* mounts.
|
|
|
|
*
|
|
|
|
* Returns a Future that will return a map of (mount path -> FUSE fd)
|
|
|
|
*/
|
|
|
|
folly::Future<TakeoverData> startTakeoverShutdown() override;
|
|
|
|
|
2017-03-21 22:57:07 +03:00
|
|
|
/**
|
2017-09-13 18:26:53 +03:00
|
|
|
* Mount and return an EdenMount.
|
2017-03-21 22:57:07 +03:00
|
|
|
*/
|
2017-09-13 18:26:53 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<std::shared_ptr<EdenMount>> mount(
|
2019-05-08 03:36:45 +03:00
|
|
|
std::unique_ptr<CheckoutConfig> initialConfig,
|
2018-10-24 04:48:38 +03:00
|
|
|
std::optional<TakeoverData::MountInfo>&& optionalTakeover = std::nullopt);
|
2016-05-24 07:32:12 +03:00
|
|
|
|
2018-01-10 09:00:58 +03:00
|
|
|
/**
|
|
|
|
* Takeover a mount from another eden instance
|
|
|
|
*/
|
|
|
|
FOLLY_NODISCARD folly::Future<std::shared_ptr<EdenMount>> takeoverMount(
|
|
|
|
TakeoverData::MountInfo&& takeover);
|
|
|
|
|
2017-03-21 22:57:07 +03:00
|
|
|
/**
|
|
|
|
* Unmount an EdenMount.
|
|
|
|
*/
|
2017-08-01 06:48:19 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> unmount(
|
|
|
|
folly::StringPiece mountPath);
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2017-03-21 22:57:07 +03:00
|
|
|
/**
|
|
|
|
* Unmount all mount points maintained by this server, and wait for them to
|
|
|
|
* be completely unmounted.
|
|
|
|
*/
|
2018-04-05 05:40:22 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> unmountAll();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop all mount points maintained by this server so that they can then be
|
|
|
|
* transferred to a new edenfs process to perform a graceful restart.
|
|
|
|
*/
|
|
|
|
FOLLY_NODISCARD folly::Future<TakeoverData> stopMountsForTakeover();
|
2018-01-10 09:00:50 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
const std::shared_ptr<EdenServiceHandler>& getHandler() const {
|
|
|
|
return handler_;
|
|
|
|
}
|
|
|
|
const std::shared_ptr<apache::thrift::ThriftServer>& getServer() const {
|
|
|
|
return server_;
|
|
|
|
}
|
|
|
|
|
2019-03-07 07:30:45 +03:00
|
|
|
/**
|
|
|
|
* Get the list of mount points.
|
|
|
|
*
|
|
|
|
* The returned list excludes mount points that are still in the process of
|
|
|
|
* initializing. This is the behavior desired by most callers, as no access
|
|
|
|
* to inode information is allowed yet on initializing mount points.
|
|
|
|
*
|
|
|
|
* Mount points in the returned list may be in the process of shutting down.
|
|
|
|
* (Even if we attempted to return only running mount points, they may
|
|
|
|
* transition to shutting down before the caller can access them.)
|
|
|
|
*/
|
2016-05-20 20:33:42 +03:00
|
|
|
MountList getMountPoints() const;
|
2017-04-04 01:47:52 +03:00
|
|
|
|
2019-03-07 07:30:45 +03:00
|
|
|
/**
|
|
|
|
* Get all mount points, including mounts that are currently initializing.
|
|
|
|
*/
|
|
|
|
MountList getAllMountPoints() const;
|
|
|
|
|
2017-04-04 01:47:52 +03:00
|
|
|
/**
|
|
|
|
* Look up an EdenMount by the path where it is mounted.
|
|
|
|
*
|
2019-03-07 07:30:45 +03:00
|
|
|
* Throws an EdenError if no mount exists with the specified path, or if the
|
|
|
|
* mount is still initializing and is not ready for inode operations yet.
|
2017-04-04 01:47:52 +03:00
|
|
|
*/
|
2016-05-20 20:33:42 +03:00
|
|
|
std::shared_ptr<EdenMount> getMount(folly::StringPiece mountPath) const;
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2017-04-04 01:47:52 +03:00
|
|
|
/**
|
|
|
|
* Look up an EdenMount by the path where it is mounted.
|
|
|
|
*
|
2019-03-07 07:30:45 +03:00
|
|
|
* This is similar to getMount(), but will also return mounts that are still
|
|
|
|
* initializing. It is the caller's responsibility to ensure they do not
|
|
|
|
* perform any inode operations on the returned mount without first verifying
|
|
|
|
* it is ready for access.
|
2017-04-04 01:47:52 +03:00
|
|
|
*/
|
2019-03-07 07:30:45 +03:00
|
|
|
std::shared_ptr<EdenMount> getMountUnsafe(folly::StringPiece mountPath) const;
|
2017-04-04 01:47:52 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
std::shared_ptr<LocalStore> getLocalStore() const {
|
|
|
|
return localStore_;
|
|
|
|
}
|
|
|
|
|
2018-12-07 06:25:38 +03:00
|
|
|
const std::shared_ptr<BlobCache>& getBlobCache() const {
|
|
|
|
return blobCache_;
|
|
|
|
}
|
|
|
|
|
2016-06-14 01:15:31 +03:00
|
|
|
/**
|
|
|
|
* Look up the BackingStore object for the specified repository type+name.
|
|
|
|
*
|
|
|
|
* EdenServer maintains an internal cache of all known BackingStores,
|
|
|
|
* so that multiple mount points that use the same repository can
|
|
|
|
* share the same BackingStore object.
|
|
|
|
*
|
|
|
|
* If this is the first time this given (type, name) has been used, a new
|
|
|
|
* BackingStore object will be created and returned. Otherwise this will
|
|
|
|
* return the existing BackingStore that was previously created.
|
|
|
|
*/
|
|
|
|
std::shared_ptr<BackingStore> getBackingStore(
|
|
|
|
folly::StringPiece type,
|
|
|
|
folly::StringPiece name);
|
|
|
|
|
2019-04-17 07:14:33 +03:00
|
|
|
AbsolutePathPiece getEdenDir() const {
|
|
|
|
return edenDir_.getPath();
|
2016-11-26 23:00:16 +03:00
|
|
|
}
|
|
|
|
|
2019-09-19 23:34:24 +03:00
|
|
|
const std::shared_ptr<ServerState>& getServerState() const {
|
2018-04-23 23:10:31 +03:00
|
|
|
return serverState_;
|
2018-02-09 03:33:32 +03:00
|
|
|
}
|
2019-04-11 05:55:31 +03:00
|
|
|
|
2019-10-24 22:46:59 +03:00
|
|
|
const std::string& getVersion() const {
|
|
|
|
return version_;
|
|
|
|
}
|
|
|
|
|
2019-04-15 06:42:26 +03:00
|
|
|
std::shared_ptr<EdenStats> getSharedStats() {
|
|
|
|
return std::shared_ptr<EdenStats>(serverState_, getStats());
|
2019-04-11 05:55:31 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 06:42:26 +03:00
|
|
|
EdenStats* getStats() {
|
2018-04-23 23:10:31 +03:00
|
|
|
return &serverState_->getStats();
|
2017-03-31 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
2017-08-18 21:43:57 +03:00
|
|
|
/**
|
|
|
|
* Flush all thread-local stats to the main ServiceData object.
|
|
|
|
*
|
|
|
|
* Thread-local counters are normally flushed to the main ServiceData once
|
|
|
|
* a second. flushStatsNow() can be used to flush thread-local counters on
|
|
|
|
* demand, in addition to the normal once-a-second flush.
|
|
|
|
*
|
|
|
|
* This is mainly useful for unit and integration tests that want to ensure
|
|
|
|
* they see up-to-date counter information without waiting for the normal
|
|
|
|
* flush interval.
|
|
|
|
*/
|
2018-02-09 03:33:32 +03:00
|
|
|
void flushStatsNow();
|
2017-08-18 21:43:57 +03:00
|
|
|
|
2019-06-15 04:10:35 +03:00
|
|
|
/**
|
|
|
|
* Reload the configuration files from disk.
|
|
|
|
*
|
|
|
|
* The configuration files are automatically reloaded from disk periodically
|
|
|
|
* (controlled by the "config:reload-interval" setting in the config file).
|
|
|
|
*
|
|
|
|
* This method can be invoked to immediately force a config reload,
|
|
|
|
* independently of the configured interval.
|
|
|
|
*/
|
|
|
|
void reloadConfig();
|
|
|
|
|
2017-09-01 04:58:48 +03:00
|
|
|
/**
|
|
|
|
* Get the main thread's EventBase.
|
|
|
|
*
|
|
|
|
* Callers can use this for scheduling work to be run in the main thread.
|
|
|
|
*/
|
|
|
|
folly::EventBase* getMainEventBase() const {
|
|
|
|
return mainEventBase_;
|
|
|
|
}
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
private:
|
2017-08-01 06:48:19 +03:00
|
|
|
// Struct to store EdenMount along with SharedPromise that is set
|
2017-12-12 05:01:15 +03:00
|
|
|
// during unmount to allow synchronization between unmountFinished
|
2017-08-01 06:48:19 +03:00
|
|
|
// and unmount functions.
|
|
|
|
struct EdenMountInfo {
|
|
|
|
std::shared_ptr<EdenMount> edenMount;
|
|
|
|
folly::SharedPromise<folly::Unit> unmountPromise;
|
2018-10-24 04:48:38 +03:00
|
|
|
std::optional<folly::Promise<TakeoverData::MountInfo>> takeoverPromise;
|
2017-08-01 06:48:19 +03:00
|
|
|
|
|
|
|
explicit EdenMountInfo(const std::shared_ptr<EdenMount>& mount)
|
|
|
|
: edenMount(mount),
|
|
|
|
unmountPromise(folly::SharedPromise<folly::Unit>()) {}
|
|
|
|
};
|
|
|
|
|
2019-05-31 01:08:02 +03:00
|
|
|
template <void (EdenServer::*MemberFn)()>
|
|
|
|
class PeriodicFnTask : public PeriodicTask {
|
|
|
|
public:
|
|
|
|
using PeriodicTask::PeriodicTask;
|
|
|
|
void runTask() override {
|
|
|
|
(getServer()->*MemberFn)();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-14 01:15:31 +03:00
|
|
|
using BackingStoreKey = std::pair<std::string, std::string>;
|
|
|
|
using BackingStoreMap =
|
|
|
|
std::unordered_map<BackingStoreKey, std::shared_ptr<BackingStore>>;
|
2017-08-01 06:48:19 +03:00
|
|
|
using MountMap = folly::StringKeyedMap<struct EdenMountInfo>;
|
2017-06-27 05:27:34 +03:00
|
|
|
class ThriftServerEventHandler;
|
2016-06-14 01:15:31 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
// Forbidden copy constructor and assignment operator
|
|
|
|
EdenServer(EdenServer const&) = delete;
|
|
|
|
EdenServer& operator=(EdenServer const&) = delete;
|
|
|
|
|
2019-05-31 01:08:02 +03:00
|
|
|
void startPeriodicTasks();
|
2019-06-15 04:10:35 +03:00
|
|
|
void updatePeriodicTaskIntervals(const EdenConfig& config);
|
2017-09-13 18:26:50 +03:00
|
|
|
|
2019-01-22 21:44:24 +03:00
|
|
|
/**
|
|
|
|
* Schedule a call to unloadInodes() to happen after timeout
|
|
|
|
* has expired.
|
|
|
|
* Must be called only from the eventBase thread.
|
|
|
|
*/
|
2017-09-13 18:26:50 +03:00
|
|
|
void scheduleInodeUnload(std::chrono::milliseconds timeout);
|
|
|
|
|
|
|
|
// Perform unloading of inodes based on their last access time
|
|
|
|
// and then schedule another call to unloadInodes() to happen
|
|
|
|
// at the next appropriate interval. The unload attempt applies to
|
|
|
|
// all mounts.
|
|
|
|
void unloadInodes();
|
|
|
|
|
2016-06-14 01:15:31 +03:00
|
|
|
std::shared_ptr<BackingStore> createBackingStore(
|
|
|
|
folly::StringPiece type,
|
|
|
|
folly::StringPiece name);
|
2018-06-26 22:05:27 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> createThriftServer();
|
2017-11-20 22:34:37 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
void prepareThriftAddress();
|
|
|
|
|
2018-06-26 22:05:27 +03:00
|
|
|
/**
|
|
|
|
* prepareImpl() contains the bulk of the implementation of prepare()
|
|
|
|
*/
|
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> prepareImpl(
|
2019-03-07 07:30:45 +03:00
|
|
|
std::shared_ptr<StartupLogger> logger,
|
|
|
|
bool waitForMountCompletion);
|
|
|
|
FOLLY_NODISCARD std::vector<folly::Future<folly::Unit>> prepareMountsTakeover(
|
|
|
|
std::shared_ptr<StartupLogger> logger,
|
|
|
|
std::vector<TakeoverData::MountInfo>&& takeoverMounts);
|
|
|
|
FOLLY_NODISCARD std::vector<folly::Future<folly::Unit>> prepareMounts(
|
2018-06-26 22:05:27 +03:00
|
|
|
std::shared_ptr<StartupLogger> logger);
|
|
|
|
|
2019-08-29 03:11:37 +03:00
|
|
|
/**
|
|
|
|
* Create config file if this the first time running the server, otherwise
|
|
|
|
* parse existing config file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
std::shared_ptr<cpptoml::table> parseConfig();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create default config toml table
|
|
|
|
*/
|
|
|
|
std::shared_ptr<cpptoml::table> getDefaultConfig();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open local storage engine for caching source control data.
|
|
|
|
*/
|
|
|
|
void openStorageEngine(
|
|
|
|
std::shared_ptr<cpptoml::table>,
|
|
|
|
std::shared_ptr<StartupLogger> logger);
|
|
|
|
|
2016-05-20 20:33:42 +03:00
|
|
|
// Called when a mount has been unmounted and has stopped.
|
2018-01-10 09:00:50 +03:00
|
|
|
void mountFinished(
|
|
|
|
EdenMount* mountPoint,
|
2018-10-24 04:48:38 +03:00
|
|
|
std::optional<TakeoverData::MountInfo> takeover);
|
2016-05-12 23:43:17 +03:00
|
|
|
|
2018-01-11 00:01:19 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> performNormalShutdown();
|
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> performTakeoverShutdown(
|
|
|
|
folly::File thriftSocket);
|
2017-11-20 02:18:29 +03:00
|
|
|
void shutdownPrivhelper();
|
2017-08-01 06:49:35 +03:00
|
|
|
|
2018-01-11 00:01:19 +03:00
|
|
|
// Starts up a new fuse mount for edenMount, starting up the thread
|
|
|
|
// pool and initializing the fuse session
|
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> performFreshFuseStart(
|
|
|
|
std::shared_ptr<EdenMount> edenMount);
|
|
|
|
|
|
|
|
// Performs a takeover initialization for the provided fuse mount,
|
|
|
|
// loading the state from the old incarnation and starting up the
|
|
|
|
// thread pool.
|
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> performTakeoverFuseStart(
|
|
|
|
std::shared_ptr<EdenMount> edenMount,
|
|
|
|
TakeoverData::MountInfo&& takeover);
|
2018-06-12 03:54:24 +03:00
|
|
|
FOLLY_NODISCARD folly::Future<folly::Unit> completeTakeoverFuseStart(
|
|
|
|
std::shared_ptr<EdenMount> edenMount,
|
|
|
|
TakeoverData::MountInfo&& takeover);
|
2018-01-11 00:01:19 +03:00
|
|
|
|
2017-09-13 18:26:53 +03:00
|
|
|
// Add the mount point to mountPoints_.
|
|
|
|
// This also makes sure we don't have this path mounted already.
|
|
|
|
void addToMountPoints(std::shared_ptr<EdenMount> edenMount);
|
|
|
|
|
|
|
|
// Registers (or removes) stats callbacks for edenMount.
|
|
|
|
// These are here rather than in EdenMount because we need to
|
|
|
|
// hold an owning reference to the mount to safely sample stats.
|
|
|
|
void registerStats(std::shared_ptr<EdenMount> edenMount);
|
|
|
|
void unregisterStats(EdenMount* edenMount);
|
|
|
|
|
2019-05-31 01:08:02 +03:00
|
|
|
// Report memory usage statistics to ServiceData.
|
|
|
|
void reportMemoryStats();
|
|
|
|
|
2019-06-21 06:53:39 +03:00
|
|
|
// Compute stats for the local store and perform garbage collection if
|
|
|
|
// necessary
|
|
|
|
void manageLocalStore();
|
|
|
|
|
2020-01-18 01:57:31 +03:00
|
|
|
// some backing store may require periodic maintenance, specifically rust
|
|
|
|
// datapack store needs to release file descriptor it holds every once in a
|
|
|
|
// while.
|
|
|
|
void refreshBackingStore();
|
|
|
|
|
2018-01-11 00:01:22 +03:00
|
|
|
// Cancel all subscribers on all mounts so that we can tear
|
|
|
|
// down the thrift server without blocking
|
2018-07-17 01:59:23 +03:00
|
|
|
void shutdownSubscribers();
|
2018-01-11 00:01:22 +03:00
|
|
|
|
2020-03-06 20:25:21 +03:00
|
|
|
/**
|
|
|
|
* Look up all BackingStores which are HgBackingStore
|
|
|
|
*
|
|
|
|
* EdenServer maintains an internal cache of all known BackingStores,
|
|
|
|
* so that multiple mount points that use the same repository can
|
|
|
|
* share the same BackingStore object.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
std::unordered_set<std::shared_ptr<HgBackingStore>> getHgBackingStores();
|
|
|
|
|
2016-06-20 21:43:45 +03:00
|
|
|
/*
|
|
|
|
* Member variables.
|
|
|
|
*
|
|
|
|
* Note that the declaration order below is important for initialization
|
2019-04-17 07:14:33 +03:00
|
|
|
* and cleanup order. edenDir_ is near the top so it will be destroyed last,
|
|
|
|
* as it holds the process-wide lock for our on-disk state.
|
2016-06-20 21:43:45 +03:00
|
|
|
* mountPoints_ are near the bottom, so they get destroyed before the
|
|
|
|
* backingStores_ and localStore_.
|
|
|
|
*/
|
|
|
|
|
2019-07-17 23:43:32 +03:00
|
|
|
const std::vector<std::string> originalCommandLine_;
|
2019-04-17 07:14:33 +03:00
|
|
|
EdenStateDir edenDir_;
|
2016-05-12 23:43:17 +03:00
|
|
|
std::shared_ptr<EdenServiceHandler> handler_;
|
|
|
|
std::shared_ptr<apache::thrift::ThriftServer> server_;
|
2017-06-27 05:27:34 +03:00
|
|
|
std::shared_ptr<ThriftServerEventHandler> serverEventHandler_;
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
std::shared_ptr<LocalStore> localStore_;
|
2016-06-14 01:15:31 +03:00
|
|
|
folly::Synchronized<BackingStoreMap> backingStores_;
|
2018-11-26 22:08:10 +03:00
|
|
|
const std::shared_ptr<BlobCache> blobCache_;
|
2016-07-01 07:00:01 +03:00
|
|
|
|
2017-08-03 03:40:57 +03:00
|
|
|
folly::Synchronized<MountMap> mountPoints_;
|
2017-08-01 06:49:35 +03:00
|
|
|
|
2019-05-10 02:28:23 +03:00
|
|
|
#ifndef _WIN32
|
2017-11-20 02:18:29 +03:00
|
|
|
/**
|
|
|
|
* A server that waits on a new edenfs process to attempt
|
|
|
|
* a graceful restart, taking over our running mount points.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<TakeoverServer> takeoverServer_;
|
|
|
|
folly::Promise<TakeoverData> takeoverPromise_;
|
|
|
|
|
2019-05-10 02:28:23 +03:00
|
|
|
#endif // !_WIN32
|
2018-10-21 03:33:33 +03:00
|
|
|
|
2018-02-09 06:32:01 +03:00
|
|
|
/**
|
|
|
|
* Information about whether the EdenServer is starting, running, or shutting
|
|
|
|
* down, including whether it is performing a graceful restart.
|
|
|
|
*/
|
|
|
|
struct RunStateData {
|
|
|
|
RunState state{RunState::STARTING};
|
2017-11-20 02:18:29 +03:00
|
|
|
bool takeoverShutdown{false};
|
2017-11-20 02:18:31 +03:00
|
|
|
folly::File takeoverThriftSocket;
|
2017-11-20 02:18:29 +03:00
|
|
|
};
|
2018-02-09 06:32:01 +03:00
|
|
|
folly::Synchronized<RunStateData> runningState_;
|
2017-11-20 02:18:29 +03:00
|
|
|
|
2018-02-09 03:33:32 +03:00
|
|
|
/**
|
|
|
|
* Common state shared by all of the EdenMount objects.
|
|
|
|
*/
|
2018-11-26 22:08:10 +03:00
|
|
|
const std::shared_ptr<ServerState> serverState_;
|
2018-02-09 03:33:32 +03:00
|
|
|
|
2017-09-01 04:58:48 +03:00
|
|
|
/**
|
2019-10-24 22:46:59 +03:00
|
|
|
* Build package version
|
|
|
|
*/
|
|
|
|
const std::string version_;
|
|
|
|
|
|
|
|
/**
|
2017-09-01 04:58:48 +03:00
|
|
|
* The EventBase driving the main thread loop.
|
|
|
|
*
|
|
|
|
* This is used to drive the the thrift server and can also be used for
|
|
|
|
* scheduling other asynchronous operations.
|
|
|
|
*
|
|
|
|
* This is set when the EdenServer is started and is never updated after
|
|
|
|
* this, so we do not need synchronization when reading it.
|
|
|
|
*/
|
|
|
|
folly::EventBase* mainEventBase_;
|
2018-06-20 18:56:26 +03:00
|
|
|
|
2019-06-15 04:10:35 +03:00
|
|
|
PeriodicFnTask<&EdenServer::reloadConfig> reloadConfigTask_{this,
|
|
|
|
"reload_config"};
|
2019-05-31 01:08:02 +03:00
|
|
|
PeriodicFnTask<&EdenServer::flushStatsNow> flushStatsTask_{this,
|
|
|
|
"flush_stats"};
|
2019-06-22 03:01:36 +03:00
|
|
|
#ifndef _WIN32
|
2019-05-31 01:08:02 +03:00
|
|
|
PeriodicFnTask<&EdenServer::reportMemoryStats> memoryStatsTask_{this,
|
|
|
|
"mem_stats"};
|
2019-06-22 03:01:36 +03:00
|
|
|
#endif
|
2019-06-21 06:53:39 +03:00
|
|
|
PeriodicFnTask<&EdenServer::manageLocalStore> localStoreTask_{this,
|
|
|
|
"local_store"};
|
2020-01-18 01:57:31 +03:00
|
|
|
|
|
|
|
PeriodicFnTask<&EdenServer::refreshBackingStore> backingStoreTask_{
|
|
|
|
this,
|
|
|
|
"backing_store"};
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|