1
0
mirror of https://github.com/apple/foundationdb.git synced 2025-05-22 23:19:02 +08:00
foundationdb/fdbcli/ConsistencyCheckCommand.actor.cpp
2021-04-23 02:04:16 -07:00

48 lines
1.7 KiB
C++

#include "fdbcli/fdbcli.h"
#include "fdbclient/FDBOptions.g.h"
#include "fdbclient/IClientApi.h"
#include "flow/Arena.h"
#include "flow/FastRef.h"
#include "flow/ThreadHelper.actor.h"
#include "flow/actorcompiler.h" // This must be the last #include.
using namespace fdb_cli;
ACTOR static Future<bool> consistencyCheckCommandActor(Reference<ITransaction> tr, std::vector<StringRef> tokens) {
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
if (tokens.size() == 1) {
Optional<Value> suspended = wait(safeThreadFutureToFuture(tr->get(consistencyCheckSpeicalKey)));
printf("ConsistencyCheck is %s\n", suspended.present() ? "off" : "on");
} else if (tokens.size() == 2 && tokencmp(tokens[1], "off")) {
tr->set(consistencyCheckSpeicalKey, Value());
wait(safeThreadFutureToFuture(tr->commit()));
} else if (tokens.size() == 2 && tokencmp(tokens[1], "on")) {
tr->clear(consistencyCheckSpeicalKey);
wait(safeThreadFutureToFuture(tr->commit()));
} else {
printUsage(tokens[0]);
return false;
}
return true;
}
namespace fdb_cli {
const KeyRef consistencyCheckSpeicalKey = LiteralStringRef("\xff\xff/management/consistency_check_suspended");
Future<bool> consistencyCheckCommand(Reference<ITransaction> tr, std::vector<StringRef> tokens) {
return consistencyCheckCommandActor(tr, tokens);
}
CommandFactory consistencyCheckFactory(
"consistencycheck",
CommandHelp(
"consistencycheck [on|off]",
"permits or prevents consistency checking",
"Calling this command with `on' permits consistency check processes to run and `off' will halt their checking. "
"Calling this command with no arguments will display if consistency checking is currently allowed.\n"));
} // namespace fdb_cli