2020-10-11 11:10:12 +08:00
|
|
|
/*
|
|
|
|
* BackupToBlob.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2020-10-11 11:10:12 +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
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "fdbclient/BackupAgent.actor.h"
|
|
|
|
#include "fdbclient/BackupContainer.h"
|
2022-10-27 00:38:27 +08:00
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2022-09-30 05:45:47 +08:00
|
|
|
#include "fdbserver/Knobs.h"
|
2020-12-25 09:57:53 +08:00
|
|
|
#include "fdbserver/workloads/BlobStoreWorkload.h"
|
2020-10-11 11:10:12 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
|
|
|
struct BackupToBlobWorkload : TestWorkload {
|
|
|
|
double backupAfter;
|
|
|
|
Key backupTag;
|
|
|
|
Standalone<StringRef> backupURL;
|
2021-04-14 10:22:13 +08:00
|
|
|
int initSnapshotInterval = 0;
|
2020-10-11 11:10:12 +08:00
|
|
|
int snapshotInterval = 100000;
|
|
|
|
|
2022-10-14 10:53:48 +08:00
|
|
|
static constexpr auto NAME = "BackupToBlob";
|
2020-10-11 11:10:12 +08:00
|
|
|
|
|
|
|
BackupToBlobWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
2022-09-20 02:35:58 +08:00
|
|
|
backupAfter = getOption(options, "backupAfter"_sr, 10.0);
|
|
|
|
backupTag = getOption(options, "backupTag"_sr, BackupAgentBase::getDefaultTag());
|
|
|
|
auto backupURLString = getOption(options, "backupURL"_sr, "http://0.0.0.0:10000"_sr).toString();
|
|
|
|
auto accessKeyEnvVar = getOption(options, "accessKeyVar"_sr, "BLOB_ACCESS_KEY"_sr).toString();
|
|
|
|
auto secretKeyEnvVar = getOption(options, "secretKeyVar"_sr, "BLOB_SECRET_KEY"_sr).toString();
|
|
|
|
bool provideKeys = getOption(options, "provideKeys"_sr, false);
|
2020-12-25 08:57:51 +08:00
|
|
|
if (provideKeys) {
|
2020-12-25 09:57:53 +08:00
|
|
|
updateBackupURL(backupURLString, accessKeyEnvVar, "<access_key>", secretKeyEnvVar, "<secret_key>");
|
2020-12-04 03:32:30 +08:00
|
|
|
}
|
|
|
|
backupURL = backupURLString;
|
2020-10-11 11:10:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> setup(Database const& cx) override { return Void(); }
|
|
|
|
|
|
|
|
ACTOR static Future<Void> _start(Database cx, BackupToBlobWorkload* self) {
|
|
|
|
state FileBackupAgent backupAgent;
|
|
|
|
state Standalone<VectorRef<KeyRangeRef>> backupRanges;
|
2022-09-17 06:55:54 +08:00
|
|
|
|
|
|
|
addDefaultBackupRanges(backupRanges);
|
2020-10-11 11:10:12 +08:00
|
|
|
|
|
|
|
wait(delay(self->backupAfter));
|
2022-10-27 00:38:27 +08:00
|
|
|
state DatabaseConfiguration configuration = wait(getDatabaseConfiguration(cx));
|
2021-04-15 01:41:41 +08:00
|
|
|
wait(backupAgent.submitBackup(cx,
|
|
|
|
self->backupURL,
|
2022-03-29 08:10:49 +08:00
|
|
|
{},
|
2021-04-15 01:41:41 +08:00
|
|
|
self->initSnapshotInterval,
|
|
|
|
self->snapshotInterval,
|
|
|
|
self->backupTag.toString(),
|
2022-09-30 05:45:47 +08:00
|
|
|
backupRanges,
|
2022-10-27 00:38:27 +08:00
|
|
|
SERVER_KNOBS->ENABLE_ENCRYPTION &&
|
|
|
|
configuration.tenantMode != TenantMode::OPTIONAL_TENANT));
|
2021-07-17 15:11:40 +08:00
|
|
|
EBackupState backupStatus = wait(backupAgent.waitBackup(cx, self->backupTag.toString(), StopWhenDone::True));
|
2020-10-11 11:10:12 +08:00
|
|
|
TraceEvent("BackupToBlob_BackupStatus").detail("Status", BackupAgentBase::getStateText(backupStatus));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> start(Database const& cx) override { return clientId ? Void() : _start(cx, this); }
|
|
|
|
|
|
|
|
Future<bool> check(Database const& cx) override { return true; }
|
|
|
|
|
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {}
|
|
|
|
};
|
|
|
|
|
2022-10-14 10:53:48 +08:00
|
|
|
WorkloadFactory<BackupToBlobWorkload> BackupToBlobWorkloadFactory;
|