2017-05-26 04:48:44 +08:00
|
|
|
/*
|
2019-02-18 07:19:05 +08:00
|
|
|
* BackupAgent.actor.h
|
2017-05-26 04:48:44 +08:00
|
|
|
*
|
|
|
|
* 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-05-26 04:48:44 +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-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-02-18 07:19:05 +08:00
|
|
|
#if defined(NO_INTELLISENSE) && !defined(FDBCLIENT_BACKUP_AGENT_ACTOR_G_H)
|
2021-03-11 02:06:03 +08:00
|
|
|
#define FDBCLIENT_BACKUP_AGENT_ACTOR_G_H
|
|
|
|
#include "fdbclient/BackupAgent.actor.g.h"
|
2019-02-18 07:19:05 +08:00
|
|
|
#elif !defined(FDBCLIENT_BACKUP_AGENT_ACTOR_H)
|
2021-03-11 02:06:03 +08:00
|
|
|
#define FDBCLIENT_BACKUP_AGENT_ACTOR_H
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#include "flow/flow.h"
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/TaskBucket.h"
|
|
|
|
#include "fdbclient/Notified.h"
|
|
|
|
#include "fdbrpc/IAsyncFile.h"
|
|
|
|
#include "fdbclient/KeyBackedTypes.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <ctime>
|
|
|
|
#include <climits>
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/BackupContainer.h"
|
2019-02-18 07:19:05 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-07-09 20:41:33 +08:00
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(LockDB);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(UnlockDB);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(StopWhenDone);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(Verbose);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(WaitForComplete);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(ForceAction);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(Terminator);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(IncrementalBackupOnly);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(UsePartitionedLog);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(OnlyApplyMutationLogs);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(InconsistentSnapshotOnly);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(ShowErrors);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(AbortOldBackup);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(DstOnly); // TODO: More descriptive name?
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(WaitForDestUID);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(CheckBackupUID);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(DeleteData);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(SetValidation);
|
|
|
|
FDB_DECLARE_BOOLEAN_PARAM(PartialBackup);
|
2021-07-05 07:27:26 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class BackupAgentBase : NonCopyable {
|
|
|
|
public:
|
2019-03-07 14:34:25 +08:00
|
|
|
// Time formatter for anything backup or restore related
|
2019-03-20 16:18:37 +08:00
|
|
|
static std::string formatTime(int64_t epochs);
|
|
|
|
static int64_t parseTime(std::string timestamp);
|
2019-03-07 14:34:25 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static std::string timeFormat() { return "YYYY/MM/DD.HH:MI:SS[+/-]HHMM"; }
|
2019-03-11 07:00:01 +08:00
|
|
|
|
2020-09-24 05:50:34 +08:00
|
|
|
enum class EnumState {
|
|
|
|
STATE_ERRORED = 0,
|
|
|
|
STATE_SUBMITTED = 1,
|
|
|
|
STATE_RUNNING = 2,
|
|
|
|
STATE_RUNNING_DIFFERENTIAL = 3,
|
|
|
|
STATE_COMPLETED = 4,
|
|
|
|
STATE_NEVERRAN = 5,
|
|
|
|
STATE_ABORTED = 6,
|
|
|
|
STATE_PARTIALLY_ABORTED = 7
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Key keyFolderId;
|
|
|
|
static const Key keyBeginVersion;
|
|
|
|
static const Key keyEndVersion;
|
2018-02-21 05:22:31 +08:00
|
|
|
static const Key keyPrevBeginVersion;
|
2017-05-26 04:48:44 +08:00
|
|
|
static const Key keyConfigBackupTag;
|
|
|
|
static const Key keyConfigLogUid;
|
|
|
|
static const Key keyConfigBackupRanges;
|
|
|
|
static const Key keyConfigStopWhenDoneKey;
|
|
|
|
static const Key keyStateStatus;
|
|
|
|
static const Key keyStateStop;
|
2021-07-09 23:13:02 +08:00
|
|
|
static const Key keyStateLogBeginVersion;
|
2017-05-26 04:48:44 +08:00
|
|
|
static const Key keyLastUid;
|
|
|
|
static const Key keyBeginKey;
|
|
|
|
static const Key keyEndKey;
|
2018-04-27 08:24:40 +08:00
|
|
|
static const Key keyDrVersion;
|
2018-02-21 05:22:31 +08:00
|
|
|
static const Key destUid;
|
2018-03-14 02:21:24 +08:00
|
|
|
static const Key backupStartVersion;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
static const Key keyTagName;
|
|
|
|
static const Key keyStates;
|
|
|
|
static const Key keyConfig;
|
|
|
|
static const Key keyErrors;
|
|
|
|
static const Key keyRanges;
|
|
|
|
static const Key keyTasks;
|
|
|
|
static const Key keyFutures;
|
|
|
|
static const Key keySourceStates;
|
|
|
|
static const Key keySourceTagName;
|
|
|
|
|
2021-07-05 10:07:52 +08:00
|
|
|
static constexpr int logHeaderSize = 12;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Convert the status text to an enumerated value
|
2021-07-05 10:07:52 +08:00
|
|
|
static EnumState getState(std::string const& stateText);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-11 07:00:01 +08:00
|
|
|
// Convert the status enum to a text description
|
2021-07-05 10:07:52 +08:00
|
|
|
static const char* getStateText(EnumState enState);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-11 07:00:01 +08:00
|
|
|
// Convert the status enum to a name
|
2021-07-05 10:07:52 +08:00
|
|
|
static const char* getStateName(EnumState enState);
|
2019-03-11 07:00:01 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Determine if the specified state is runnable
|
2021-07-05 10:07:52 +08:00
|
|
|
static bool isRunnable(EnumState enState);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-07-05 10:07:52 +08:00
|
|
|
static KeyRef getDefaultTag() { return StringRef(defaultTagName); }
|
2017-09-06 02:38:40 +08:00
|
|
|
|
2021-07-05 10:07:52 +08:00
|
|
|
static std::string getDefaultTagName() { return defaultTagName; }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-03-07 14:34:25 +08:00
|
|
|
// This is only used for automatic backup name generation
|
2021-07-05 10:07:52 +08:00
|
|
|
static Standalone<StringRef> getCurrentTime();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
protected:
|
2017-09-06 02:38:40 +08:00
|
|
|
static const std::string defaultTagName;
|
2017-05-26 04:48:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileBackupAgent : public BackupAgentBase {
|
|
|
|
public:
|
|
|
|
FileBackupAgent();
|
|
|
|
|
2020-06-10 08:33:41 +08:00
|
|
|
FileBackupAgent(FileBackupAgent&& r) noexcept
|
|
|
|
: subspace(std::move(r.subspace)), config(std::move(r.config)), lastRestorable(std::move(r.lastRestorable)),
|
|
|
|
taskBucket(std::move(r.taskBucket)), futureBucket(std::move(r.futureBucket)) {}
|
|
|
|
|
|
|
|
void operator=(FileBackupAgent&& r) noexcept {
|
2017-05-26 04:48:44 +08:00
|
|
|
subspace = std::move(r.subspace);
|
|
|
|
config = std::move(r.config);
|
2021-03-11 02:06:03 +08:00
|
|
|
lastRestorable = std::move(r.lastRestorable), taskBucket = std::move(r.taskBucket);
|
2017-05-26 04:48:44 +08:00
|
|
|
futureBucket = std::move(r.futureBucket);
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Key> lastBackupTimestamp() { return config.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-08-31 09:05:50 +08:00
|
|
|
|
2021-07-06 04:20:43 +08:00
|
|
|
Future<Void> run(Database cx, double pollDelay, int maxConcurrentTasks) {
|
|
|
|
return taskBucket->run(cx, futureBucket, std::make_shared<double const>(pollDelay), maxConcurrentTasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> run(Database cx, std::shared_ptr<double const> pollDelay, int maxConcurrentTasks) {
|
2017-05-26 04:48:44 +08:00
|
|
|
return taskBucket->run(cx, futureBucket, pollDelay, maxConcurrentTasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** RESTORE **/
|
2017-12-21 08:54:57 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
enum ERestoreState { UNITIALIZED = 0, QUEUED = 1, STARTING = 2, RUNNING = 3, COMPLETED = 4, ABORTED = 5 };
|
|
|
|
static StringRef restoreStateText(ERestoreState id);
|
2020-11-07 03:03:29 +08:00
|
|
|
static Key getPauseKey();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-03-25 05:15:15 +08:00
|
|
|
// parallel restore
|
2021-07-17 15:11:40 +08:00
|
|
|
Future<Void> parallelRestoreFinish(Database cx, UID randomUID, UnlockDB = UnlockDB::True);
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> submitParallelRestore(Database cx,
|
|
|
|
Key backupTag,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
Key bcUrl,
|
|
|
|
Version targetVersion,
|
2021-07-05 07:27:26 +08:00
|
|
|
LockDB lockDB,
|
2021-03-11 02:06:03 +08:00
|
|
|
UID randomUID,
|
|
|
|
Key addPrefix,
|
|
|
|
Key removePrefix);
|
|
|
|
Future<Void> atomicParallelRestore(Database cx,
|
|
|
|
Key tagName,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> ranges,
|
|
|
|
Key addPrefix,
|
2020-06-19 01:35:41 +08:00
|
|
|
Key removePrefix);
|
2020-03-25 05:15:15 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// restore() will
|
|
|
|
// - make sure that url is readable and appears to be a complete backup
|
|
|
|
// - make sure the requested TargetVersion is valid
|
|
|
|
// - submit a restore on the given tagName
|
|
|
|
// - Optionally wait for the restore's completion. Will restore_error if restore fails or is aborted.
|
2021-03-11 02:06:03 +08:00
|
|
|
// restore() will return the targetVersion which will be either the valid version passed in or the max restorable
|
|
|
|
// version for the given url.
|
|
|
|
Future<Version> restore(Database cx,
|
|
|
|
Optional<Database> cxOrig,
|
|
|
|
Key tagName,
|
|
|
|
Key url,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> ranges,
|
2021-07-17 15:11:40 +08:00
|
|
|
WaitForComplete = WaitForComplete::True,
|
2021-07-05 07:27:26 +08:00
|
|
|
Version targetVersion = ::invalidVersion,
|
2021-07-17 15:11:40 +08:00
|
|
|
Verbose = Verbose::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
Key addPrefix = Key(),
|
|
|
|
Key removePrefix = Key(),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB = LockDB::True,
|
|
|
|
OnlyApplyMutationLogs = OnlyApplyMutationLogs::False,
|
|
|
|
InconsistentSnapshotOnly = InconsistentSnapshotOnly::False,
|
2021-06-26 06:11:03 +08:00
|
|
|
Version beginVersion = ::invalidVersion,
|
|
|
|
Optional<std::string> const& encryptionKeyFileName = {});
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Version> restore(Database cx,
|
|
|
|
Optional<Database> cxOrig,
|
|
|
|
Key tagName,
|
|
|
|
Key url,
|
2021-07-17 15:11:40 +08:00
|
|
|
WaitForComplete waitForComplete = WaitForComplete::True,
|
2021-07-05 07:27:26 +08:00
|
|
|
Version targetVersion = ::invalidVersion,
|
2021-07-17 15:11:40 +08:00
|
|
|
Verbose verbose = Verbose::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyRange range = normalKeys,
|
|
|
|
Key addPrefix = Key(),
|
|
|
|
Key removePrefix = Key(),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB lockDB = LockDB::True,
|
|
|
|
OnlyApplyMutationLogs onlyApplyMutationLogs = OnlyApplyMutationLogs::False,
|
|
|
|
InconsistentSnapshotOnly inconsistentSnapshotOnly = InconsistentSnapshotOnly::False,
|
2021-06-26 06:11:03 +08:00
|
|
|
Version beginVersion = ::invalidVersion,
|
|
|
|
Optional<std::string> const& encryptionKeyFileName = {}) {
|
2019-02-26 10:00:28 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> rangeRef;
|
|
|
|
rangeRef.push_back_deep(rangeRef.arena(), range);
|
2021-03-11 02:06:03 +08:00
|
|
|
return restore(cx,
|
|
|
|
cxOrig,
|
|
|
|
tagName,
|
|
|
|
url,
|
|
|
|
rangeRef,
|
|
|
|
waitForComplete,
|
|
|
|
targetVersion,
|
|
|
|
verbose,
|
|
|
|
addPrefix,
|
|
|
|
removePrefix,
|
|
|
|
lockDB,
|
2021-07-05 09:30:55 +08:00
|
|
|
onlyApplyMutationLogs,
|
2021-04-27 03:30:46 +08:00
|
|
|
inconsistentSnapshotOnly,
|
2021-06-26 06:11:03 +08:00
|
|
|
beginVersion,
|
|
|
|
encryptionKeyFileName);
|
2021-03-11 02:06:03 +08:00
|
|
|
}
|
|
|
|
Future<Version> atomicRestore(Database cx,
|
|
|
|
Key tagName,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> ranges,
|
|
|
|
Key addPrefix = Key(),
|
|
|
|
Key removePrefix = Key());
|
|
|
|
Future<Version> atomicRestore(Database cx,
|
|
|
|
Key tagName,
|
|
|
|
KeyRange range = normalKeys,
|
|
|
|
Key addPrefix = Key(),
|
|
|
|
Key removePrefix = Key()) {
|
2019-02-26 10:00:28 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> rangeRef;
|
|
|
|
rangeRef.push_back_deep(rangeRef.arena(), range);
|
|
|
|
return atomicRestore(cx, tagName, rangeRef, addPrefix, removePrefix);
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
// Tries to abort the restore for a tag. Returns the final (stable) state of the tag.
|
|
|
|
Future<ERestoreState> abortRestore(Reference<ReadYourWritesTransaction> tr, Key tagName);
|
2017-12-05 09:21:43 +08:00
|
|
|
Future<ERestoreState> abortRestore(Database cx, Key tagName);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Waits for a restore tag to reach a final (stable) state.
|
2021-07-05 15:35:33 +08:00
|
|
|
Future<ERestoreState> waitRestore(Database cx, Key tagName, Verbose);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Get a string describing the status of a tag
|
|
|
|
Future<std::string> restoreStatus(Reference<ReadYourWritesTransaction> tr, Key tagName);
|
|
|
|
Future<std::string> restoreStatus(Database cx, Key tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx,
|
|
|
|
[=](Reference<ReadYourWritesTransaction> tr) { return restoreStatus(tr, tagName); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** BACKUP METHODS **/
|
2017-12-21 08:54:57 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> submitBackup(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
Key outContainer,
|
2021-04-14 10:22:13 +08:00
|
|
|
int initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
int snapshotIntervalSeconds,
|
2021-06-26 05:11:21 +08:00
|
|
|
std::string const& tagName,
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone = StopWhenDone::True,
|
|
|
|
UsePartitionedLog = UsePartitionedLog::False,
|
|
|
|
IncrementalBackupOnly = IncrementalBackupOnly::False,
|
2021-06-26 05:11:21 +08:00
|
|
|
Optional<std::string> const& encryptionKeyFileName = {});
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> submitBackup(Database cx,
|
|
|
|
Key outContainer,
|
2021-04-14 10:22:13 +08:00
|
|
|
int initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
int snapshotIntervalSeconds,
|
2021-06-26 05:11:21 +08:00
|
|
|
std::string const& tagName,
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone stopWhenDone = StopWhenDone::True,
|
|
|
|
UsePartitionedLog partitionedLog = UsePartitionedLog::False,
|
|
|
|
IncrementalBackupOnly incrementalBackupOnly = IncrementalBackupOnly::False,
|
2021-06-26 05:11:21 +08:00
|
|
|
Optional<std::string> const& encryptionKeyFileName = {}) {
|
2020-03-07 07:40:06 +08:00
|
|
|
return runRYWTransactionFailIfLocked(cx, [=](Reference<ReadYourWritesTransaction> tr) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return submitBackup(tr,
|
|
|
|
outContainer,
|
2021-04-14 10:22:13 +08:00
|
|
|
initialSnapshotIntervalSeconds,
|
2021-03-11 02:06:03 +08:00
|
|
|
snapshotIntervalSeconds,
|
|
|
|
tagName,
|
|
|
|
backupRanges,
|
|
|
|
stopWhenDone,
|
|
|
|
partitionedLog,
|
2021-06-26 05:11:21 +08:00
|
|
|
incrementalBackupOnly,
|
|
|
|
encryptionKeyFileName);
|
2020-03-07 07:40:06 +08:00
|
|
|
});
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> discontinueBackup(Reference<ReadYourWritesTransaction> tr, Key tagName);
|
|
|
|
Future<Void> discontinueBackup(Database cx, Key tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(
|
|
|
|
cx, [=](Reference<ReadYourWritesTransaction> tr) { return discontinueBackup(tr, tagName); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 08:54:57 +08:00
|
|
|
// Terminate an ongoing backup, without waiting for the backup to finish.
|
|
|
|
// Preconditions:
|
|
|
|
// A backup is running with the tag of `tagName`.
|
|
|
|
// Otherwise `backup_unneeded` will be thrown indicating that the backup never existed or already finished.
|
|
|
|
// Postconditions:
|
|
|
|
// No more tasks will be spawned to backup ranges of the database.
|
|
|
|
// logRangesRange and backupLogKeys will be cleared for this backup.
|
2017-09-06 02:38:40 +08:00
|
|
|
Future<Void> abortBackup(Reference<ReadYourWritesTransaction> tr, std::string tagName);
|
|
|
|
Future<Void> abortBackup(Database cx, std::string tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) { return abortBackup(tr, tagName); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
Future<std::string> getStatus(Database cx, ShowErrors, std::string tagName);
|
2019-03-07 13:32:46 +08:00
|
|
|
Future<std::string> getStatusJSON(Database cx, std::string tagName);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-04-14 10:22:13 +08:00
|
|
|
Future<Optional<Version>> getLastRestorable(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
Key tagName,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot = Snapshot::False);
|
2017-11-15 15:33:17 +08:00
|
|
|
void setLastRestorable(Reference<ReadYourWritesTransaction> tr, Key tagName, Version version);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// stopWhenDone will return when the backup is stopped, if enabled. Otherwise, it
|
|
|
|
// will return when the backup directory is restorable.
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<EnumState> waitBackup(Database cx,
|
|
|
|
std::string tagName,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone = StopWhenDone::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
Reference<IBackupContainer>* pContainer = nullptr,
|
|
|
|
UID* pUID = nullptr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-10-28 05:06:15 +08:00
|
|
|
static const Key keyLastRestorable;
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<int64_t> getTaskCount(Reference<ReadYourWritesTransaction> tr) { return taskBucket->getTaskCount(tr); }
|
|
|
|
Future<int64_t> getTaskCount(Database cx) { return taskBucket->getTaskCount(cx); }
|
|
|
|
Future<Void> watchTaskCount(Reference<ReadYourWritesTransaction> tr) { return taskBucket->watchTaskCount(tr); }
|
|
|
|
|
|
|
|
Future<bool> checkActive(Database cx) { return taskBucket->checkActive(cx); }
|
|
|
|
|
2020-04-03 06:28:51 +08:00
|
|
|
// If "pause" is true, pause all backups; otherwise, resume all.
|
|
|
|
Future<Void> changePause(Database db, bool pause);
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
friend class FileBackupAgentImpl;
|
|
|
|
static const int dataFooterSize;
|
|
|
|
|
|
|
|
Subspace subspace;
|
|
|
|
Subspace config;
|
|
|
|
Subspace lastRestorable;
|
|
|
|
|
|
|
|
Reference<TaskBucket> taskBucket;
|
|
|
|
Reference<FutureBucket> futureBucket;
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
template <>
|
|
|
|
inline Tuple Codec<FileBackupAgent::ERestoreState>::pack(FileBackupAgent::ERestoreState const& val) {
|
|
|
|
return Tuple().append(val);
|
|
|
|
}
|
|
|
|
template <>
|
|
|
|
inline FileBackupAgent::ERestoreState Codec<FileBackupAgent::ERestoreState>::unpack(Tuple const& val) {
|
|
|
|
return (FileBackupAgent::ERestoreState)val.getInt(0);
|
|
|
|
}
|
2021-01-31 02:03:25 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class DatabaseBackupAgent : public BackupAgentBase {
|
|
|
|
public:
|
|
|
|
DatabaseBackupAgent();
|
|
|
|
explicit DatabaseBackupAgent(Database src);
|
|
|
|
|
2020-06-10 08:33:41 +08:00
|
|
|
DatabaseBackupAgent(DatabaseBackupAgent&& r) noexcept
|
|
|
|
: subspace(std::move(r.subspace)), states(std::move(r.states)), config(std::move(r.config)),
|
|
|
|
errors(std::move(r.errors)), ranges(std::move(r.ranges)), tagNames(std::move(r.tagNames)),
|
2021-07-23 13:48:27 +08:00
|
|
|
sourceStates(std::move(r.sourceStates)), sourceTagNames(std::move(r.sourceTagNames)),
|
|
|
|
taskBucket(std::move(r.taskBucket)), futureBucket(std::move(r.futureBucket)) {}
|
2020-06-10 08:33:41 +08:00
|
|
|
|
|
|
|
void operator=(DatabaseBackupAgent&& r) noexcept {
|
2017-05-26 04:48:44 +08:00
|
|
|
subspace = std::move(r.subspace);
|
|
|
|
states = std::move(r.states);
|
|
|
|
config = std::move(r.config);
|
|
|
|
errors = std::move(r.errors);
|
|
|
|
ranges = std::move(r.ranges);
|
|
|
|
tagNames = std::move(r.tagNames);
|
|
|
|
taskBucket = std::move(r.taskBucket);
|
|
|
|
futureBucket = std::move(r.futureBucket);
|
|
|
|
sourceStates = std::move(r.sourceStates);
|
|
|
|
sourceTagNames = std::move(r.sourceTagNames);
|
|
|
|
}
|
|
|
|
|
2021-07-06 04:20:43 +08:00
|
|
|
Future<Void> run(Database cx, double pollDelay, int maxConcurrentTasks) {
|
|
|
|
return taskBucket->run(cx, futureBucket, std::make_shared<double const>(pollDelay), maxConcurrentTasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> run(Database cx, std::shared_ptr<double const> pollDelay, int maxConcurrentTasks) {
|
2017-05-26 04:48:44 +08:00
|
|
|
return taskBucket->run(cx, futureBucket, pollDelay, maxConcurrentTasks);
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> atomicSwitchover(Database dest,
|
|
|
|
Key tagName,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
Key addPrefix,
|
|
|
|
Key removePrefix,
|
2021-07-17 15:11:40 +08:00
|
|
|
ForceAction = ForceAction::False);
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<Void> unlockBackup(Reference<ReadYourWritesTransaction> tr, Key tagName);
|
|
|
|
Future<Void> unlockBackup(Database cx, Key tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx,
|
|
|
|
[=](Reference<ReadYourWritesTransaction> tr) { return unlockBackup(tr, tagName); });
|
|
|
|
}
|
|
|
|
|
2021-03-31 08:17:47 +08:00
|
|
|
// Specifies the action to take on the backup's destination key range
|
|
|
|
// before the backup begins.
|
|
|
|
enum PreBackupAction {
|
|
|
|
NONE = 0, // No action is taken
|
|
|
|
VERIFY = 1, // Verify the key range being restored to is empty.
|
|
|
|
CLEAR = 2 // Clear the key range being restored to.
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> submitBackup(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
Key tagName,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone = StopWhenDone::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
Key addPrefix = StringRef(),
|
|
|
|
Key removePrefix = StringRef(),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB lockDatabase = LockDB::False,
|
2021-03-31 08:17:47 +08:00
|
|
|
PreBackupAction backupAction = PreBackupAction::VERIFY);
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> submitBackup(Database cx,
|
|
|
|
Key tagName,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
2021-07-17 15:11:40 +08:00
|
|
|
StopWhenDone stopWhenDone = StopWhenDone::True,
|
2021-03-11 02:06:03 +08:00
|
|
|
Key addPrefix = StringRef(),
|
|
|
|
Key removePrefix = StringRef(),
|
2021-07-17 15:11:40 +08:00
|
|
|
LockDB lockDatabase = LockDB::False,
|
2021-03-31 08:17:47 +08:00
|
|
|
PreBackupAction backupAction = PreBackupAction::VERIFY) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) {
|
|
|
|
return submitBackup(
|
2021-03-31 08:17:47 +08:00
|
|
|
tr, tagName, backupRanges, stopWhenDone, addPrefix, removePrefix, lockDatabase, backupAction);
|
2021-03-11 02:06:03 +08:00
|
|
|
});
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> discontinueBackup(Reference<ReadYourWritesTransaction> tr, Key tagName);
|
|
|
|
Future<Void> discontinueBackup(Database cx, Key tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(
|
|
|
|
cx, [=](Reference<ReadYourWritesTransaction> tr) { return discontinueBackup(tr, tagName); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> abortBackup(Database cx,
|
|
|
|
Key tagName,
|
2021-07-17 15:11:40 +08:00
|
|
|
PartialBackup = PartialBackup::False,
|
|
|
|
AbortOldBackup = AbortOldBackup::False,
|
|
|
|
DstOnly = DstOnly::False,
|
|
|
|
WaitForDestUID = WaitForDestUID::False);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
Future<std::string> getStatus(Database cx, int errorLimit, Key tagName);
|
|
|
|
|
2021-07-17 15:11:40 +08:00
|
|
|
Future<EnumState> getStateValue(Reference<ReadYourWritesTransaction> tr, UID logUid, Snapshot = Snapshot::False);
|
2020-09-24 05:50:34 +08:00
|
|
|
Future<EnumState> getStateValue(Database cx, UID logUid) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx,
|
|
|
|
[=](Reference<ReadYourWritesTransaction> tr) { return getStateValue(tr, logUid); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-07-17 15:11:40 +08:00
|
|
|
Future<UID> getDestUid(Reference<ReadYourWritesTransaction> tr, UID logUid, Snapshot = Snapshot::False);
|
2018-02-21 05:22:31 +08:00
|
|
|
Future<UID> getDestUid(Database cx, UID logUid) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) { return getDestUid(tr, logUid); });
|
2018-02-21 05:22:31 +08:00
|
|
|
}
|
|
|
|
|
2021-07-17 15:11:40 +08:00
|
|
|
Future<UID> getLogUid(Reference<ReadYourWritesTransaction> tr, Key tagName, Snapshot = Snapshot::False);
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<UID> getLogUid(Database cx, Key tagName) {
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) { return getLogUid(tr, tagName); });
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<int64_t> getRangeBytesWritten(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
UID logUid,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot = Snapshot::False);
|
|
|
|
Future<int64_t> getLogBytesWritten(Reference<ReadYourWritesTransaction> tr, UID logUid, Snapshot = Snapshot::False);
|
2017-05-26 04:48:44 +08:00
|
|
|
// stopWhenDone will return when the backup is stopped, if enabled. Otherwise, it
|
|
|
|
// will return when the backup directory is restorable.
|
2021-07-17 15:11:40 +08:00
|
|
|
Future<EnumState> waitBackup(Database cx, Key tagName, StopWhenDone = StopWhenDone::True);
|
2020-09-24 05:50:34 +08:00
|
|
|
Future<EnumState> waitSubmitted(Database cx, Key tagName);
|
2018-04-27 08:24:40 +08:00
|
|
|
Future<Void> waitUpgradeToLatestDrVersion(Database cx, Key tagName);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
static const Key keyAddPrefix;
|
|
|
|
static const Key keyRemovePrefix;
|
|
|
|
static const Key keyRangeVersions;
|
|
|
|
static const Key keyCopyStop;
|
|
|
|
static const Key keyDatabasesInSync;
|
2018-04-27 08:24:40 +08:00
|
|
|
static const int LATEST_DR_VERSION;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
Future<int64_t> getTaskCount(Reference<ReadYourWritesTransaction> tr) { return taskBucket->getTaskCount(tr); }
|
|
|
|
Future<int64_t> getTaskCount(Database cx) { return taskBucket->getTaskCount(cx); }
|
|
|
|
Future<Void> watchTaskCount(Reference<ReadYourWritesTransaction> tr) { return taskBucket->watchTaskCount(tr); }
|
|
|
|
|
|
|
|
Future<bool> checkActive(Database cx) { return taskBucket->checkActive(cx); }
|
|
|
|
|
|
|
|
friend class DatabaseBackupAgentImpl;
|
|
|
|
|
|
|
|
Subspace subspace;
|
|
|
|
Subspace states;
|
|
|
|
Subspace config;
|
|
|
|
Subspace errors;
|
|
|
|
Subspace ranges;
|
|
|
|
Subspace tagNames;
|
|
|
|
Subspace sourceStates;
|
|
|
|
Subspace sourceTagNames;
|
|
|
|
|
|
|
|
Reference<TaskBucket> taskBucket;
|
|
|
|
Reference<FutureBucket> futureBucket;
|
|
|
|
};
|
|
|
|
|
2021-05-04 04:14:16 +08:00
|
|
|
using RangeResultWithVersion = std::pair<RangeResult, Version>;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct RCGroup {
|
2021-05-04 04:14:16 +08:00
|
|
|
RangeResult items;
|
2017-05-26 04:48:44 +08:00
|
|
|
Version version;
|
|
|
|
uint64_t groupKey;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
RCGroup() : version(-1), groupKey(ULLONG_MAX){};
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, items, version, groupKey);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool copyParameter(Reference<Task> source, Reference<Task> dest, Key key);
|
|
|
|
Version getVersionFromString(std::string const& value);
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> getLogRanges(Version beginVersion,
|
|
|
|
Version endVersion,
|
|
|
|
Key destUidValue,
|
|
|
|
int blockSize = CLIENT_KNOBS->LOG_RANGE_BLOCK_SIZE);
|
2017-05-26 04:48:44 +08:00
|
|
|
Standalone<VectorRef<KeyRangeRef>> getApplyRanges(Version beginVersion, Version endVersion, Key backupUid);
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> eraseLogData(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
Key logUidValue,
|
|
|
|
Key destUidValue,
|
|
|
|
Optional<Version> endVersion = Optional<Version>(),
|
2021-07-17 15:11:40 +08:00
|
|
|
CheckBackupUID = CheckBackupUID::False,
|
2021-03-11 02:06:03 +08:00
|
|
|
Version backupUid = 0);
|
|
|
|
Key getApplyKey(Version version, Key backupUid);
|
2021-08-10 05:36:07 +08:00
|
|
|
Key getLogKey(Version version, Key backupUid);
|
2020-06-16 18:59:47 +08:00
|
|
|
Version getLogKeyVersion(Key key);
|
2019-09-13 06:40:14 +08:00
|
|
|
std::pair<Version, uint32_t> decodeBKMutationLogKey(Key key);
|
2017-05-26 04:48:44 +08:00
|
|
|
Future<Void> logError(Database cx, Key keyErrors, const std::string& message);
|
|
|
|
Future<Void> logError(Reference<ReadYourWritesTransaction> tr, Key keyErrors, const std::string& message);
|
|
|
|
Future<Void> checkVersion(Reference<ReadYourWritesTransaction> const& tr);
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> readCommitted(Database cx,
|
|
|
|
PromiseStream<RangeResultWithVersion> results,
|
|
|
|
Reference<FlowLock> lock,
|
|
|
|
KeyRangeRef range,
|
2021-07-17 15:11:40 +08:00
|
|
|
Terminator terminator = Terminator::True,
|
|
|
|
AccessSystemKeys systemAccess = AccessSystemKeys::False,
|
|
|
|
LockAware lockAware = LockAware::False);
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> readCommitted(Database cx,
|
|
|
|
PromiseStream<RCGroup> results,
|
|
|
|
Future<Void> active,
|
|
|
|
Reference<FlowLock> lock,
|
|
|
|
KeyRangeRef range,
|
|
|
|
std::function<std::pair<uint64_t, uint32_t>(Key key)> groupBy,
|
2021-07-17 15:11:40 +08:00
|
|
|
Terminator terminator = Terminator::True,
|
|
|
|
AccessSystemKeys systemAccess = AccessSystemKeys::False,
|
|
|
|
LockAware lockAware = LockAware::False);
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> applyMutations(Database cx,
|
|
|
|
Key uid,
|
|
|
|
Key addPrefix,
|
|
|
|
Key removePrefix,
|
|
|
|
Version beginVersion,
|
|
|
|
Version* endVersion,
|
|
|
|
RequestStream<CommitTransactionRequest> commit,
|
|
|
|
NotifiedVersion* committedVersion,
|
|
|
|
Reference<KeyRangeMap<Version>> keyVersion);
|
2021-07-05 09:30:55 +08:00
|
|
|
ACTOR Future<Void> cleanupBackup(Database cx, DeleteData deleteData);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-09-24 05:50:34 +08:00
|
|
|
using EBackupState = BackupAgentBase::EnumState;
|
|
|
|
template <>
|
|
|
|
inline Tuple Codec<EBackupState>::pack(EBackupState const& val) {
|
|
|
|
return Tuple().append(static_cast<int>(val));
|
|
|
|
}
|
|
|
|
template <>
|
|
|
|
inline EBackupState Codec<EBackupState>::unpack(Tuple const& val) {
|
|
|
|
return static_cast<EBackupState>(val.getInt(0));
|
|
|
|
}
|
2017-09-07 00:46:27 +08:00
|
|
|
|
|
|
|
// Key backed tags are a single-key slice of the TagUidMap, defined below.
|
|
|
|
// The Value type of the key is a UidAndAbortedFlagT which is a pair of {UID, aborted_flag}
|
|
|
|
// All tasks on the UID will have a validation key/value that requires aborted_flag to be
|
|
|
|
// false, so changing that value, such as changing the UID or setting aborted_flag to true,
|
|
|
|
// will kill all of the active tasks on that backup/restore UID.
|
|
|
|
typedef std::pair<UID, bool> UidAndAbortedFlagT;
|
|
|
|
class KeyBackedTag : public KeyBackedProperty<UidAndAbortedFlagT> {
|
|
|
|
public:
|
|
|
|
KeyBackedTag() : KeyBackedProperty(StringRef()) {}
|
|
|
|
KeyBackedTag(std::string tagName, StringRef tagMapPrefix);
|
|
|
|
|
|
|
|
Future<Void> cancel(Reference<ReadYourWritesTransaction> tr) {
|
|
|
|
std::string tag = tagName;
|
|
|
|
Key _tagMapPrefix = tagMapPrefix;
|
|
|
|
return map(get(tr), [tag, _tagMapPrefix, tr](Optional<UidAndAbortedFlagT> up) -> Void {
|
|
|
|
if (up.present()) {
|
|
|
|
// Set aborted flag to true
|
|
|
|
up.get().second = true;
|
|
|
|
KeyBackedTag(tag, _tagMapPrefix).set(tr, up.get());
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tagName;
|
|
|
|
Key tagMapPrefix;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef KeyBackedMap<std::string, UidAndAbortedFlagT> TagMap;
|
|
|
|
// Map of tagName to {UID, aborted_flag} located in the fileRestorePrefixRange keyspace.
|
|
|
|
class TagUidMap : public KeyBackedMap<std::string, UidAndAbortedFlagT> {
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR static Future<std::vector<KeyBackedTag>> getAll_impl(TagUidMap* tagsMap,
|
|
|
|
Reference<ReadYourWritesTransaction> tr,
|
2021-07-03 12:41:50 +08:00
|
|
|
Snapshot snapshot);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TagUidMap(const StringRef& prefix) : TagMap(LiteralStringRef("tag->uid/").withPrefix(prefix)), prefix(prefix) {}
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2021-07-03 12:41:50 +08:00
|
|
|
Future<std::vector<KeyBackedTag>> getAll(Reference<ReadYourWritesTransaction> tr,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot snapshot = Snapshot::False) {
|
2019-12-19 16:29:35 +08:00
|
|
|
return getAll_impl(this, tr, snapshot);
|
2017-09-07 00:46:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Key prefix;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline KeyBackedTag makeRestoreTag(std::string tagName) {
|
|
|
|
return KeyBackedTag(tagName, fileRestorePrefixRange.begin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline KeyBackedTag makeBackupTag(std::string tagName) {
|
|
|
|
return KeyBackedTag(tagName, fileBackupPrefixRange.begin);
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static inline Future<std::vector<KeyBackedTag>> getAllRestoreTags(Reference<ReadYourWritesTransaction> tr,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot snapshot = Snapshot::False) {
|
2019-12-19 16:29:35 +08:00
|
|
|
return TagUidMap(fileRestorePrefixRange.begin).getAll(tr, snapshot);
|
2017-09-07 00:46:27 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
static inline Future<std::vector<KeyBackedTag>> getAllBackupTags(Reference<ReadYourWritesTransaction> tr,
|
2021-07-17 15:11:40 +08:00
|
|
|
Snapshot snapshot = Snapshot::False) {
|
2019-12-19 16:29:35 +08:00
|
|
|
return TagUidMap(fileBackupPrefixRange.begin).getAll(tr, snapshot);
|
2017-09-07 00:46:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class KeyBackedConfig {
|
|
|
|
public:
|
|
|
|
static struct {
|
2021-03-11 02:06:03 +08:00
|
|
|
static TaskParam<UID> uid() { return LiteralStringRef(__FUNCTION__); }
|
2017-09-07 00:46:27 +08:00
|
|
|
} TaskParams;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedConfig(StringRef prefix, UID uid = UID())
|
|
|
|
: uid(uid), prefix(prefix), configSpace(uidPrefixKey(LiteralStringRef("uid->config/").withPrefix(prefix), uid)) {}
|
2017-09-07 00:46:27 +08:00
|
|
|
|
|
|
|
KeyBackedConfig(StringRef prefix, Reference<Task> task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {}
|
|
|
|
|
2021-07-05 09:30:55 +08:00
|
|
|
Future<Void> toTask(Reference<ReadYourWritesTransaction> tr,
|
|
|
|
Reference<Task> task,
|
2021-07-17 15:11:40 +08:00
|
|
|
SetValidation setValidation = SetValidation::True) {
|
2017-09-07 00:46:27 +08:00
|
|
|
// Set the uid task parameter
|
|
|
|
TaskParams.uid().set(task, uid);
|
2018-02-21 05:22:31 +08:00
|
|
|
|
|
|
|
if (!setValidation) {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Set the validation condition for the task which is that the restore uid's tag's uid is the same as the
|
|
|
|
// restore uid. Get this uid's tag, then get the KEY for the tag's uid but don't read it. That becomes the
|
|
|
|
// validation key which TaskBucket will check, and its value must be this restore config's uid.
|
|
|
|
UID u = uid; // 'this' could be invalid in lambda
|
2017-09-07 00:46:27 +08:00
|
|
|
Key p = prefix;
|
2021-03-11 02:06:03 +08:00
|
|
|
return map(tag().get(tr), [u, p, task](Optional<std::string> const& tag) -> Void {
|
|
|
|
if (!tag.present())
|
2017-09-07 00:46:27 +08:00
|
|
|
throw restore_error();
|
|
|
|
// Validation contition is that the uidPair key must be exactly {u, false}
|
2021-03-11 02:06:03 +08:00
|
|
|
TaskBucket::setValidationCondition(
|
|
|
|
task, KeyBackedTag(tag.get(), p).key, Codec<UidAndAbortedFlagT>::pack({ u, false }).pack());
|
2017-09-07 00:46:27 +08:00
|
|
|
return Void();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<std::string> tag() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
|
|
|
UID getUid() { return uid; }
|
|
|
|
|
|
|
|
Key getUidAsKey() { return BinaryWriter::toValue(uid, Unversioned()); }
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void clear(Reference<ReadYourWritesTransaction> tr) { tr->clear(configSpace.range()); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2017-09-09 07:09:18 +08:00
|
|
|
// lastError is a pair of error message and timestamp expressed as an int64_t
|
2018-02-17 11:38:31 +08:00
|
|
|
KeyBackedProperty<std::pair<std::string, Version>> lastError() {
|
2017-09-09 07:09:18 +08:00
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2018-02-17 11:38:31 +08:00
|
|
|
KeyBackedMap<int64_t, std::pair<std::string, Version>> lastErrorPerType() {
|
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the error per type map and the last error property
|
|
|
|
Future<Void> updateErrorInfo(Database cx, Error e, std::string message) {
|
|
|
|
// Avoid capture of this ptr
|
2021-03-11 02:06:03 +08:00
|
|
|
auto& copy = *this;
|
2018-02-17 11:38:31 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) mutable {
|
2018-02-17 11:38:31 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
return map(tr->getReadVersion(), [=](Version v) mutable {
|
|
|
|
copy.lastError().set(tr, { message, v });
|
|
|
|
copy.lastErrorPerType().set(tr, e.code(), { message, v });
|
2018-02-17 11:38:31 +08:00
|
|
|
return Void();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:46:27 +08:00
|
|
|
protected:
|
|
|
|
UID uid;
|
|
|
|
Key prefix;
|
|
|
|
Subspace configSpace;
|
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
template <>
|
|
|
|
inline Tuple Codec<Reference<IBackupContainer>>::pack(Reference<IBackupContainer> const& bc) {
|
2021-07-22 09:02:51 +08:00
|
|
|
Tuple tuple;
|
|
|
|
tuple.append(StringRef(bc->getURL()));
|
|
|
|
if (bc->getEncryptionKeyFileName().present()) {
|
|
|
|
tuple.append(bc->getEncryptionKeyFileName().get());
|
|
|
|
}
|
|
|
|
return tuple;
|
2017-11-15 15:33:17 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
template <>
|
|
|
|
inline Reference<IBackupContainer> Codec<Reference<IBackupContainer>>::unpack(Tuple const& val) {
|
2021-07-22 09:02:51 +08:00
|
|
|
ASSERT(val.size() == 1 || val.size() == 2);
|
|
|
|
auto url = val.getString(0).toString();
|
|
|
|
Optional<std::string> encryptionKeyFileName;
|
|
|
|
if (val.size() == 2) {
|
|
|
|
encryptionKeyFileName = val.getString(1).toString();
|
|
|
|
}
|
|
|
|
return IBackupContainer::openContainer(url, encryptionKeyFileName);
|
2017-11-15 15:33:17 +08:00
|
|
|
}
|
|
|
|
|
2017-09-07 00:46:27 +08:00
|
|
|
class BackupConfig : public KeyBackedConfig {
|
|
|
|
public:
|
|
|
|
BackupConfig(UID uid = UID()) : KeyBackedConfig(fileBackupPrefixRange.begin, uid) {}
|
|
|
|
BackupConfig(Reference<Task> task) : KeyBackedConfig(fileBackupPrefixRange.begin, task) {}
|
|
|
|
|
|
|
|
// rangeFileMap maps a keyrange file's End to its Begin and Filename
|
2017-11-15 15:33:17 +08:00
|
|
|
struct RangeSlice {
|
|
|
|
Key begin;
|
|
|
|
Version version;
|
|
|
|
std::string fileName;
|
|
|
|
int64_t fileSize;
|
|
|
|
Tuple pack() const {
|
|
|
|
return Tuple().append(begin).append(version).append(StringRef(fileName)).append(fileSize);
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
static RangeSlice unpack(Tuple const& t) {
|
2017-11-15 15:33:17 +08:00
|
|
|
RangeSlice r;
|
|
|
|
int i = 0;
|
|
|
|
r.begin = t.getString(i++);
|
|
|
|
r.version = t.getInt(i++);
|
|
|
|
r.fileName = t.getString(i++).toString();
|
|
|
|
r.fileSize = t.getInt(i++);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
// Map of range end boundaries to info about the backup file written for that range.
|
2017-11-15 15:33:17 +08:00
|
|
|
typedef KeyBackedMap<Key, RangeSlice> RangeFileMapT;
|
2021-03-11 02:06:03 +08:00
|
|
|
RangeFileMapT snapshotRangeFileMap() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-18 06:29:57 +08:00
|
|
|
|
2018-11-23 21:23:56 +08:00
|
|
|
// Number of kv range files that were both committed to persistent storage AND inserted into
|
|
|
|
// the snapshotRangeFileMap. Note that since insertions could replace 1 or more existing
|
|
|
|
// map entries this is not necessarily the number of entries currently in the map.
|
2021-03-11 02:06:03 +08:00
|
|
|
// This value exists to help with sizing of kv range folders for BackupContainers that
|
2018-11-23 21:23:56 +08:00
|
|
|
// require it.
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedBinaryValue<int64_t> snapshotRangeFileCount() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2018-11-23 21:23:56 +08:00
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
// Coalesced set of ranges already dispatched for writing.
|
|
|
|
typedef KeyBackedMap<Key, bool> RangeDispatchMapT;
|
2021-03-11 02:06:03 +08:00
|
|
|
RangeDispatchMapT snapshotRangeDispatchMap() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2021-04-14 10:22:13 +08:00
|
|
|
// Interval to use for the first (initial) snapshot.
|
|
|
|
KeyBackedProperty<int64_t> initialSnapshotIntervalSeconds() {
|
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2017-12-15 17:39:50 +08:00
|
|
|
// Interval to use for determining the target end version for new snapshots
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<int64_t> snapshotIntervalSeconds() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2017-12-15 17:39:50 +08:00
|
|
|
// When the current snapshot began
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Version> snapshotBeginVersion() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// When the current snapshot is desired to end.
|
|
|
|
// This can be changed at runtime to speed up or slow down a snapshot
|
|
|
|
KeyBackedProperty<Version> snapshotTargetEndVersion() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<int64_t> snapshotBatchSize() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-15 17:39:50 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Key> snapshotBatchFuture() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Key> snapshotBatchDispatchDoneKey() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-14 17:44:38 +08:00
|
|
|
|
2019-03-11 16:25:51 +08:00
|
|
|
KeyBackedProperty<int64_t> snapshotDispatchLastShardsBehind() {
|
2019-03-11 07:00:01 +08:00
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyBackedProperty<Version> snapshotDispatchLastVersion() {
|
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
Future<Void> initNewSnapshot(Reference<ReadYourWritesTransaction> tr, int64_t intervalSeconds = -1) {
|
2021-03-11 02:06:03 +08:00
|
|
|
BackupConfig& copy = *this; // Capture this by value instead of this ptr
|
2017-12-18 06:29:57 +08:00
|
|
|
|
|
|
|
Future<Version> beginVersion = tr->getReadVersion();
|
|
|
|
Future<int64_t> defaultInterval = 0;
|
2021-04-14 10:22:13 +08:00
|
|
|
if (intervalSeconds < 0) {
|
2017-12-18 06:29:57 +08:00
|
|
|
defaultInterval = copy.snapshotIntervalSeconds().getOrThrow(tr);
|
2021-04-14 10:22:13 +08:00
|
|
|
}
|
2017-12-18 06:29:57 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// Make sure read version and possibly the snapshot interval value are ready, then clear/init the snapshot
|
|
|
|
// config members
|
2017-12-18 06:29:57 +08:00
|
|
|
return map(success(beginVersion) && success(defaultInterval), [=](Void) mutable {
|
|
|
|
copy.snapshotRangeFileMap().clear(tr);
|
|
|
|
copy.snapshotRangeDispatchMap().clear(tr);
|
|
|
|
copy.snapshotBatchSize().clear(tr);
|
|
|
|
copy.snapshotBatchFuture().clear(tr);
|
|
|
|
copy.snapshotBatchDispatchDoneKey().clear(tr);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (intervalSeconds < 0)
|
2017-12-18 06:29:57 +08:00
|
|
|
intervalSeconds = defaultInterval.get();
|
|
|
|
Version endVersion = beginVersion.get() + intervalSeconds * CLIENT_KNOBS->CORE_VERSIONSPERSECOND;
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
copy.snapshotBeginVersion().set(tr, beginVersion.get());
|
|
|
|
copy.snapshotTargetEndVersion().set(tr, endVersion);
|
2018-11-23 21:23:56 +08:00
|
|
|
copy.snapshotRangeFileCount().set(tr, 0);
|
2019-03-11 07:00:01 +08:00
|
|
|
copy.snapshotDispatchLastVersion().clear(tr);
|
|
|
|
copy.snapshotDispatchLastShardsBehind().clear(tr);
|
2017-12-18 06:29:57 +08:00
|
|
|
|
|
|
|
return Void();
|
|
|
|
});
|
2017-09-07 00:46:27 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedBinaryValue<int64_t> rangeBytesWritten() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedBinaryValue<int64_t> logBytesWritten() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<EBackupState> stateEnum() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2017-11-15 15:33:17 +08:00
|
|
|
KeyBackedProperty<Reference<IBackupContainer>> backupContainer() {
|
2017-09-07 00:46:27 +08:00
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2020-01-22 08:57:30 +08:00
|
|
|
// Set to true when all backup workers for saving mutation logs have been started.
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<bool> allWorkerStarted() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2020-01-22 08:57:30 +08:00
|
|
|
|
2020-03-23 07:31:39 +08:00
|
|
|
// Each backup worker adds its (epoch, tag.id) to this property.
|
|
|
|
KeyBackedProperty<std::vector<std::pair<int64_t, int64_t>>> startedBackupWorkers() {
|
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2020-03-07 03:58:10 +08:00
|
|
|
// Set to true if backup worker is enabled.
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<bool> backupWorkerEnabled() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2020-03-07 03:58:10 +08:00
|
|
|
|
2020-03-07 07:40:06 +08:00
|
|
|
// Set to true if partitioned log is enabled (only useful if backup worker is also enabled).
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<bool> partitionedLogEnabled() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2020-03-07 07:40:06 +08:00
|
|
|
|
2020-07-22 04:07:16 +08:00
|
|
|
// Set to true if only requesting incremental backup without base snapshot.
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<bool> incrementalBackupOnly() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2020-07-22 04:07:16 +08:00
|
|
|
|
2020-03-07 03:58:10 +08:00
|
|
|
// Latest version for which all prior versions have saved by backup workers.
|
|
|
|
KeyBackedProperty<Version> latestBackupWorkerSavedVersion() {
|
|
|
|
return configSpace.pack(LiteralStringRef(__FUNCTION__));
|
|
|
|
}
|
|
|
|
|
2017-09-07 00:46:27 +08:00
|
|
|
// Stop differntial logging if already started or don't start after completing KV ranges
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<bool> stopWhenDone() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
// Latest version for which all prior versions have had their log copy tasks completed
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Version> latestLogEndVersion() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-18 06:29:57 +08:00
|
|
|
|
|
|
|
// The end version of the last complete snapshot
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Version> latestSnapshotEndVersion() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2017-12-22 09:09:21 +08:00
|
|
|
// The end version of the first complete snapshot
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Version> firstSnapshotEndVersion() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-12-22 09:09:21 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<Key> destUidValue() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2018-02-21 05:22:31 +08:00
|
|
|
|
2017-12-18 06:29:57 +08:00
|
|
|
Future<Optional<Version>> getLatestRestorableVersion(Reference<ReadYourWritesTransaction> tr) {
|
2017-12-22 07:45:10 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE);
|
2017-12-18 06:29:57 +08:00
|
|
|
auto lastLog = latestLogEndVersion().get(tr);
|
2017-12-22 09:09:21 +08:00
|
|
|
auto firstSnapshot = firstSnapshotEndVersion().get(tr);
|
2020-03-07 07:40:06 +08:00
|
|
|
auto workerEnabled = backupWorkerEnabled().get(tr);
|
|
|
|
auto plogEnabled = partitionedLogEnabled().get(tr);
|
2020-03-07 03:58:10 +08:00
|
|
|
auto workerVersion = latestBackupWorkerSavedVersion().get(tr);
|
2020-08-05 03:48:43 +08:00
|
|
|
auto incrementalBackup = incrementalBackupOnly().get(tr);
|
|
|
|
return map(success(lastLog) && success(firstSnapshot) && success(workerEnabled) && success(plogEnabled) &&
|
|
|
|
success(workerVersion) && success(incrementalBackup),
|
|
|
|
[=](Void) -> Optional<Version> {
|
|
|
|
// The latest log greater than the oldest snapshot is the restorable version
|
|
|
|
Optional<Version> logVersion = workerEnabled.get().present() && workerEnabled.get().get() &&
|
|
|
|
plogEnabled.get().present() && plogEnabled.get().get()
|
|
|
|
? workerVersion.get()
|
|
|
|
: lastLog.get();
|
|
|
|
if (logVersion.present() && firstSnapshot.get().present() &&
|
|
|
|
logVersion.get() > firstSnapshot.get().get()) {
|
|
|
|
return std::max(logVersion.get() - 1, firstSnapshot.get().get());
|
|
|
|
}
|
|
|
|
if (logVersion.present() && incrementalBackup.isReady() && incrementalBackup.get().present() &&
|
|
|
|
incrementalBackup.get().get()) {
|
|
|
|
return logVersion.get() - 1;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
});
|
2017-12-18 06:29:57 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyBackedProperty<std::vector<KeyRange>> backupRanges() { return configSpace.pack(LiteralStringRef(__FUNCTION__)); }
|
2017-09-07 00:46:27 +08:00
|
|
|
|
2018-02-21 05:22:31 +08:00
|
|
|
void startMutationLogs(Reference<ReadYourWritesTransaction> tr, KeyRangeRef backupRange, Key destUidValue) {
|
|
|
|
Key mutationLogsDestKey = destUidValue.withPrefix(backupLogKeys.begin);
|
2021-03-11 02:06:03 +08:00
|
|
|
tr->set(logRangesEncodeKey(backupRange.begin, BinaryReader::fromStringRef<UID>(destUidValue, Unversioned())),
|
|
|
|
logRangesEncodeValue(backupRange.end, mutationLogsDestKey));
|
2017-09-07 00:46:27 +08:00
|
|
|
}
|
2017-09-09 07:09:18 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Future<Void> logError(Database cx, Error e, std::string details, void* taskInstance = nullptr) {
|
|
|
|
if (!uid.isValid()) {
|
2017-09-09 07:09:18 +08:00
|
|
|
TraceEvent(SevError, "FileBackupErrorNoUID").error(e).detail("Description", details);
|
|
|
|
return Void();
|
|
|
|
}
|
2017-11-19 20:34:28 +08:00
|
|
|
TraceEvent t(SevWarn, "FileBackupError");
|
2021-03-11 02:06:03 +08:00
|
|
|
t.error(e)
|
|
|
|
.detail("BackupUID", uid)
|
|
|
|
.detail("Description", details)
|
|
|
|
.detail("TaskInstance", (uint64_t)taskInstance);
|
2020-06-09 10:02:53 +08:00
|
|
|
// key_not_found could happen
|
2021-03-11 02:06:03 +08:00
|
|
|
if (e.code() == error_code_key_not_found)
|
2017-11-19 20:34:28 +08:00
|
|
|
t.backtrace();
|
2018-02-17 11:38:31 +08:00
|
|
|
|
2018-03-01 10:22:45 +08:00
|
|
|
return updateErrorInfo(cx, e, details);
|
2017-09-09 07:09:18 +08:00
|
|
|
}
|
2017-09-07 00:46:27 +08:00
|
|
|
};
|
2019-01-25 11:25:10 +08:00
|
|
|
|
2019-10-26 07:01:09 +08:00
|
|
|
// Helper class for reading restore data from a buffer and throwing the right errors.
|
|
|
|
struct StringRefReader {
|
|
|
|
StringRefReader(StringRef s = StringRef(), Error e = Error()) : rptr(s.begin()), end(s.end()), failure_error(e) {}
|
|
|
|
|
|
|
|
// Return remainder of data as a StringRef
|
|
|
|
StringRef remainder() { return StringRef(rptr, end - rptr); }
|
|
|
|
|
|
|
|
// Return a pointer to len bytes at the current read position and advance read pos
|
|
|
|
const uint8_t* consume(unsigned int len) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (rptr == end && len != 0)
|
|
|
|
throw end_of_stream();
|
2019-10-26 07:01:09 +08:00
|
|
|
const uint8_t* p = rptr;
|
|
|
|
rptr += len;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (rptr > end)
|
|
|
|
throw failure_error;
|
2019-10-26 07:01:09 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a T from the current read position and advance read pos
|
|
|
|
template <typename T>
|
|
|
|
const T consume() {
|
|
|
|
return *(const T*)consume(sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Functions for consuming big endian (network byte order) integers.
|
|
|
|
// Consumes a big endian number, swaps it to little endian, and returns it.
|
2020-07-25 03:24:42 +08:00
|
|
|
int32_t consumeNetworkInt32() { return (int32_t)bigEndian32((uint32_t)consume<int32_t>()); }
|
|
|
|
uint32_t consumeNetworkUInt32() { return bigEndian32(consume<uint32_t>()); }
|
2019-10-26 07:01:09 +08:00
|
|
|
|
2020-02-19 05:21:29 +08:00
|
|
|
// Convert big Endian value (e.g., encoded in log file) into a littleEndian uint64_t value.
|
|
|
|
int64_t consumeNetworkInt64() { return (int64_t)bigEndian64((uint32_t)consume<int64_t>()); }
|
|
|
|
uint64_t consumeNetworkUInt64() { return bigEndian64(consume<uint64_t>()); }
|
|
|
|
|
2019-10-26 07:01:09 +08:00
|
|
|
bool eof() { return rptr == end; }
|
|
|
|
|
|
|
|
const uint8_t *rptr, *end;
|
|
|
|
Error failure_error;
|
|
|
|
};
|
|
|
|
|
2020-04-22 02:38:45 +08:00
|
|
|
namespace fileBackup {
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Standalone<VectorRef<KeyValueRef>>> decodeRangeFileBlock(Reference<IAsyncFile> file,
|
|
|
|
int64_t offset,
|
2020-04-22 02:38:45 +08:00
|
|
|
int len);
|
2020-04-28 04:59:45 +08:00
|
|
|
|
2021-08-02 13:39:28 +08:00
|
|
|
// Reads a mutation log block from file and parses into batch mutation blocks for further parsing.
|
|
|
|
ACTOR Future<Standalone<VectorRef<KeyValueRef>>> decodeMutationLogFileBlock(Reference<IAsyncFile> file,
|
|
|
|
int64_t offset,
|
|
|
|
int len);
|
|
|
|
|
2020-04-28 04:59:45 +08:00
|
|
|
// Return a block of contiguous padding bytes "\0xff" for backup files, growing if needed.
|
|
|
|
Value makePadding(int size);
|
2021-03-11 02:06:03 +08:00
|
|
|
} // namespace fileBackup
|
2020-04-22 02:38:45 +08:00
|
|
|
|
2020-06-24 06:48:37 +08:00
|
|
|
// For fast restore simulation test
|
|
|
|
// For testing addPrefix feature in fast restore.
|
|
|
|
// Transform db content in restoreRanges by removePrefix and then addPrefix.
|
|
|
|
// Assume: DB is locked
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> transformRestoredDatabase(Database cx,
|
|
|
|
Standalone<VectorRef<KeyRangeRef>> backupRanges,
|
|
|
|
Key addPrefix,
|
|
|
|
Key removePrefix);
|
2020-06-24 06:48:37 +08:00
|
|
|
|
2020-09-10 01:47:08 +08:00
|
|
|
void simulateBlobFailure();
|
|
|
|
|
2019-06-27 04:33:19 +08:00
|
|
|
#include "flow/unactorcompiler.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|