2019-06-21 05:28:31 +08:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__INTEL_COMPILER)
|
2019-06-14 06:26:46 +08:00
|
|
|
#define BOOST_SYSTEM_NO_LIB
|
|
|
|
#define BOOST_DATE_TIME_NO_LIB
|
|
|
|
#define BOOST_REGEX_NO_LIB
|
|
|
|
#include <boost/process.hpp>
|
|
|
|
#endif
|
2019-04-21 03:58:24 +08:00
|
|
|
#include "fdbserver/FDBExecHelper.actor.h"
|
|
|
|
#include "flow/Trace.h"
|
|
|
|
#include "flow/flow.h"
|
2020-05-23 00:25:32 +08:00
|
|
|
#include "fdbclient/versions.h"
|
2019-07-16 02:33:40 +08:00
|
|
|
#include "fdbserver/Knobs.h"
|
2019-04-21 03:58:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
ExecCmdValueString::ExecCmdValueString(StringRef pCmdValueString) {
|
|
|
|
cmdValueString = pCmdValueString;
|
|
|
|
parseCmdValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecCmdValueString::setCmdValueString(StringRef pCmdValueString) {
|
|
|
|
// reset everything
|
|
|
|
binaryPath = StringRef();
|
|
|
|
|
|
|
|
// set the new cmdValueString
|
|
|
|
cmdValueString = pCmdValueString;
|
|
|
|
|
|
|
|
// parse it out
|
|
|
|
parseCmdValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ExecCmdValueString::getCmdValueString() {
|
|
|
|
return cmdValueString.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ExecCmdValueString::getBinaryPath() {
|
|
|
|
return binaryPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorRef<StringRef> ExecCmdValueString::getBinaryArgs() {
|
|
|
|
return binaryArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecCmdValueString::parseCmdValue() {
|
|
|
|
StringRef param = this->cmdValueString;
|
|
|
|
// get the binary path
|
2019-08-29 01:52:56 +08:00
|
|
|
this->binaryPath = param.eat(LiteralStringRef(" "));
|
2019-04-21 03:58:24 +08:00
|
|
|
|
|
|
|
// no arguments provided
|
|
|
|
if (param == StringRef()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract the arguments
|
|
|
|
while (param != StringRef()) {
|
2019-08-29 01:52:56 +08:00
|
|
|
StringRef token = param.eat(LiteralStringRef(" "));
|
2019-04-21 03:58:24 +08:00
|
|
|
this->binaryArgs.push_back(this->binaryArgs.arena(), token);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecCmdValueString::dbgPrint() {
|
|
|
|
auto te = TraceEvent("ExecCmdValueString");
|
|
|
|
|
|
|
|
te.detail("CmdValueString", cmdValueString.toString());
|
|
|
|
te.detail("BinaryPath", binaryPath.toString());
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (auto elem : binaryArgs) {
|
|
|
|
te.detail(format("Arg", ++i).c_str(), elem.toString());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-21 05:28:31 +08:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__) || defined(__INTEL_COMPILER)
|
2019-06-20 02:20:44 +08:00
|
|
|
ACTOR Future<int> spawnProcess(std::string binPath, std::vector<std::string> paramList, double maxWaitTime, bool isSync, double maxSimDelayTime)
|
2019-06-14 06:26:46 +08:00
|
|
|
{
|
|
|
|
wait(delay(0.0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2020-05-08 04:17:27 +08:00
|
|
|
|
|
|
|
pid_t fork_child(const std::string& path,
|
|
|
|
std::vector<char*>& paramList)
|
|
|
|
{
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (pid == 0) {
|
|
|
|
execv(const_cast<char*>(path.c_str()), ¶mList[0]);
|
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
return pid;
|
|
|
|
}
|
|
|
|
|
2020-05-08 04:14:51 +08:00
|
|
|
ACTOR Future<int> spawnProcess(std::string path, std::vector<std::string> args, double maxWaitTime, bool isSync, double maxSimDelayTime)
|
2019-04-21 03:58:24 +08:00
|
|
|
{
|
2020-05-08 04:17:27 +08:00
|
|
|
// for async calls in simulator, always delay by a deterministic amount of time and then
|
|
|
|
// do the call synchronously, otherwise the predictability of the simulator breaks
|
|
|
|
if (!isSync && g_network->isSimulated()) {
|
|
|
|
double snapDelay = std::max(maxSimDelayTime - 1, 0.0);
|
|
|
|
// add some randomness
|
|
|
|
snapDelay += deterministicRandom()->random01();
|
|
|
|
TraceEvent("SnapDelaySpawnProcess")
|
|
|
|
.detail("SnapDelay", snapDelay);
|
|
|
|
wait(delay(snapDelay));
|
|
|
|
}
|
|
|
|
|
2020-05-08 04:14:51 +08:00
|
|
|
std::vector<char*> paramList;
|
|
|
|
for (int i = 0; i < args.size(); i++) {
|
|
|
|
paramList.push_back(const_cast<char*>(args[i].c_str()));
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
2020-05-08 04:14:51 +08:00
|
|
|
paramList.push_back(nullptr);
|
2019-04-21 03:58:24 +08:00
|
|
|
|
2020-05-08 04:16:23 +08:00
|
|
|
state std::string allArgs;
|
2020-05-08 04:14:51 +08:00
|
|
|
for (int i = 0; i < args.size(); i++) {
|
2020-05-08 04:16:23 +08:00
|
|
|
allArgs += args[i];
|
2019-04-25 03:45:28 +08:00
|
|
|
}
|
|
|
|
|
2020-05-08 04:17:27 +08:00
|
|
|
state pid_t pid = fork_child(path, paramList);
|
2020-05-08 04:14:51 +08:00
|
|
|
if (pid == -1) {
|
2020-05-08 04:16:23 +08:00
|
|
|
TraceEvent(SevWarnAlways, "SpawnProcess: Command failed to spawn")
|
|
|
|
.detail("Cmd", path)
|
|
|
|
.detail("Args", allArgs);
|
2020-05-08 04:14:51 +08:00
|
|
|
return -1;
|
|
|
|
} else if (pid > 0) {
|
2020-05-08 04:17:27 +08:00
|
|
|
state int status = -1;
|
|
|
|
state double runTime = 0;
|
|
|
|
while (true) {
|
|
|
|
if (runTime > maxWaitTime) {
|
|
|
|
// timing out
|
|
|
|
TraceEvent(SevWarnAlways, "SpawnProcess : Command failed, timeout")
|
|
|
|
.detail("Cmd", path)
|
|
|
|
.detail("Args", allArgs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int err = waitpid(pid, &status, WNOHANG);
|
|
|
|
if (err < 0) {
|
|
|
|
TraceEvent(SevWarnAlways, "SpawnProcess : Command failed")
|
|
|
|
.detail("Cmd", path)
|
|
|
|
.detail("Args", allArgs)
|
|
|
|
.detail("Errno", WIFEXITED(status) ? WEXITSTATUS(status) : -1);
|
|
|
|
return -1;
|
|
|
|
} else if (err == 0) {
|
|
|
|
// child process has not completed yet
|
|
|
|
if (isSync || g_network->isSimulated()) {
|
|
|
|
// synchronously sleep
|
|
|
|
threadSleep(0.1);
|
|
|
|
} else {
|
|
|
|
// yield for other actors to run
|
|
|
|
wait(delay(0.1));
|
|
|
|
}
|
|
|
|
runTime += 0.1;
|
|
|
|
} else {
|
|
|
|
// child process completed
|
|
|
|
if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
|
|
|
|
TraceEvent(SevWarnAlways, "SpawnProcess : Command failed")
|
|
|
|
.detail("Cmd", path)
|
|
|
|
.detail("Args", allArgs)
|
|
|
|
.detail("Errno", WIFEXITED(status) ? WEXITSTATUS(status) : -1);
|
|
|
|
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
|
|
|
|
}
|
|
|
|
TraceEvent("SpawnProcess : Command status")
|
|
|
|
.detail("Cmd", path)
|
|
|
|
.detail("Args", allArgs)
|
|
|
|
.detail("Errno", WIFEXITED(status) ? WEXITSTATUS(status) : 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
2019-05-08 04:35:28 +08:00
|
|
|
}
|
2020-05-08 04:17:27 +08:00
|
|
|
return -1;
|
2019-05-08 04:35:28 +08:00
|
|
|
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
2019-06-14 06:26:46 +08:00
|
|
|
#endif
|
2019-04-21 03:58:24 +08:00
|
|
|
|
2019-08-29 01:52:56 +08:00
|
|
|
ACTOR Future<int> execHelper(ExecCmdValueString* execArg, UID snapUID, std::string folder, std::string role) {
|
2019-10-25 06:56:22 +08:00
|
|
|
state Standalone<StringRef> uidStr(snapUID.toString());
|
2019-04-21 03:58:24 +08:00
|
|
|
state int err = 0;
|
|
|
|
state Future<int> cmdErr;
|
2019-07-23 06:44:49 +08:00
|
|
|
state double maxWaitTime = SERVER_KNOBS->SNAP_CREATE_MAX_TIMEOUT;
|
2019-04-21 03:58:24 +08:00
|
|
|
if (!g_network->isSimulated()) {
|
|
|
|
// get bin path
|
|
|
|
auto snapBin = execArg->getBinaryPath();
|
|
|
|
std::vector<std::string> paramList;
|
2020-05-08 04:14:51 +08:00
|
|
|
paramList.push_back(snapBin.toString());
|
2019-04-21 03:58:24 +08:00
|
|
|
// get user passed arguments
|
|
|
|
auto listArgs = execArg->getBinaryArgs();
|
|
|
|
for (auto elem : listArgs) {
|
|
|
|
paramList.push_back(elem.toString());
|
|
|
|
}
|
|
|
|
// get additional arguments
|
2019-08-29 01:52:56 +08:00
|
|
|
paramList.push_back("--path");
|
|
|
|
paramList.push_back(folder);
|
2019-04-21 03:58:24 +08:00
|
|
|
const char* version = FDB_VT_VERSION;
|
2019-08-29 01:52:56 +08:00
|
|
|
paramList.push_back("--version");
|
|
|
|
paramList.push_back(version);
|
|
|
|
paramList.push_back("--role");
|
2019-04-21 03:58:24 +08:00
|
|
|
paramList.push_back(role);
|
2019-08-29 01:52:56 +08:00
|
|
|
paramList.push_back("--uid");
|
|
|
|
paramList.push_back(uidStr.toString());
|
2019-07-16 02:33:40 +08:00
|
|
|
cmdErr = spawnProcess(snapBin.toString(), paramList, maxWaitTime, false /*isSync*/, 0);
|
2019-04-21 03:58:24 +08:00
|
|
|
wait(success(cmdErr));
|
|
|
|
err = cmdErr.get();
|
|
|
|
} else {
|
|
|
|
// copy the files
|
2019-04-23 21:55:55 +08:00
|
|
|
state std::string folderFrom = folder + "/.";
|
|
|
|
state std::string folderTo = folder + "-snap-" + uidStr.toString();
|
2019-07-23 06:44:49 +08:00
|
|
|
double maxSimDelayTime = 10.0;
|
|
|
|
folderTo = folder + "-snap-" + uidStr.toString() + "-" + role;
|
2019-04-21 03:58:24 +08:00
|
|
|
std::vector<std::string> paramList;
|
|
|
|
std::string mkdirBin = "/bin/mkdir";
|
2020-05-08 04:14:51 +08:00
|
|
|
paramList.push_back(mkdirBin);
|
2019-04-21 03:58:24 +08:00
|
|
|
paramList.push_back(folderTo);
|
2019-07-16 02:33:40 +08:00
|
|
|
cmdErr = spawnProcess(mkdirBin, paramList, maxWaitTime, false /*isSync*/, maxSimDelayTime);
|
2019-04-21 03:58:24 +08:00
|
|
|
wait(success(cmdErr));
|
|
|
|
err = cmdErr.get();
|
|
|
|
if (err == 0) {
|
|
|
|
std::vector<std::string> paramList;
|
|
|
|
std::string cpBin = "/bin/cp";
|
2020-05-08 04:14:51 +08:00
|
|
|
paramList.push_back(cpBin);
|
2019-04-21 03:58:24 +08:00
|
|
|
paramList.push_back("-a");
|
|
|
|
paramList.push_back(folderFrom);
|
|
|
|
paramList.push_back(folderTo);
|
2019-07-16 02:33:40 +08:00
|
|
|
cmdErr = spawnProcess(cpBin, paramList, maxWaitTime, true /*isSync*/, 1.0);
|
2019-04-21 03:58:24 +08:00
|
|
|
wait(success(cmdErr));
|
|
|
|
err = cmdErr.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-06-20 02:20:44 +08:00
|
|
|
struct StorageVersionInfo {
|
|
|
|
Version version;
|
|
|
|
Version durableVersion;
|
|
|
|
};
|
2019-04-21 03:58:24 +08:00
|
|
|
|
2019-07-16 02:33:40 +08:00
|
|
|
// storage nodes get snapshotted through the worker interface which does not have context about version information,
|
|
|
|
// following info is gathered at worker level to facilitate printing of version info during storage snapshots.
|
2019-06-20 02:20:44 +08:00
|
|
|
typedef std::map<UID, StorageVersionInfo> UidStorageVersionInfo;
|
2019-04-21 03:58:24 +08:00
|
|
|
|
2019-06-20 02:20:44 +08:00
|
|
|
std::map<NetworkAddress, UidStorageVersionInfo> workerStorageVersionInfo;
|
2019-04-21 03:58:24 +08:00
|
|
|
|
2019-06-20 02:20:44 +08:00
|
|
|
void setDataVersion(UID uid, Version version) {
|
2019-04-21 03:58:24 +08:00
|
|
|
NetworkAddress addr = g_network->getLocalAddress();
|
2019-06-20 02:20:44 +08:00
|
|
|
workerStorageVersionInfo[addr][uid].version = version;
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
|
|
|
|
2019-06-20 02:20:44 +08:00
|
|
|
void setDataDurableVersion(UID uid, Version durableVersion) {
|
2019-04-21 03:58:24 +08:00
|
|
|
NetworkAddress addr = g_network->getLocalAddress();
|
2019-06-20 02:20:44 +08:00
|
|
|
workerStorageVersionInfo[addr][uid].durableVersion = durableVersion;
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
2019-06-20 02:20:44 +08:00
|
|
|
|
|
|
|
void printStorageVersionInfo() {
|
2019-04-21 03:58:24 +08:00
|
|
|
NetworkAddress addr = g_network->getLocalAddress();
|
2019-06-20 02:20:44 +08:00
|
|
|
for (auto itr = workerStorageVersionInfo[addr].begin(); itr != workerStorageVersionInfo[addr].end(); itr++) {
|
|
|
|
TraceEvent("StorageVersionInfo")
|
|
|
|
.detail("UID", itr->first)
|
|
|
|
.detail("Version", itr->second.version)
|
|
|
|
.detail("DurableVersion", itr->second.durableVersion);
|
2019-04-21 03:58:24 +08:00
|
|
|
}
|
|
|
|
}
|