2017-09-19 07:54:49 +08:00
|
|
|
/*
|
|
|
|
* BackupToDBAbort.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-09-19 07:54:49 +08:00
|
|
|
* 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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-09-19 07:54:49 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-09-19 07:54:49 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 07:19:05 +08:00
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
2021-10-11 11:44:56 +08:00
|
|
|
#include "fdbclient/ClusterConnectionMemoryRecord.h"
|
2019-02-18 09:38:13 +08:00
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2021-03-11 02:06:03 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-09-19 07:54:49 +08:00
|
|
|
|
|
|
|
struct BackupToDBAbort : TestWorkload {
|
|
|
|
double abortDelay;
|
|
|
|
Database extraDB;
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges;
|
|
|
|
UID lockid;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
explicit BackupToDBAbort(const WorkloadContext& wcx) : TestWorkload(wcx) {
|
2017-09-19 07:54:49 +08:00
|
|
|
abortDelay = getOption(options, LiteralStringRef("abortDelay"), 50.0);
|
|
|
|
|
|
|
|
backupRanges.push_back_deep(backupRanges.arena(), normalKeys);
|
|
|
|
|
2021-10-11 11:44:56 +08:00
|
|
|
auto extraFile = makeReference<ClusterConnectionMemoryRecord>(*g_simulator.extraDB);
|
2018-09-22 06:58:14 +08:00
|
|
|
extraDB = Database::createDatabase(extraFile, -1);
|
2017-09-19 07:54:49 +08:00
|
|
|
|
|
|
|
lockid = UID(0xbeeffeed, 0xdecaf00d);
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string description() const override { return "BackupToDBAbort"; }
|
2017-09-19 07:54:49 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> setup(const Database& cx) override {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (clientId != 0)
|
|
|
|
return Void();
|
2017-09-19 07:54:49 +08:00
|
|
|
return _setup(this, cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> _setup(BackupToDBAbort* self, Database cx) {
|
|
|
|
state DatabaseBackupAgent backupAgent(cx);
|
|
|
|
try {
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Submit1").log();
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(backupAgent.submitBackup(self->extraDB,
|
|
|
|
BackupAgentBase::getDefaultTag(),
|
|
|
|
self->backupRanges,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone::False,
|
2021-03-11 02:06:03 +08:00
|
|
|
StringRef(),
|
|
|
|
StringRef(),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB::True));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Submit2").log();
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() != error_code_backup_duplicate)
|
2017-09-19 07:54:49 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> start(Database const& cx) override {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (clientId != 0)
|
|
|
|
return Void();
|
2017-09-19 07:54:49 +08:00
|
|
|
return _start(this, cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> _start(BackupToDBAbort* self, Database cx) {
|
|
|
|
state DatabaseBackupAgent backupAgent(cx);
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent("BDBA_Start").detail("Delay", self->abortDelay);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(self->abortDelay));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Wait").log();
|
2021-07-17 15:11:40 +08:00
|
|
|
wait(success(backupAgent.waitBackup(self->extraDB, BackupAgentBase::getDefaultTag(), StopWhenDone::False)));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Lock").log();
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(lockDatabase(cx, self->lockid));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Abort").log();
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.abortBackup(self->extraDB, BackupAgentBase::getDefaultTag()));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_Unlock").log();
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(backupAgent.unlockBackup(self->extraDB, BackupAgentBase::getDefaultTag()));
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_End").log();
|
2017-09-19 07:54:49 +08:00
|
|
|
|
|
|
|
// SOMEDAY: Remove after backup agents can exist quiescently
|
2020-11-23 11:49:16 +08:00
|
|
|
if (g_simulator.drAgents == ISimulator::BackupAgentType::BackupToDB) {
|
|
|
|
g_simulator.drAgents = ISimulator::BackupAgentType::NoBackupAgents;
|
2017-09-19 07:54:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<bool> _check(BackupToDBAbort* self, Database cx) {
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent("BDBA_UnlockPrimary").log();
|
2017-09-19 07:54:49 +08:00
|
|
|
// Too much of the tester framework expects the primary database to be unlocked, so we unlock it
|
|
|
|
// once all of the workloads have finished.
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(unlockDatabase(cx, self->lockid));
|
2017-09-19 07:54:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(const Database& cx) override { return _check(this, cx); }
|
2017-09-19 07:54:49 +08:00
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {}
|
2017-09-19 07:54:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_WORKLOAD(BackupToDBAbort);
|