2018-04-11 06:19:53 +08:00
|
|
|
/*
|
|
|
|
* BackupToDBUpgrade.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fdbrpc/simulator.h"
|
2019-02-18 07:19:05 +08:00
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/workloads/BulkSetup.actor.h"
|
2019-02-18 09:38:13 +08:00
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2018-04-11 06:19:53 +08:00
|
|
|
|
|
|
|
//A workload which test the correctness of upgrading DR from 5.1 to 5.2
|
|
|
|
struct BackupToDBUpgradeWorkload : TestWorkload {
|
|
|
|
double backupAfter, stopDifferentialAfter;
|
2018-04-27 08:24:40 +08:00
|
|
|
Key backupTag, restoreTag, backupPrefix, extraPrefix;
|
|
|
|
int backupRangesCount, backupRangeLengthMax;
|
2018-04-11 06:19:53 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges;
|
|
|
|
Database extraDB;
|
|
|
|
|
|
|
|
BackupToDBUpgradeWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
2019-05-11 05:01:52 +08:00
|
|
|
backupAfter = getOption(options, LiteralStringRef("backupAfter"), deterministicRandom()->random01() * 10.0);
|
2018-04-11 06:19:53 +08:00
|
|
|
backupPrefix = getOption(options, LiteralStringRef("backupPrefix"), StringRef());
|
|
|
|
backupRangeLengthMax = getOption(options, LiteralStringRef("backupRangeLengthMax"), 1);
|
|
|
|
stopDifferentialAfter = getOption(options, LiteralStringRef("stopDifferentialAfter"), 60.0);
|
|
|
|
backupTag = getOption(options, LiteralStringRef("backupTag"), BackupAgentBase::getDefaultTag());
|
2018-04-27 08:24:40 +08:00
|
|
|
restoreTag = getOption(options, LiteralStringRef("restoreTag"), LiteralStringRef("restore"));
|
2018-04-11 06:19:53 +08:00
|
|
|
backupRangesCount = getOption(options, LiteralStringRef("backupRangesCount"), 5);
|
2018-04-14 00:59:32 +08:00
|
|
|
extraPrefix = backupPrefix.withPrefix(LiteralStringRef("\xfe\xff\xfe"));
|
|
|
|
backupPrefix = backupPrefix.withPrefix(LiteralStringRef("\xfe\xff\xff"));
|
2018-04-11 06:19:53 +08:00
|
|
|
|
|
|
|
ASSERT(backupPrefix != StringRef());
|
|
|
|
|
|
|
|
KeyRef beginRange;
|
|
|
|
KeyRef endRange;
|
|
|
|
|
|
|
|
if(backupRangesCount <= 0) {
|
2018-04-14 00:59:32 +08:00
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), KeyRangeRef(normalKeys.begin, std::min(backupPrefix, extraPrefix)));
|
2018-04-11 06:19:53 +08:00
|
|
|
} else {
|
|
|
|
// Add backup ranges
|
|
|
|
for (int rangeLoop = 0; rangeLoop < backupRangesCount; rangeLoop++)
|
|
|
|
{
|
|
|
|
// Get a random range of a random sizes
|
2019-05-11 05:01:52 +08:00
|
|
|
beginRange = KeyRef(backupRanges.arena(), deterministicRandom()->randomAlphaNumeric(deterministicRandom()->randomInt(1, backupRangeLengthMax + 1)));
|
|
|
|
endRange = KeyRef(backupRanges.arena(), deterministicRandom()->randomAlphaNumeric(deterministicRandom()->randomInt(1, backupRangeLengthMax + 1)));
|
2018-04-11 06:19:53 +08:00
|
|
|
|
|
|
|
// Add the range to the array
|
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), (beginRange < endRange) ? KeyRangeRef(beginRange, endRange) : KeyRangeRef(endRange, beginRange));
|
|
|
|
|
|
|
|
// Track the added range
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_BackupRange").detail("RangeBegin", (beginRange < endRange) ? printable(beginRange) : printable(endRange))
|
|
|
|
.detail("RangeEnd", (beginRange < endRange) ? printable(endRange) : printable(beginRange));
|
2018-04-11 06:19:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<ClusterConnectionFile> extraFile(new ClusterConnectionFile(*g_simulator.extraDB));
|
2018-09-22 06:58:14 +08:00
|
|
|
extraDB = Database::createDatabase(extraFile, -1);
|
2018-04-11 06:19:53 +08:00
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_Start");
|
2018-04-11 06:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string description() {
|
|
|
|
return "BackupToDBUpgrade";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Future<Void> setup(Database const& cx) {
|
|
|
|
if (clientId != 0)
|
|
|
|
return Void();
|
|
|
|
return _setup(cx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Future<Void> start(Database const& cx) {
|
|
|
|
if (clientId != 0)
|
|
|
|
return Void();
|
|
|
|
return _start(cx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Future<bool> check(Database const& cx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getMetrics(vector<PerfMetric>& m) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> doBackup(BackupToDBUpgradeWorkload* self, DatabaseBackupAgent* backupAgent, Database cx, Key tag, Standalone<VectorRef<KeyRangeRef>> backupRanges) {
|
|
|
|
try {
|
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(self->extraDB));
|
|
|
|
loop{
|
|
|
|
try {
|
|
|
|
for (auto r : self->backupRanges) {
|
|
|
|
if (!r.empty()) {
|
|
|
|
auto targetRange = r.withPrefix(self->backupPrefix);
|
|
|
|
printf("Clearing %s in destination\n", printable(targetRange).c_str());
|
|
|
|
tr->addReadConflictRange(targetRange);
|
|
|
|
tr->clear(targetRange);
|
|
|
|
}
|
|
|
|
}
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent->submitBackup(tr, tag, backupRanges, false, self->backupPrefix, StringRef()));
|
|
|
|
wait(tr->commit());
|
2018-04-11 06:19:53 +08:00
|
|
|
break;
|
|
|
|
} catch (Error &e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->onError(e));
|
2018-04-11 06:19:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_DoBackupInDifferentialMode").detail("Tag", printable(tag));
|
2018-04-11 06:19:53 +08:00
|
|
|
} catch (Error &e) {
|
2018-08-02 05:30:57 +08:00
|
|
|
TraceEvent("DRU_DoBackupSubmitBackupError").error(e).detail("Tag", printable(tag));
|
2018-04-11 06:19:53 +08:00
|
|
|
if (e.code() != error_code_backup_unneeded && e.code() != error_code_backup_duplicate) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 08:07:17 +08:00
|
|
|
wait(success( backupAgent->waitBackup(self->extraDB, tag, false) ));
|
2018-04-11 06:19:53 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-07-02 10:49:24 +08:00
|
|
|
ACTOR static Future<Void> checkData(Database cx, UID logUid, UID destUid, Key tag, DatabaseBackupAgent* backupAgent) {
|
2018-04-27 08:24:40 +08:00
|
|
|
state Key backupAgentKey = uidPrefixKey(logRangesRange.begin, logUid);
|
|
|
|
state Key backupLogValuesKey = uidPrefixKey(backupLogKeys.begin, destUid);
|
|
|
|
state Key backupLatestVersionsPath = uidPrefixKey(backupLatestVersionsPrefix, destUid);
|
|
|
|
state Key backupLatestVersionsKey = uidPrefixKey(backupLatestVersionsPath, logUid);
|
|
|
|
state int displaySystemKeys = 0;
|
|
|
|
|
2018-04-28 04:54:34 +08:00
|
|
|
ASSERT(destUid.isValid());
|
|
|
|
|
2018-04-27 08:24:40 +08:00
|
|
|
// Ensure that there is no left over key within the backup subspace
|
|
|
|
loop {
|
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_CheckLeftoverkeys").detail("BackupTag", printable(tag));
|
2018-04-27 08:24:40 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
|
|
|
|
// Check the left over tasks
|
|
|
|
// We have to wait for the list to empty since an abort and get status
|
|
|
|
// can leave extra tasks in the queue
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_CheckLeftovertasks").detail("BackupTag", printable(tag));
|
2018-04-27 08:24:40 +08:00
|
|
|
state int64_t taskCount = wait( backupAgent->getTaskCount(tr) );
|
|
|
|
state int waitCycles = 0;
|
|
|
|
|
2019-02-18 10:46:59 +08:00
|
|
|
if ((taskCount) && false) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_EndingNonzeroTaskCount").detail("BackupTag", printable(tag)).detail("TaskCount", taskCount).detail("WaitCycles", waitCycles);
|
2018-04-27 08:24:40 +08:00
|
|
|
printf("EndingNonZeroTasks: %ld\n", (long) taskCount);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(TaskBucket::debugPrintRange(cx, LiteralStringRef("\xff"), StringRef()));
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
|
|
|
waitCycles ++;
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_NonzeroTaskWait").detail("BackupTag", printable(tag)).detail("TaskCount", taskCount).detail("WaitCycles", waitCycles);
|
2018-04-27 08:24:40 +08:00
|
|
|
printf("%.6f Wait #%4d for %lld tasks to end\n", now(), waitCycles, (long long) taskCount);
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(20.0));
|
2018-04-27 08:24:40 +08:00
|
|
|
tr->commit();
|
|
|
|
tr = Reference<ReadYourWritesTransaction>(new ReadYourWritesTransaction(cx));
|
|
|
|
int64_t _taskCount = wait( backupAgent->getTaskCount(tr) );
|
|
|
|
taskCount = _taskCount;
|
|
|
|
|
|
|
|
if (!taskCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskCount) {
|
|
|
|
displaySystemKeys ++;
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "DRU_NonzeroTaskCount").detail("BackupTag", printable(tag)).detail("TaskCount", taskCount).detail("WaitCycles", waitCycles);
|
|
|
|
printf("BackupCorrectnessLeftoverLogTasks: %ld\n", (long) taskCount);
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Standalone<RangeResultRef> agentValues = wait(tr->getRange(KeyRange(KeyRangeRef(backupAgentKey, strinc(backupAgentKey))), 100));
|
|
|
|
|
|
|
|
// Error if the system keyspace for the backup tag is not empty
|
|
|
|
if (agentValues.size() > 0) {
|
|
|
|
displaySystemKeys++;
|
2018-06-09 02:11:08 +08:00
|
|
|
printf("BackupCorrectnessLeftoverMutationKeys: (%d) %s\n", agentValues.size(), printable(backupAgentKey).c_str());
|
|
|
|
TraceEvent(SevError, "BackupCorrectnessLeftoverMutationKeys").detail("BackupTag", printable(tag))
|
|
|
|
.detail("LeftoverKeys", agentValues.size()).detail("KeySpace", printable(backupAgentKey));
|
2018-04-27 08:24:40 +08:00
|
|
|
for (auto & s : agentValues) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_LeftoverKey").detail("Key", printable(StringRef(s.key.toString()))).detail("Value", printable(StringRef(s.value.toString())));
|
2018-04-27 08:24:40 +08:00
|
|
|
printf(" Key: %-50s Value: %s\n", printable(StringRef(s.key.toString())).c_str(), printable(StringRef(s.value.toString())).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("No left over backup agent configuration keys\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<Value> latestVersion = wait(tr->get(backupLatestVersionsKey));
|
|
|
|
if (latestVersion.present()) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "BackupCorrectnessLeftoverVersionKey").detail("BackupTag", printable(tag)).detail("Key", backupLatestVersionsKey.printable()).detail("Value", BinaryReader::fromStringRef<Version>(latestVersion.get(), Unversioned()));
|
2018-04-27 08:24:40 +08:00
|
|
|
} else {
|
|
|
|
printf("No left over backup version key\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Standalone<RangeResultRef> versions = wait(tr->getRange(KeyRange(KeyRangeRef(backupLatestVersionsPath, strinc(backupLatestVersionsPath))), 1));
|
2018-07-02 10:49:24 +08:00
|
|
|
if (!versions.size()) {
|
2018-04-27 08:24:40 +08:00
|
|
|
Standalone<RangeResultRef> logValues = wait(tr->getRange(KeyRange(KeyRangeRef(backupLogValuesKey, strinc(backupLogValuesKey))), 100));
|
|
|
|
|
|
|
|
// Error if the log/mutation keyspace for the backup tag is not empty
|
|
|
|
if (logValues.size() > 0) {
|
|
|
|
displaySystemKeys++;
|
2018-06-09 02:11:08 +08:00
|
|
|
printf("BackupCorrectnessLeftoverLogKeys: (%d) %s\n", logValues.size(), printable(backupLogValuesKey).c_str());
|
|
|
|
TraceEvent(SevError, "BackupCorrectnessLeftoverLogKeys").detail("BackupTag", printable(tag))
|
|
|
|
.detail("LeftoverKeys", logValues.size()).detail("KeySpace", printable(backupLogValuesKey)).detail("Version", decodeBKMutationLogKey(logValues[0].key).first);
|
2018-04-27 08:24:40 +08:00
|
|
|
for (auto & s : logValues) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_LeftoverKey").detail("Key", printable(StringRef(s.key.toString()))).detail("Value", printable(StringRef(s.value.toString())));
|
2018-04-27 08:24:40 +08:00
|
|
|
printf(" Key: %-50s Value: %s\n", printable(StringRef(s.key.toString())).c_str(), printable(StringRef(s.value.toString())).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("No left over backup log keys\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch (Error &e) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_CheckError").error(e);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr->onError(e));
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displaySystemKeys) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(TaskBucket::debugPrintRange(cx, LiteralStringRef("\xff"), StringRef()));
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-04-11 06:19:53 +08:00
|
|
|
ACTOR static Future<Void> _setup(Database cx, BackupToDBUpgradeWorkload* self) {
|
|
|
|
state DatabaseBackupAgent backupAgent(cx);
|
|
|
|
|
|
|
|
try{
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(self->backupAfter));
|
2018-04-11 06:19:53 +08:00
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_DoBackup").detail("Tag", printable(self->backupTag));
|
2018-04-11 06:19:53 +08:00
|
|
|
state Future<Void> b = doBackup(self, &backupAgent, self->extraDB, self->backupTag, self->backupRanges);
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_DoBackupWait").detail("BackupTag", printable(self->backupTag));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(b);
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_DoBackupWaitEnd").detail("BackupTag", printable(self->backupTag));
|
2018-04-11 06:19:53 +08:00
|
|
|
}
|
|
|
|
catch (Error& e) {
|
2018-04-27 08:24:40 +08:00
|
|
|
TraceEvent(SevError, "BackupToDBUpgradeSetuEerror").error(e);
|
2018-04-11 06:19:53 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-05-10 06:11:05 +08:00
|
|
|
ACTOR static Future<Void> diffRanges(Standalone<VectorRef<KeyRangeRef>> ranges, StringRef backupPrefix, Database src, Database dest) {
|
|
|
|
state int rangeIndex;
|
|
|
|
for (rangeIndex = 0; rangeIndex < ranges.size(); ++rangeIndex) {
|
|
|
|
state KeyRangeRef range = ranges[rangeIndex];
|
|
|
|
state Key begin = range.begin;
|
|
|
|
if(range.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
loop {
|
|
|
|
state Transaction tr(src);
|
|
|
|
state Transaction tr2(dest);
|
|
|
|
try {
|
|
|
|
loop {
|
|
|
|
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
tr2.setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
state Future<Standalone<RangeResultRef>> srcFuture = tr.getRange(KeyRangeRef(begin, range.end), 1000);
|
|
|
|
state Future<Standalone<RangeResultRef>> bkpFuture = tr2.getRange(KeyRangeRef(begin, range.end).withPrefix(backupPrefix), 1000);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(success(srcFuture) && success(bkpFuture));
|
2018-05-10 06:11:05 +08:00
|
|
|
|
|
|
|
auto src = srcFuture.get().begin();
|
|
|
|
auto bkp = bkpFuture.get().begin();
|
|
|
|
|
|
|
|
while (src != srcFuture.get().end() && bkp != bkpFuture.get().end()) {
|
|
|
|
KeyRef bkpKey = bkp->key.substr(backupPrefix.size());
|
|
|
|
if (src->key != bkpKey && src->value != bkp->value) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MismatchKeyAndValue").detail("SrcKey", printable(src->key)).detail("SrcVal", printable(src->value)).detail("BkpKey", printable(bkpKey)).detail("BkpVal", printable(bkp->value));
|
2018-05-10 06:11:05 +08:00
|
|
|
}
|
|
|
|
else if (src->key != bkpKey) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MismatchKey").detail("SrcKey", printable(src->key)).detail("SrcVal", printable(src->value)).detail("BkpKey", printable(bkpKey)).detail("BkpVal", printable(bkp->value));
|
2018-05-10 06:11:05 +08:00
|
|
|
}
|
|
|
|
else if (src->value != bkp->value) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MismatchValue").detail("SrcKey", printable(src->key)).detail("SrcVal", printable(src->value)).detail("BkpKey", printable(bkpKey)).detail("BkpVal", printable(bkp->value));
|
2018-05-10 06:11:05 +08:00
|
|
|
}
|
|
|
|
begin = std::min(src->key, bkpKey);
|
|
|
|
if (src->key == bkpKey) {
|
|
|
|
++src;
|
|
|
|
++bkp;
|
|
|
|
}
|
|
|
|
else if (src->key < bkpKey) {
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++bkp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (src != srcFuture.get().end() && !bkpFuture.get().more) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MissingBkpKey").detail("SrcKey", printable(src->key)).detail("SrcVal", printable(src->value));
|
2018-05-10 06:11:05 +08:00
|
|
|
begin = src->key;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
while (bkp != bkpFuture.get().end() && !srcFuture.get().more) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevError, "MissingSrcKey").detail("BkpKey", printable(bkp->key.substr(backupPrefix.size()))).detail("BkpVal", printable(bkp->value));
|
2018-05-10 06:11:05 +08:00
|
|
|
begin = bkp->key;
|
|
|
|
++bkp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srcFuture.get().more && !bkpFuture.get().more) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
begin = keyAfter(begin);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch (Error &e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2018-05-10 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-04-11 06:19:53 +08:00
|
|
|
ACTOR static Future<Void> _start(Database cx, BackupToDBUpgradeWorkload* self) {
|
2018-04-27 08:24:40 +08:00
|
|
|
state DatabaseBackupAgent backupAgent(cx);
|
|
|
|
state DatabaseBackupAgent restoreAgent(self->extraDB);
|
|
|
|
state Standalone<VectorRef<KeyRangeRef>> prevBackupRanges;
|
|
|
|
state UID logUid;
|
2018-05-10 06:11:05 +08:00
|
|
|
state Version commitVersion;
|
2018-04-27 08:24:40 +08:00
|
|
|
|
|
|
|
state Future<Void> stopDifferential = delay(self->stopDifferentialAfter);
|
|
|
|
state Future<Void> waitUpgrade = backupAgent.waitUpgradeToLatestDrVersion(self->extraDB, self->backupTag);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(success(stopDifferential) && success(waitUpgrade));
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_WaitDifferentialEnd").detail("Tag", printable(self->backupTag));
|
2018-04-27 08:24:40 +08:00
|
|
|
|
2018-04-11 06:19:53 +08:00
|
|
|
try {
|
2018-04-27 08:24:40 +08:00
|
|
|
// Get restore ranges before aborting
|
|
|
|
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(self->extraDB));
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
// Get backup ranges
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
UID _logUid = wait(backupAgent.getLogUid(tr, self->backupTag));
|
|
|
|
logUid = _logUid;
|
|
|
|
|
|
|
|
Optional<Key> backupKeysPacked = wait(tr->get(backupAgent.config.get(BinaryWriter::toValue(logUid, Unversioned())).pack(BackupAgentBase::keyConfigBackupRanges)));
|
|
|
|
ASSERT(backupKeysPacked.present());
|
|
|
|
|
|
|
|
BinaryReader br(backupKeysPacked.get(), IncludeVersion());
|
2018-05-10 06:11:05 +08:00
|
|
|
prevBackupRanges = Standalone<VectorRef<KeyRangeRef>>();
|
2018-04-27 08:24:40 +08:00
|
|
|
br >> prevBackupRanges;
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( lockDatabase(tr, logUid) );
|
2018-05-10 06:11:05 +08:00
|
|
|
tr->addWriteConflictRange(singleKeyRange(StringRef()));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr->commit() );
|
2018-05-10 06:11:05 +08:00
|
|
|
commitVersion = tr->getCommittedVersion();
|
2018-04-27 08:24:40 +08:00
|
|
|
break;
|
|
|
|
} catch( Error &e ) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr->onError(e) );
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-11 06:19:53 +08:00
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_Locked").detail("LockedVersion", commitVersion);
|
2018-05-10 06:11:05 +08:00
|
|
|
|
|
|
|
// Wait for the destination to apply mutations up to the lock commit before switching over.
|
|
|
|
state ReadYourWritesTransaction versionCheckTr(self->extraDB);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
versionCheckTr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
versionCheckTr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
Optional<Value> v = wait(versionCheckTr.get(BinaryWriter::toValue(logUid, Unversioned()).withPrefix(applyMutationsBeginRange.begin)));
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_Applied").detail("AppliedVersion", v.present() ? BinaryReader::fromStringRef<Version>(v.get(), Unversioned()) : -1);
|
2018-05-10 06:11:05 +08:00
|
|
|
if( v.present() && BinaryReader::fromStringRef<Version>(v.get(), Unversioned()) >= commitVersion)
|
|
|
|
break;
|
|
|
|
|
|
|
|
state Future<Void> versionWatch = versionCheckTr.watch(BinaryWriter::toValue(logUid, Unversioned()).withPrefix(applyMutationsBeginRange.begin));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(versionCheckTr.commit());
|
|
|
|
wait(versionWatch);
|
2018-05-10 06:11:05 +08:00
|
|
|
versionCheckTr.reset();
|
|
|
|
} catch( Error &e ) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(versionCheckTr.onError(e));
|
2018-05-10 06:11:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_DiffRanges");
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( diffRanges(prevBackupRanges, self->backupPrefix, cx, self->extraDB ) );
|
2018-05-10 06:11:05 +08:00
|
|
|
|
2018-04-27 08:24:40 +08:00
|
|
|
// abort backup
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_AbortBackup").detail("Tag", printable(self->backupTag));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.abortBackup(self->extraDB, self->backupTag));
|
|
|
|
wait( unlockDatabase(self->extraDB, logUid) );
|
2018-04-27 08:24:40 +08:00
|
|
|
|
|
|
|
// restore database
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_PrepareRestore").detail("RestoreTag", printable(self->restoreTag));
|
2018-04-27 08:24:40 +08:00
|
|
|
state Reference<ReadYourWritesTransaction> tr2(new ReadYourWritesTransaction(cx));
|
|
|
|
loop{
|
|
|
|
try{
|
|
|
|
tr2->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr2->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
for (auto r : prevBackupRanges) {
|
|
|
|
if(!r.empty()) {
|
|
|
|
std::cout << "r: " << r.begin.printable() << " - " << r.end.printable() << std::endl;
|
|
|
|
tr2->addReadConflictRange(r);
|
|
|
|
tr2->clear(r);
|
|
|
|
}
|
|
|
|
}
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr2->commit() );
|
2018-04-27 08:24:40 +08:00
|
|
|
break;
|
|
|
|
} catch( Error &e ) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_RestoreSetupError").error(e, true);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( tr2->onError(e) );
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state Standalone<VectorRef<KeyRangeRef>> restoreRanges;
|
|
|
|
for (auto r : prevBackupRanges) {
|
|
|
|
restoreRanges.push_back_deep(restoreRanges.arena(), KeyRangeRef( r.begin.withPrefix(self->backupPrefix), r.end.withPrefix(self->backupPrefix) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// start restoring db
|
|
|
|
try {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_RestoreDb").detail("RestoreTag", printable(self->restoreTag));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(restoreAgent.submitBackup(cx, self->restoreTag, restoreRanges, true, StringRef(), self->backupPrefix));
|
2018-04-27 08:24:40 +08:00
|
|
|
}
|
|
|
|
catch (Error& e) {
|
2018-08-02 05:30:57 +08:00
|
|
|
TraceEvent("DRU_RestoreSubmitBackupError").error(e).detail("Tag", printable(self->restoreTag));
|
2018-04-27 08:24:40 +08:00
|
|
|
if (e.code() != error_code_backup_unneeded && e.code() != error_code_backup_duplicate)
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2019-02-13 08:07:17 +08:00
|
|
|
wait(success(restoreAgent.waitBackup(cx, self->restoreTag)));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(restoreAgent.unlockBackup(cx, self->restoreTag));
|
|
|
|
wait(checkData(self->extraDB, logUid, logUid, self->backupTag, &backupAgent));
|
2018-04-27 08:24:40 +08:00
|
|
|
|
|
|
|
state UID restoreUid = wait(restoreAgent.getLogUid(cx, self->restoreTag));
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(checkData(cx, restoreUid, restoreUid, self->restoreTag, &restoreAgent));
|
2018-04-27 08:24:40 +08:00
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("DRU_Complete").detail("BackupTag", printable(self->backupTag));
|
2018-04-27 08:24:40 +08:00
|
|
|
|
|
|
|
if (g_simulator.drAgents == ISimulator::BackupToDB) {
|
|
|
|
g_simulator.drAgents = ISimulator::NoBackupAgents;
|
|
|
|
}
|
2018-04-11 06:19:53 +08:00
|
|
|
} catch (Error& e) {
|
2018-04-27 08:24:40 +08:00
|
|
|
TraceEvent(SevError, "BackupAndRestoreCorrectnessError").error(e);
|
2018-04-11 06:19:53 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkloadFactory<BackupToDBUpgradeWorkload> BackupToDBUpgradeWorkloadFactory("BackupToDBUpgrade");
|