sapling/eden/integration/helpers/TakeoverTool.cpp
Genevieve Helsel 9944a5dff5 add EdenServer recovery step and recover after failed takeover data send handshake
Summary:
* This adds a `EdenServer::recover()` method to start back up on unsuccessful takeover data send.
    * On an unsuccessful ping, filfill the `shutdownPromise` with a `TakeoverSendError` continaing the constructed `TakeoverData`. After this `recover` function is called, `takeoverPromise_` is reset, `takeoverShutdown` is set to `false`, and the `runningState_` is set to `RUNNING`.
With taking over from the returned `TakeoverData`, the user will not encounter `Transport not connected` errors on recovery.

* This adds a `EdenServer::closeStorage()` method to defer closing the `backingStore_` and `localStore_` until after our ready handshake is successful.
* This defers the shutdown of the `PrivHelper` until a successful ready handshake.

I also update the takeover documentation here with the new logic (and fix some formatting issues)

Reviewed By: simpkins

Differential Revision: D20433433

fbshipit-source-id: f59e660922674d281957e80aee5049735b901a2c
2020-04-07 09:52:21 -07:00

69 lines
2.1 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include <sysexits.h>
#include <folly/init/Init.h>
#include <folly/logging/Init.h>
#include <folly/logging/xlog.h>
#include <gflags/gflags.h>
#include "eden/fs/takeover/TakeoverClient.h"
#include "eden/fs/takeover/TakeoverData.h"
DEFINE_string(edenDir, "", "The path to the .eden directory");
/**
* Versions 3 and 4 are the only valid versions to send here. Even if
* a different version is specified, we still log version 3/4 message
* contents.
*/
DEFINE_int32(takeoverVersion, 0, "The takeover version number to send");
DEFINE_bool(
shouldPing,
true,
"This is used by integration tests to avoid sending a ping");
FOLLY_INIT_LOGGING_CONFIG("eden=DBG2");
using namespace facebook::eden::path_literals;
/*
* This is a small tool for manually exercising the edenfs takover code.
*
* This connects to an existing edenfs daemon and requests to take over its
* mount points. It prints out the mount points received and then exits.
* Note that it does not unmount them before exiting, so the mount points will
* need to be manually unmounted afterwards.
*/
int main(int argc, char* argv[]) {
folly::init(&argc, &argv);
if (FLAGS_edenDir.empty()) {
fprintf(stderr, "error: the --edenDir argument is required\n");
return EX_USAGE;
}
auto edenDir = facebook::eden::canonicalPath(FLAGS_edenDir);
auto takeoverSocketPath = edenDir + "takeover"_pc;
facebook::eden::TakeoverData data;
if (FLAGS_takeoverVersion == 0) {
data = facebook::eden::takeoverMounts(takeoverSocketPath, FLAGS_shouldPing);
} else {
auto takeoverVersion = std::set<int32_t>{FLAGS_takeoverVersion};
data = facebook::eden::takeoverMounts(
takeoverSocketPath, FLAGS_shouldPing, takeoverVersion);
}
for (const auto& mount : data.mountPoints) {
XLOG(INFO) << "mount " << mount.mountPath << ": fd=" << mount.fuseFD.fd();
for (const auto& bindMount : mount.bindMounts) {
XLOG(INFO) << " bind mount " << bindMount;
}
}
return EX_OK;
}