snap v2: fdbclient related changes

This commit is contained in:
sramamoorthy 2019-06-19 11:11:22 -07:00 committed by Alex Miller
parent 83f4b8ebb1
commit 209448807d
5 changed files with 93 additions and 7 deletions

View File

@ -2170,7 +2170,9 @@ ACTOR Future<bool> exclude( Database db, std::vector<StringRef> tokens, Referenc
}
ACTOR Future<bool> createSnapshot(Database db, StringRef snapCmd) {
wait(makeInterruptable(mgmtSnapCreate(db, snapCmd)));
// FIXME: default version for snapshots are still 1, once version 2 is stable - it will be made the default
// and version 1 may be deprecated
wait(makeInterruptable(mgmtSnapCreate(db, snapCmd, 1 /* version */)));
return false;
}

View File

@ -1482,14 +1482,18 @@ ACTOR Future<std::set<NetworkAddress>> checkForExcludingServers(Database cx, vec
return inProgressExclusion;
}
ACTOR Future<Void> mgmtSnapCreate(Database cx, StringRef snapCmd) {
ACTOR Future<Void> mgmtSnapCreate(Database cx, StringRef snapCmd, int version) {
state int retryCount = 0;
loop {
state UID snapUID = deterministicRandom()->randomUniqueID();
try {
wait(snapCreate(cx, snapCmd, snapUID));
printf("Snapshots tagged with UID: %s, check logs for status\n", snapUID.toString().c_str());
wait(snapCreate(cx, snapCmd, snapUID, version));
if (version == 1) {
printf("Snapshots tagged with UID: %s, check logs for status\n", snapUID.toString().c_str());
} else {
printf("Snapshots create succeeded with UID: %s\n", snapUID.toString().c_str());
}
TraceEvent("SnapCreateSucceeded").detail("snapUID", snapUID);
break;
} catch (Error& e) {

View File

@ -195,7 +195,7 @@ bool schemaMatch( json_spirit::mValue const& schema, json_spirit::mValue const&
// execute payload in 'snapCmd' on all the coordinators, TLogs and
// storage nodes
ACTOR Future<Void> mgmtSnapCreate(Database cx, StringRef snapCmd);
ACTOR Future<Void> mgmtSnapCreate(Database cx, StringRef snapCmd, int version);
#include "flow/unactorcompiler.h"
#endif

View File

@ -3439,7 +3439,7 @@ void enableClientInfoLogging() {
TraceEvent(SevInfo, "ClientInfoLoggingEnabled");
}
ACTOR Future<Void> snapCreate(Database inputCx, StringRef snapCmd, UID snapUID) {
ACTOR Future<Void> snapCreateVersion1(Database inputCx, StringRef snapCmd, UID snapUID) {
state Transaction tr(inputCx);
state DatabaseContext* cx = inputCx.getPtr();
// remember the client ID before the snap operation
@ -3537,3 +3537,83 @@ ACTOR Future<Void> snapCreate(Database inputCx, StringRef snapCmd, UID snapUID)
TraceEvent("SnapCreateComplete").detail("UID", snapUID);
return Void();
}
ACTOR Future<Void> snapshotDatabase(DatabaseContext* cx, StringRef snapPayload, UID snapUID, Optional<UID> debugID) {
TraceEvent("NativeAPI.SnapshotDatabaseEnter")
.detail("SnapPayload", snapPayload)
.detail("SnapUID", snapUID);
try {
if (debugID.present()) {
g_traceBatch.addEvent("TransactionDebug", debugID.get().first(), "NativeAPI.snapshotDatabase.Before");
}
state ProxySnapRequest req(snapPayload, snapUID, debugID);
wait(loadBalance(cx->getMasterProxies(false), &MasterProxyInterface::proxySnapReq, req, cx->taskID, true /*atmostOnce*/ ));
if (debugID.present())
g_traceBatch.addEvent("TransactionDebug", debugID.get().first(),
"NativeAPI.SnapshotDatabase.After");
} catch (Error& e) {
TraceEvent("NativeAPI.SnapshotDatabaseError")
.detail("SnapPayload", snapPayload)
.detail("SnapUID", snapUID)
.error(e, true /* includeCancelled */);
throw;
}
return Void();
}
ACTOR Future<Void> snapCreateVersion2(Database inputCx, StringRef snapCmd, UID snapUID) {
state DatabaseContext* cx = inputCx.getPtr();
// remember the client ID before the snap operation
state UID preSnapClientUID = cx->clientInfo->get().id;
TraceEvent("SnapCreateEnterVersion2")
.detail("SnapCmd", snapCmd.toString())
.detail("UID", snapUID)
.detail("PreSnapClientUID", preSnapClientUID);
StringRef snapCmdArgs = snapCmd;
StringRef snapCmdPart = snapCmdArgs.eat(":");
state Standalone<StringRef> snapUIDRef(snapUID.toString());
state Standalone<StringRef> snapPayloadRef = snapCmdPart
.withSuffix(LiteralStringRef(":uid="))
.withSuffix(snapUIDRef)
.withSuffix(LiteralStringRef(","))
.withSuffix(snapCmdArgs);
try {
Future<Void> exec = snapshotDatabase(cx, snapPayloadRef, snapUID, snapUID);
wait(timeoutError(exec, g_network->isSimulated() ? 80 : 600)); // dependent on SERVER_KNOBS->SNAP_CRATE_MAX_TIMEOUT
// FIXME: remove the timeoutError and hard-coded time limits
} catch (Error& e) {
TraceEvent("SnapshotDatabaseErrorVersion2")
.detail("SnapCmd", snapCmd.toString())
.detail("UID", snapUID)
.error(e);
throw;
}
UID postSnapClientUID = cx->clientInfo->get().id;
if (preSnapClientUID != postSnapClientUID) {
// if the client IDs changed then we fail the snapshot
TraceEvent("UIDMismatchVersion2")
.detail("SnapPreSnapClientUID", preSnapClientUID)
.detail("SnapPostSnapClientUID", postSnapClientUID);
throw coordinators_changed();
}
TraceEvent("SnapCreateExitVersion2")
.detail("SnapCmd", snapCmd.toString())
.detail("UID", snapUID)
.detail("PreSnapClientUID", preSnapClientUID);
return Void();
}
ACTOR Future<Void> snapCreate(Database inputCx, StringRef snapCmd, UID snapUID, int version) {
if (version == 1) {
wait(snapCreateVersion1(inputCx, snapCmd, snapUID));
return Void();
}
wait(snapCreateVersion2(inputCx, snapCmd, snapUID));
return Void();
}

View File

@ -344,7 +344,7 @@ int64_t extractIntOption( Optional<StringRef> value, int64_t minValue = std::num
// Takes a snapshot of the cluster, specifically the following persistent
// states: coordinator, TLog and storage state
ACTOR Future<Void> snapCreate(Database cx, StringRef snapCmd, UID snapUID);
ACTOR Future<Void> snapCreate(Database cx, StringRef snapCmd, UID snapUID, int version);
#include "flow/unactorcompiler.h"
#endif