add comments; remove unnecessary actor suffix; code format

This commit is contained in:
Xiaoxi Wang 2023-01-02 23:59:46 -08:00
parent bbcb3cc018
commit 5de0c87654
4 changed files with 108 additions and 112 deletions

View File

@ -868,7 +868,7 @@ const KeyRef configKeysPrefix = configKeys.begin;
const KeyRef perpetualStorageWiggleKey("\xff/conf/perpetual_storage_wiggle"_sr);
const KeyRef perpetualStorageWiggleLocalityKey("\xff/conf/perpetual_storage_wiggle_locality"_sr);
// The below two are there for compatible upgrade and downgrade. After 7.3, the perpetual wiggle related keys should use
// format "\xff/storageWiggle/[primary | remote]/[fieldName]"
// format "\xff/storageWiggle/[primary | remote]/[fieldName]". See class StorageWiggleData for the data schema.
const KeyRef perpetualStorageWiggleIDPrefix("\xff/storageWiggleID/"_sr); // withSuffix /primary/ or /remote/
const KeyRef perpetualStorageWiggleStatsPrefix("\xff/storageWiggleStats/"_sr); // withSuffix /primary or /remote
const KeyRef perpetualStorageWigglePrefix("\xff/storageWiggle/"_sr);

View File

@ -34,7 +34,7 @@
#include <ctime>
#include <climits>
#include "fdbclient/BackupContainer.h"
#include "fdbclient/KeyBackedConfig.actor.h"
#include "fdbclient/KeyBackedConfig.h"
#include "flow/actorcompiler.h" // has to be last include
FDB_DECLARE_BOOLEAN_PARAM(LockDB);
@ -54,107 +54,9 @@ 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(PartialBackup);
FDB_DECLARE_BOOLEAN_PARAM(SetValidation);
FDB_DECLARE_BOOLEAN_PARAM(PartialBackup);
// 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> {
ACTOR static Future<std::vector<KeyBackedTag>> getAll_impl(TagUidMap* tagsMap,
Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot);
public:
TagUidMap(const StringRef& prefix) : TagMap("tag->uid/"_sr.withPrefix(prefix)), prefix(prefix) {}
Future<std::vector<KeyBackedTag>> getAll(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return getAll_impl(this, tr, snapshot);
}
Key prefix;
};
class KeyBackedTaskConfig : public KeyBackedConfig {
public:
static struct {
static TaskParam<UID> uid() { return __FUNCTION__sr; }
} TaskParams;
KeyBackedTaskConfig(StringRef prefix, UID uid = UID()) : KeyBackedConfig(prefix, uid) {}
KeyBackedTaskConfig(StringRef prefix, Reference<Task> task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {}
Future<Void> toTask(Reference<ReadYourWritesTransaction> tr,
Reference<Task> task,
SetValidation setValidation = SetValidation::True) {
// Set the uid task parameter
TaskParams.uid().set(task, uid);
if (!setValidation) {
return Void();
}
// 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
Key p = prefix;
return map(tag().get(tr), [u, p, task](Optional<std::string> const& tag) -> Void {
if (!tag.present())
throw restore_error();
// Validation contition is that the uidPair key must be exactly {u, false}
TaskBucket::setValidationCondition(
task, KeyBackedTag(tag.get(), p).key, TupleCodec<UidAndAbortedFlagT>::pack({ u, false }));
return Void();
});
}
// 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
auto& copy = *this;
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) mutable {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
return map(tr->getReadVersion(), [=](Version v) mutable {
copy.lastError().set(tr, { message, v });
copy.lastErrorPerType().set(tr, e.code(), { message, v });
return Void();
});
});
}
};
class BackupAgentBase : NonCopyable {
public:
// Time formatter for anything backup or restore related
@ -686,6 +588,105 @@ inline EBackupState TupleCodec<EBackupState>::unpack(Standalone<StringRef> const
return static_cast<EBackupState>(Tuple::unpack(val).getInt(0));
}
// 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> {
ACTOR static Future<std::vector<KeyBackedTag>> getAll_impl(TagUidMap* tagsMap,
Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot);
public:
TagUidMap(const StringRef& prefix) : TagMap("tag->uid/"_sr.withPrefix(prefix)), prefix(prefix) {}
Future<std::vector<KeyBackedTag>> getAll(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return getAll_impl(this, tr, snapshot);
}
Key prefix;
};
class KeyBackedTaskConfig : public KeyBackedConfig {
public:
static struct {
static TaskParam<UID> uid() { return __FUNCTION__sr; }
} TaskParams;
KeyBackedTaskConfig(StringRef prefix, UID uid = UID()) : KeyBackedConfig(prefix, uid) {}
KeyBackedTaskConfig(StringRef prefix, Reference<Task> task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {}
Future<Void> toTask(Reference<ReadYourWritesTransaction> tr,
Reference<Task> task,
SetValidation setValidation = SetValidation::True) {
// Set the uid task parameter
TaskParams.uid().set(task, uid);
if (!setValidation) {
return Void();
}
// 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
Key p = prefix;
return map(tag().get(tr), [u, p, task](Optional<std::string> const& tag) -> Void {
if (!tag.present())
throw restore_error();
// Validation contition is that the uidPair key must be exactly {u, false}
TaskBucket::setValidationCondition(
task, KeyBackedTag(tag.get(), p).key, TupleCodec<UidAndAbortedFlagT>::pack({ u, false }));
return Void();
});
}
// 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
auto& copy = *this;
return runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) mutable {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
return map(tr->getReadVersion(), [=](Version v) mutable {
copy.lastError().set(tr, { message, v });
copy.lastErrorPerType().set(tr, e.code(), { message, v });
return Void();
});
});
}
};
static inline KeyBackedTag makeRestoreTag(std::string tagName) {
return KeyBackedTag(tagName, fileRestorePrefixRange.begin);
}

View File

@ -1,5 +1,5 @@
/*
* KeyBackedConfig.actor.h
* KeyBackedConfig.h
*
* This source file is part of the FoundationDB open source project
*
@ -18,13 +18,9 @@
* limitations under the License.
*/
#pragma once
#if defined(NO_INTELLISENSE) && !defined(FDBCLIENT_KEYBACKEDCONFIG_G_H)
#define FDBCLIENT_KEYBACKEDCONFIG_G_H
#include "fdbclient/KeyBackedConfig.actor.g.h"
#elif !defined(FDBCLIENT_KEYBACKEDCONFIG_ACTOR_H)
#define FDBCLIENT_KEYBACKEDCONFIG_ACTOR_H
#ifndef FDBCLIENT_KEYBACKEDCONFIG_H
#define FDBCLIENT_KEYBACKEDCONFIG_H
#include "fdbclient/KeyBackedTypes.h"
#include "flow/actorcompiler.h" // has to be last include
class KeyBackedConfig {
public:
@ -55,5 +51,4 @@ protected:
Subspace configSpace;
};
#include "flow/unactorcompiler.h"
#endif // FOUNDATIONDB_KEYBACKEDCONFIG_H
#endif // FDBCLIENT_KEYBACKEDCONFIG_H

View File

@ -1,5 +1,5 @@
/*
* StorageWiggleMetrics.h
* StorageWiggleMetrics.actor.h
*
* This source file is part of the FoundationDB open source project
*
@ -29,7 +29,7 @@
#include "flow/ObjectSerializer.h"
#include "flow/serialize.h"
#include "fdbclient/SystemData.h"
#include "fdbclient/KeyBackedConfig.actor.h"
#include "fdbclient/KeyBackedConfig.h"
#include "fdbclient/RunTransaction.actor.h"
#include "flow/actorcompiler.h"