From bbcb3cc0188f9a681c28e23e861568d491d7910b Mon Sep 17 00:00:00 2001 From: Xiaoxi Wang Date: Mon, 2 Jan 2023 23:34:39 -0800 Subject: [PATCH] extract KeyBackedConfig, StorageWiggleData class; solve template resolution problem; solve MV txn and native api conflict by splitting RunTransaction file --- fdbbackup/backup.actor.cpp | 2 +- fdbclient/BackupContainer.actor.cpp | 2 +- fdbclient/FileBackupAgent.actor.cpp | 8 +- fdbclient/NativeAPI.actor.cpp | 7 +- fdbclient/SystemData.cpp | 22 -- .../include/fdbclient/BackupAgent.actor.h | 105 ++++++++- .../ConsistencyScanInterface.actor.h | 2 +- .../fdbclient/GenericManagementAPI.actor.h | 5 +- .../include/fdbclient/KeyBackedConfig.actor.h | 140 ++---------- .../fdbclient/RunRYWTransaction.actor.h | 85 +++++++ .../include/fdbclient/RunTransaction.actor.h | 47 ---- .../fdbclient/StorageWiggleMetrics.actor.h | 209 ++++++++++-------- fdbclient/include/fdbclient/SystemData.h | 6 +- fdbclient/include/fdbclient/TaskBucket.h | 2 +- .../fdbclient/TenantEntryCache.actor.h | 2 +- fdbserver/DDTeamCollection.actor.cpp | 22 +- fdbserver/DataDistribution.actor.cpp | 24 +- fdbserver/OldTLogServer_6_0.actor.cpp | 2 +- fdbserver/OldTLogServer_6_2.actor.cpp | 2 +- fdbserver/QuietDatabase.actor.cpp | 2 +- fdbserver/RestoreRoleCommon.actor.cpp | 2 +- fdbserver/Status.actor.cpp | 7 +- fdbserver/TLogServer.actor.cpp | 2 +- .../include/fdbserver/DDTeamCollection.h | 2 +- .../fdbserver/DataDistribution.actor.h | 4 +- .../include/fdbserver/RestoreCommon.actor.h | 6 +- .../AtomicOpsApiCorrectness.actor.cpp | 2 +- .../AutomaticIdempotencyWorkload.actor.cpp | 2 +- ...kupAndParallelRestoreCorrectness.actor.cpp | 2 +- ...entTransactionProfileCorrectness.actor.cpp | 2 +- .../workloads/ConfigureDatabase.actor.cpp | 2 +- .../DifferentClustersSameRV.actor.cpp | 2 +- .../MetaclusterManagementWorkload.actor.cpp | 2 +- .../PerpetualWiggleStatsWorkload.actor.cpp | 3 +- fdbserver/workloads/SkewedReadWrite.actor.cpp | 2 +- .../workloads/SuspendProcesses.actor.cpp | 2 +- .../TenantManagementWorkload.actor.cpp | 2 +- fdbserver/workloads/ThreadSafety.actor.cpp | 1 - fdbserver/workloads/TriggerRecovery.actor.cpp | 2 +- 39 files changed, 388 insertions(+), 357 deletions(-) create mode 100644 fdbclient/include/fdbclient/RunRYWTransaction.actor.h diff --git a/fdbbackup/backup.actor.cpp b/fdbbackup/backup.actor.cpp index 238fb51ac0..2bfa21c4b8 100644 --- a/fdbbackup/backup.actor.cpp +++ b/fdbbackup/backup.actor.cpp @@ -45,7 +45,7 @@ #include "fdbclient/ClusterConnectionFile.h" #include "fdbclient/KeyBackedTypes.h" #include "fdbclient/IKnobCollection.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/S3BlobStore.h" #include "fdbclient/SystemData.h" #include "fdbclient/json_spirit/json_spirit_writer_template.h" diff --git a/fdbclient/BackupContainer.actor.cpp b/fdbclient/BackupContainer.actor.cpp index c318a6591d..93fe12bd30 100644 --- a/fdbclient/BackupContainer.actor.cpp +++ b/fdbclient/BackupContainer.actor.cpp @@ -47,7 +47,7 @@ #include "fdbclient/SystemData.h" #include "fdbclient/ReadYourWrites.h" #include "fdbclient/KeyBackedTypes.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include #include #include diff --git a/fdbclient/FileBackupAgent.actor.cpp b/fdbclient/FileBackupAgent.actor.cpp index 8441278977..7f13a52191 100644 --- a/fdbclient/FileBackupAgent.actor.cpp +++ b/fdbclient/FileBackupAgent.actor.cpp @@ -154,10 +154,10 @@ KeyBackedTag::KeyBackedTag(std::string tagName, StringRef tagMapPrefix) : KeyBackedProperty(TagUidMap(tagMapPrefix).getProperty(tagName)), tagName(tagName), tagMapPrefix(tagMapPrefix) {} -class RestoreConfig : public KeyBackedConfig { +class RestoreConfig : public KeyBackedTaskConfig { public: - RestoreConfig(UID uid = UID()) : KeyBackedConfig(fileRestorePrefixRange.begin, uid) {} - RestoreConfig(Reference task) : KeyBackedConfig(fileRestorePrefixRange.begin, task) {} + RestoreConfig(UID uid = UID()) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, uid) {} + RestoreConfig(Reference task) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, task) {} KeyBackedProperty stateEnum() { return configSpace.pack(__FUNCTION__sr); } Future stateText(Reference tr) { @@ -1284,7 +1284,7 @@ ACTOR Future checkTaskVersion(Database cx, Reference task, StringRef .detail("TaskVersion", taskVersion) .detail("Name", name) .detail("Version", version); - if (KeyBackedConfig::TaskParams.uid().exists(task)) { + if (KeyBackedTaskConfig::TaskParams.uid().exists(task)) { std::string msg = format("%s task version `%lu' is greater than supported version `%lu'", task->params[Task::reservedTaskParamKeyType].toString().c_str(), (unsigned long)taskVersion, diff --git a/fdbclient/NativeAPI.actor.cpp b/fdbclient/NativeAPI.actor.cpp index a9e12b9b9f..016cc5986f 100644 --- a/fdbclient/NativeAPI.actor.cpp +++ b/fdbclient/NativeAPI.actor.cpp @@ -8647,9 +8647,10 @@ Future DatabaseContext::verifyBlobRange(const KeyRange& range, ACTOR Future>> readStorageWiggleValues(Database cx, bool primary, bool use_system_priority) { - state const Key readKey = perpetualStorageWigglePrefixFor(primary, PerpetualWigglePrefixType::STORAGE_ID); - state KeyBackedObjectMap metadataMap(readKey, - IncludeVersion()); + state StorageWiggleData wiggleState; + state KeyBackedObjectMap metadataMap = + wiggleState.wigglingStorageServer(PrimaryRegion(primary)); + state Reference tr(new ReadYourWritesTransaction(cx)); state KeyBackedRangeResult> res; diff --git a/fdbclient/SystemData.cpp b/fdbclient/SystemData.cpp index 0be61d4d35..6e016de9b2 100644 --- a/fdbclient/SystemData.cpp +++ b/fdbclient/SystemData.cpp @@ -21,7 +21,6 @@ #include "fdbclient/SystemData.h" #include "fdbclient/BlobGranuleCommon.h" #include "fdbclient/FDBTypes.h" -#include "fdbclient/NativeAPI.actor.h" #include "fdbclient/StorageServerInterface.h" #include "flow/Arena.h" #include "flow/TDMetric.actor.h" @@ -872,29 +871,8 @@ const KeyRef perpetualStorageWiggleLocalityKey("\xff/conf/perpetual_storage_wigg // format "\xff/storageWiggle/[primary | remote]/[fieldName]" const KeyRef perpetualStorageWiggleIDPrefix("\xff/storageWiggleID/"_sr); // withSuffix /primary/ or /remote/ const KeyRef perpetualStorageWiggleStatsPrefix("\xff/storageWiggleStats/"_sr); // withSuffix /primary or /remote -// "\xff/storageWiggle/[primary | remote]/[fieldName]" const KeyRef perpetualStorageWigglePrefix("\xff/storageWiggle/"_sr); -// the final char is "/" -const Key perpetualStorageWigglePrefixFor(bool primaryDc, PerpetualWigglePrefixType type) { - if (type == PerpetualWigglePrefixType::STORAGE_ID) - return perpetualStorageWiggleIDPrefix.withSuffix(primaryDc ? "primary/"_sr : "remote/"_sr); - ASSERT(false); - return ""_sr; -} - -const Key perpetualStorageWiggleKeyFor(bool primaryDc, PerpetualWiggleKeyType type) { - if (type == PerpetualWiggleKeyType::WIGGLE_STATS) - return perpetualStorageWiggleStatsPrefix.withSuffix(primaryDc ? "primary"_sr : "remote"_sr); - - Key result = perpetualStorageWigglePrefix.withSuffix(primaryDc ? "primary/"_sr : "remote/"_sr); - if (type == PerpetualWiggleKeyType::WIGGLE_DELAY) - return result.withSuffix("wiggleDelay"_sr); - - ASSERT(false); - return ""_sr; -} - const KeyRef triggerDDTeamInfoPrintKey("\xff/triggerDDTeamInfoPrint"_sr); const KeyRef consistencyScanInfoKey = "\xff/consistencyScanInfo"_sr; diff --git a/fdbclient/include/fdbclient/BackupAgent.actor.h b/fdbclient/include/fdbclient/BackupAgent.actor.h index 65cd4499f1..8c455ec649 100644 --- a/fdbclient/include/fdbclient/BackupAgent.actor.h +++ b/fdbclient/include/fdbclient/BackupAgent.actor.h @@ -55,7 +55,106 @@ 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); +// 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 UidAndAbortedFlagT; +class KeyBackedTag : public KeyBackedProperty { +public: + KeyBackedTag() : KeyBackedProperty(StringRef()) {} + KeyBackedTag(std::string tagName, StringRef tagMapPrefix); + + Future cancel(Reference tr) { + std::string tag = tagName; + Key _tagMapPrefix = tagMapPrefix; + return map(get(tr), [tag, _tagMapPrefix, tr](Optional 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 TagMap; +// Map of tagName to {UID, aborted_flag} located in the fileRestorePrefixRange keyspace. +class TagUidMap : public KeyBackedMap { + ACTOR static Future> getAll_impl(TagUidMap* tagsMap, + Reference tr, + Snapshot snapshot); + +public: + TagUidMap(const StringRef& prefix) : TagMap("tag->uid/"_sr.withPrefix(prefix)), prefix(prefix) {} + + Future> getAll(Reference tr, + Snapshot snapshot = Snapshot::False) { + return getAll_impl(this, tr, snapshot); + } + + Key prefix; +}; + +class KeyBackedTaskConfig : public KeyBackedConfig { +public: + static struct { + static TaskParam uid() { return __FUNCTION__sr; } + } TaskParams; + + KeyBackedTaskConfig(StringRef prefix, UID uid = UID()) : KeyBackedConfig(prefix, uid) {} + + KeyBackedTaskConfig(StringRef prefix, Reference task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {} + + Future toTask(Reference tr, + Reference 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 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::pack({ u, false })); + return Void(); + }); + } + + // Updates the error per type map and the last error property + Future updateErrorInfo(Database cx, Error e, std::string message) { + // Avoid capture of this ptr + auto& copy = *this; + + return runRYWTransaction(cx, [=](Reference 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 @@ -643,10 +742,10 @@ inline Reference TupleCodec>::unpa return IBackupContainer::openContainer(url, proxy, encryptionKeyFileName); } -class BackupConfig : public KeyBackedConfig { +class BackupConfig : public KeyBackedTaskConfig { public: - BackupConfig(UID uid = UID()) : KeyBackedConfig(fileBackupPrefixRange.begin, uid) {} - BackupConfig(Reference task) : KeyBackedConfig(fileBackupPrefixRange.begin, task) {} + BackupConfig(UID uid = UID()) : KeyBackedTaskConfig(fileBackupPrefixRange.begin, uid) {} + BackupConfig(Reference task) : KeyBackedTaskConfig(fileBackupPrefixRange.begin, task) {} // rangeFileMap maps a keyrange file's End to its Begin and Filename struct RangeSlice { diff --git a/fdbclient/include/fdbclient/ConsistencyScanInterface.actor.h b/fdbclient/include/fdbclient/ConsistencyScanInterface.actor.h index 7d6529ced0..c96fb4dace 100644 --- a/fdbclient/include/fdbclient/ConsistencyScanInterface.actor.h +++ b/fdbclient/include/fdbclient/ConsistencyScanInterface.actor.h @@ -27,7 +27,7 @@ #include "fdbclient/CommitProxyInterface.h" #include "fdbclient/DatabaseConfiguration.h" #include "fdbclient/FDBTypes.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbrpc/fdbrpc.h" #include "fdbrpc/Locality.h" diff --git a/fdbclient/include/fdbclient/GenericManagementAPI.actor.h b/fdbclient/include/fdbclient/GenericManagementAPI.actor.h index 5575139cb4..7bd6376806 100644 --- a/fdbclient/include/fdbclient/GenericManagementAPI.actor.h +++ b/fdbclient/include/fdbclient/GenericManagementAPI.actor.h @@ -535,8 +535,9 @@ Future changeConfig(Reference db, std::mapaddReadConflictRange(singleKeyRange(moveKeysLockOwnerKey)); diff --git a/fdbclient/include/fdbclient/KeyBackedConfig.actor.h b/fdbclient/include/fdbclient/KeyBackedConfig.actor.h index 2925361bf4..a9231fc626 100644 --- a/fdbclient/include/fdbclient/KeyBackedConfig.actor.h +++ b/fdbclient/include/fdbclient/KeyBackedConfig.actor.h @@ -1,123 +1,46 @@ /* - * KeyBackedConfig.actor.h - * - * This source file is part of the FoundationDB open source project - * - * Copyright 2013-2022 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. - */ + * KeyBackedConfig.actor.h + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2022 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. + */ #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 -#include "fdbclient/TaskBucket.h" #include "fdbclient/KeyBackedTypes.h" #include "flow/actorcompiler.h" // has to be last include -FDB_DECLARE_BOOLEAN_PARAM(SetValidation); - -// 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 UidAndAbortedFlagT; -class KeyBackedTag : public KeyBackedProperty { -public: - KeyBackedTag() : KeyBackedProperty(StringRef()) {} - KeyBackedTag(std::string tagName, StringRef tagMapPrefix); - - Future cancel(Reference tr) { - std::string tag = tagName; - Key _tagMapPrefix = tagMapPrefix; - return map(get(tr), [tag, _tagMapPrefix, tr](Optional 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 TagMap; -// Map of tagName to {UID, aborted_flag} located in the fileRestorePrefixRange keyspace. -class TagUidMap : public KeyBackedMap { - ACTOR static Future> getAll_impl(TagUidMap* tagsMap, - Reference tr, - Snapshot snapshot); - -public: - TagUidMap(const StringRef& prefix) : TagMap("tag->uid/"_sr.withPrefix(prefix)), prefix(prefix) {} - - Future> getAll(Reference tr, - Snapshot snapshot = Snapshot::False) { - return getAll_impl(this, tr, snapshot); - } - - Key prefix; -}; - class KeyBackedConfig { public: - static struct { - static TaskParam uid() { return __FUNCTION__sr; } - } TaskParams; - KeyBackedConfig(StringRef prefix, UID uid = UID()) : uid(uid), prefix(prefix), configSpace(uidPrefixKey("uid->config/"_sr.withPrefix(prefix), uid)) {} - KeyBackedConfig(StringRef prefix, Reference task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {} - - Future toTask(Reference tr, - Reference 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 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::pack({ u, false })); - return Void(); - }); - } - KeyBackedProperty tag() { return configSpace.pack(__FUNCTION__sr); } UID getUid() { return uid; } Key getUidAsKey() { return BinaryWriter::toValue(uid, Unversioned()); } - void clear(Reference tr) { tr->clear(configSpace.range()); } + template + void clear(TrType tr) { + tr->clear(configSpace.range()); + } // lastError is a pair of error message and timestamp expressed as an int64_t KeyBackedProperty> lastError() { return configSpace.pack(__FUNCTION__sr); } @@ -126,23 +49,6 @@ public: return configSpace.pack(__FUNCTION__sr); } - // Updates the error per type map and the last error property - Future updateErrorInfo(Database cx, Error e, std::string message) { - // Avoid capture of this ptr - auto& copy = *this; - - return runRYWTransaction(cx, [=](Reference 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(); - }); - }); - } - protected: UID uid; Key prefix; @@ -150,4 +56,4 @@ protected: }; #include "flow/unactorcompiler.h" -#endif //FOUNDATIONDB_KEYBACKEDCONFIG_H +#endif // FOUNDATIONDB_KEYBACKEDCONFIG_H diff --git a/fdbclient/include/fdbclient/RunRYWTransaction.actor.h b/fdbclient/include/fdbclient/RunRYWTransaction.actor.h new file mode 100644 index 0000000000..de7bfee7b4 --- /dev/null +++ b/fdbclient/include/fdbclient/RunRYWTransaction.actor.h @@ -0,0 +1,85 @@ +/* + * RunRYWTransaction.actor.h + * + * This source file is part of the FoundationDB open source project + * + * Copyright 2013-2022 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. + */ + +#pragma once + +// When actually compiled (NO_INTELLISENSE), include the generated version of this file. In intellisense use the source +// version. +#if defined(NO_INTELLISENSE) && !defined(FDBCLIENT_RUNRYWTRANSACTION_ACTOR_G_H) +#define FDBCLIENT_RUNRYWTRANSACTION_ACTOR_G_H +#include "fdbclient/RunRYWTransaction.actor.g.h" +#elif !defined(FDBCLIENT_RUNRYWTRANSACTION_ACTOR_H) +#define FDBCLIENT_RUNRYWTRANSACTION_ACTOR_H + +#include + +#include "flow/flow.h" +#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/ReadYourWrites.h" +#include "flow/actorcompiler.h" // This must be the last #include. + +ACTOR template +Future()(Reference()).getValue())> runRYWTransaction( + Database cx, + Function func) { + state Reference tr(new ReadYourWritesTransaction(cx)); + loop { + try { + // func should be idempotent; otherwise, retry will get undefined result + state decltype(std::declval()(Reference()).getValue()) result = + wait(func(tr)); + wait(tr->commit()); + return result; + } catch (Error& e) { + wait(tr->onError(e)); + } + } +} + +ACTOR template +Future()(Reference()).getValue())> +runRYWTransactionFailIfLocked(Database cx, Function func) { + state Reference tr(new ReadYourWritesTransaction(cx)); + loop { + try { + state decltype(std::declval()(Reference()).getValue()) result = + wait(func(tr)); + wait(tr->commit()); + return result; + } catch (Error& e) { + if (e.code() == error_code_database_locked) + throw; + wait(tr->onError(e)); + } + } +} + +ACTOR template +Future()(Reference()).getValue())> runRYWTransactionNoRetry( + Database cx, + Function func) { + state Reference tr(new ReadYourWritesTransaction(cx)); + state decltype(std::declval()(Reference()).getValue()) result = wait(func(tr)); + wait(tr->commit()); + return result; +} + +#include "flow/unactorcompiler.h" +#endif diff --git a/fdbclient/include/fdbclient/RunTransaction.actor.h b/fdbclient/include/fdbclient/RunTransaction.actor.h index 83c8ab2223..fce0de83e6 100644 --- a/fdbclient/include/fdbclient/RunTransaction.actor.h +++ b/fdbclient/include/fdbclient/RunTransaction.actor.h @@ -31,27 +31,8 @@ #include #include "flow/flow.h" -#include "fdbclient/ReadYourWrites.h" #include "flow/actorcompiler.h" // This must be the last #include. -ACTOR template -Future()(Reference()).getValue())> runRYWTransaction( - Database cx, - Function func) { - state Reference tr(new ReadYourWritesTransaction(cx)); - loop { - try { - // func should be idempotent; otherwise, retry will get undefined result - state decltype(std::declval()(Reference()).getValue()) result = - wait(func(tr)); - wait(tr->commit()); - return result; - } catch (Error& e) { - wait(tr->onError(e)); - } - } -} - ACTOR template Future()(Reference()).getValue())> runTransaction( Reference db, @@ -70,33 +51,5 @@ Future()(Reference()) } } -ACTOR template -Future()(Reference()).getValue())> -runRYWTransactionFailIfLocked(Database cx, Function func) { - state Reference tr(new ReadYourWritesTransaction(cx)); - loop { - try { - state decltype(std::declval()(Reference()).getValue()) result = - wait(func(tr)); - wait(tr->commit()); - return result; - } catch (Error& e) { - if (e.code() == error_code_database_locked) - throw; - wait(tr->onError(e)); - } - } -} - -ACTOR template -Future()(Reference()).getValue())> runRYWTransactionNoRetry( - Database cx, - Function func) { - state Reference tr(new ReadYourWritesTransaction(cx)); - state decltype(std::declval()(Reference()).getValue()) result = wait(func(tr)); - wait(tr->commit()); - return result; -} - #include "flow/unactorcompiler.h" #endif diff --git a/fdbclient/include/fdbclient/StorageWiggleMetrics.actor.h b/fdbclient/include/fdbclient/StorageWiggleMetrics.actor.h index d945dc5be1..067a46dd1d 100644 --- a/fdbclient/include/fdbclient/StorageWiggleMetrics.actor.h +++ b/fdbclient/include/fdbclient/StorageWiggleMetrics.actor.h @@ -1,5 +1,5 @@ /* - * StorageWiggleMetrics.actor.h + * StorageWiggleMetrics.h * * This source file is part of the FoundationDB open source project * @@ -28,8 +28,10 @@ #include "fdbrpc/Smoother.h" #include "flow/ObjectSerializer.h" #include "flow/serialize.h" -#include "fdbclient/Status.h" -#include "flow/actorcompiler.h" // This must be the last #include. +#include "fdbclient/SystemData.h" +#include "fdbclient/KeyBackedConfig.actor.h" +#include "fdbclient/RunTransaction.actor.h" +#include "flow/actorcompiler.h" FDB_DECLARE_BOOLEAN_PARAM(PrimaryRegion); @@ -103,56 +105,6 @@ struct StorageWiggleMetrics { } }; -// read from DB -ACTOR template -Future> loadStorageWiggleMetrics(TxnType tr, PrimaryRegion primary) { - tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS); - tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE); - auto f = tr->get(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_STATS)); - Optional value = wait(safeThreadFutureToFuture(f)); - if (!value.present()) { - return Optional(); - } - return ObjectReader::fromStringRef(value.get(), IncludeVersion()); -} - -// update the serialized metrics when the perpetual wiggle is enabled -ACTOR template -Future updateStorageWiggleMetrics(TxnType tr, StorageWiggleMetrics metrics, PrimaryRegion primary) { - tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); - tr->setOption(FDBTransactionOptions::LOCK_AWARE); - auto f = tr->get(perpetualStorageWiggleKey); - Optional v = wait(safeThreadFutureToFuture(f)); - if (v.present() && v == "1"_sr) { - tr->set(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_STATS), - ObjectWriter::toValue(metrics, IncludeVersion())); - } else { - CODE_PROBE(true, "Intend to update StorageWiggleMetrics after PW disabled"); - } - return Void(); -} - -// set all fields except for smoothed durations to default values. If the metrics is not given, load from system key -// space -ACTOR template -Future resetStorageWiggleMetrics(TrType tr, - PrimaryRegion primary, - Optional metrics = Optional()) { - - tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); - tr->setOption(FDBTransactionOptions::LOCK_AWARE); - if (!metrics.present()) { - wait(store(metrics, loadStorageWiggleMetrics(tr, primary))); - } - - if (metrics.present()) { - metrics.get().reset(); - tr->set(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_STATS), - ObjectWriter::toValue(metrics.get(), IncludeVersion())); - } - return Void(); -} - struct StorageWiggleDelay { constexpr static FileIdentifier file_identifier = 102937; double delaySeconds = 0; @@ -164,58 +116,119 @@ struct StorageWiggleDelay { } }; +namespace { +// Persistent the total delay time to the database, and return accumulated delay time. ACTOR template -Future readPerpetualWiggleDelay(TrType tr, PrimaryRegion primary) { - tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS); +Future addPerpetualWiggleDelay_impl( + TrType tr, + KeyBackedObjectProperty delayProperty, + double secDelta) { + + state StorageWiggleDelay delayObj = wait(delayProperty.getD(tr, Snapshot::False)); + delayObj.delaySeconds += secDelta; + delayProperty.set(tr, delayObj); + + return delayObj.delaySeconds; +} + +// set all fields except for smoothed durations to default values. If the metrics is not given, load from system key +// space +ACTOR template +Future resetStorageWiggleMetrics_impl( + TrType tr, + KeyBackedObjectProperty metricsProperty, + Optional metrics) { + tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); tr->setOption(FDBTransactionOptions::LOCK_AWARE); - auto f = tr->get(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_DELAY)); - Optional v = wait(safeThreadFutureToFuture(f)); - StorageWiggleDelay delayObj; - if (v.present()) { - delayObj = BinaryReader::fromStringRef(v.get(), IncludeVersion()); + if (!metrics.present()) { + wait(store(metrics, metricsProperty.get(tr))); } - return delayObj; -} -// Persistent the total delay time to the database, and return accumulated delay time. -ACTOR template -Future addPerpetualWiggleDelay(TrType tr, PrimaryRegion primary, double secDelta) { - state double totalDelay = 0; - loop { - tr->reset(); - try { - tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); - state StorageWiggleDelay delayObj = wait(readPerpetualWiggleDelay(tr, primary)); - delayObj.delaySeconds += secDelta; - totalDelay = delayObj.delaySeconds; - tr->set(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_DELAY), - BinaryWriter::toValue(delayObj, IncludeVersion())); - wait(tr->commit()); - break; - } catch (Error& e) { - wait(tr->onError(e)); - } - } - return totalDelay; -} - -// Persistent the total delay time to the database, and return accumulated delay time. -ACTOR template -Future clearPerpetualWiggleDelay(TrType tr, PrimaryRegion primary) { - loop { - tr->reset(); - try { - tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); - tr->setOption(FDBTransactionOptions::LOCK_AWARE); - tr->clear(perpetualStorageWiggleKeyFor(primary, PerpetualWiggleKeyType::WIGGLE_DELAY)); - wait(tr->commit()); - break; - } catch (Error& e) { - wait(tr->onError(e)); - } + if (metrics.present()) { + metrics.get().reset(); + metricsProperty.set(tr, metrics.get()); } return Void(); } +} // namespace +// After 7.3, the perpetual wiggle related keys should use format "\xff/storageWiggle/[primary | remote]/[fieldName]" +class StorageWiggleData : public KeyBackedConfig { +public: + StorageWiggleData() : KeyBackedConfig(perpetualStorageWigglePrefix) {} + + auto perpetualWiggleSpeed() const { return KeyBackedProperty(perpetualStorageWiggleKey); } + + auto wigglingStorageServer(PrimaryRegion primaryDc) const { + Key mapPrefix = perpetualStorageWiggleIDPrefix.withSuffix(primaryDc ? "primary/"_sr : "remote/"_sr); + return KeyBackedObjectMap(mapPrefix, IncludeVersion()); + } + + auto storageWiggleMetrics(PrimaryRegion primaryDc) const { + Key key = perpetualStorageWiggleStatsPrefix.withSuffix(primaryDc ? "primary"_sr : "remote"_sr); + return KeyBackedObjectProperty(key, IncludeVersion()); + } + + auto storageWiggleDelay(PrimaryRegion primaryDc) const { + Key key = prefix.withSuffix(primaryDc ? "primary/"_sr : "remote/"_sr).withSuffix("wiggleDelay"_sr); + return KeyBackedObjectProperty(key, IncludeVersion()); + } + + // Persistent the total delay time to the database, and return accumulated delay time. + template + Future addPerpetualWiggleDelay(Reference db, PrimaryRegion primary, double secDelta) { + return runTransaction(db, [=, self = *this](Reference tr) { + tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); + tr->setOption(FDBTransactionOptions::LOCK_AWARE); + + return addPerpetualWiggleDelay_impl(tr, self.storageWiggleDelay(primary), secDelta); + }); + } + + // clear the persistent total delay in database + template + Future clearPerpetualWiggleDelay(Reference db, PrimaryRegion primary) { + return runTransaction(db, [=, self = *this](Reference tr) { + tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); + tr->setOption(FDBTransactionOptions::LOCK_AWARE); + self.storageWiggleDelay(primary).clear(tr); + return Future(Void()); + }); + } + + // set all fields except for smoothed durations to default values. If the metrics is not given, load from system key + // space + template + Future resetStorageWiggleMetrics(TrType tr, + PrimaryRegion primary, + Optional metrics = Optional()) { + return resetStorageWiggleMetrics_impl(tr, storageWiggleMetrics(primary), metrics); + } + + ACTOR template + static Future updateStorageWiggleMetrics_impl( + KeyBackedProperty wiggleSpeed, + KeyBackedObjectProperty storageMetrics, + TrType tr, + StorageWiggleMetrics metrics, + PrimaryRegion primary) { + tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS); + tr->setOption(FDBTransactionOptions::LOCK_AWARE); + Optional v = wait(wiggleSpeed.get(tr)); + if (v.present() && v == "1"_sr) { + storageMetrics.set(tr, metrics); + } else { + CODE_PROBE(true, "Intend to update StorageWiggleMetrics after PW disabled"); + } + return Void(); + } + + // update the serialized metrics when the perpetual wiggle is enabled + template + Future updateStorageWiggleMetrics(TrType tr, StorageWiggleMetrics metrics, PrimaryRegion primary) { + return updateStorageWiggleMetrics_impl( + perpetualWiggleSpeed(), storageWiggleMetrics(primary), tr, metrics, primary); + } +}; #include "flow/unactorcompiler.h" #endif \ No newline at end of file diff --git a/fdbclient/include/fdbclient/SystemData.h b/fdbclient/include/fdbclient/SystemData.h index e32e9a8917..2d2fa3b12b 100644 --- a/fdbclient/include/fdbclient/SystemData.h +++ b/fdbclient/include/fdbclient/SystemData.h @@ -277,11 +277,7 @@ extern const KeyRef perpetualStorageWiggleKey; extern const KeyRef perpetualStorageWiggleLocalityKey; extern const KeyRef perpetualStorageWiggleIDPrefix; extern const KeyRef perpetualStorageWiggleStatsPrefix; -// the final char is "/" -enum class PerpetualWigglePrefixType { STORAGE_ID }; -enum class PerpetualWiggleKeyType { WIGGLE_STATS, WIGGLE_DELAY }; -const Key perpetualStorageWigglePrefixFor(bool primaryDc, PerpetualWigglePrefixType type); -const Key perpetualStorageWiggleKeyFor(bool primaryDc, PerpetualWiggleKeyType type); +extern const KeyRef perpetualStorageWigglePrefix; // Change the value of this key to anything and that will trigger detailed data distribution team info log. extern const KeyRef triggerDDTeamInfoPrintKey; diff --git a/fdbclient/include/fdbclient/TaskBucket.h b/fdbclient/include/fdbclient/TaskBucket.h index ba122ac7a7..66c8d1dae7 100644 --- a/fdbclient/include/fdbclient/TaskBucket.h +++ b/fdbclient/include/fdbclient/TaskBucket.h @@ -28,7 +28,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbclient/NativeAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/Subspace.h" #include "fdbclient/KeyBackedTypes.h" diff --git a/fdbclient/include/fdbclient/TenantEntryCache.actor.h b/fdbclient/include/fdbclient/TenantEntryCache.actor.h index 06d6ff7bd3..a167581167 100644 --- a/fdbclient/include/fdbclient/TenantEntryCache.actor.h +++ b/fdbclient/include/fdbclient/TenantEntryCache.actor.h @@ -29,7 +29,7 @@ #include "fdbclient/DatabaseContext.h" #include "fdbclient/FDBOptions.g.h" #include "fdbclient/FDBTypes.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/Tenant.h" #include "fdbclient/TenantManagement.actor.h" #include "fdbclient/Knobs.h" diff --git a/fdbserver/DDTeamCollection.actor.cpp b/fdbserver/DDTeamCollection.actor.cpp index 530baf88e8..19202911f5 100644 --- a/fdbserver/DDTeamCollection.actor.cpp +++ b/fdbserver/DDTeamCollection.actor.cpp @@ -1945,9 +1945,10 @@ public: } ACTOR static Future updateNextWigglingStorageID(DDTeamCollection* self) { - state Key writeKey = perpetualStorageWigglePrefixFor(self->primary, PerpetualWigglePrefixType::STORAGE_ID); - state KeyBackedObjectMap metadataMap(writeKey, - IncludeVersion()); + state StorageWiggleData wiggleState; + state KeyBackedObjectMap metadataMap = + wiggleState.wigglingStorageServer(PrimaryRegion(self->primary)); + state UID nextId = wait(self->getNextWigglingServerID()); state StorageWiggleValue value(nextId); state Reference tr(new ReadYourWritesTransaction(self->dbContext())); @@ -1976,15 +1977,17 @@ public: wait(delay(SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY)); return Void(); } - state Reference tr = makeReference(self->dbContext()); state double nextDelay = 60.0; while (true) { wait(delay(nextDelay)); - double totalDelay = wait(addPerpetualWiggleDelay(tr, PrimaryRegion(self->primary), nextDelay)); + + double totalDelay = wait(self->storageWiggler->wiggleData.addPerpetualWiggleDelay( + self->dbContext().getReference(), PrimaryRegion(self->primary), nextDelay)); nextDelay = std::min(SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY - totalDelay, 60.0); if (totalDelay >= SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY) { - wait(clearPerpetualWiggleDelay(tr, PrimaryRegion(self->primary))); + wait(self->storageWiggler->wiggleData.clearPerpetualWiggleDelay(self->dbContext().getReference(), + PrimaryRegion(self->primary))); return Void(); } } @@ -1995,7 +1998,7 @@ public: state Promise avgShardBytes; while (takeRest) { // a minimal delay to avoid excluding and including SS too fast - wait(delay(SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY)); + wait(waitPerpetualWiggleDelay(self)); avgShardBytes.reset(); self->getAverageShardBytes.send(avgShardBytes); @@ -2076,8 +2079,9 @@ public: ACTOR static Future perpetualStorageWiggler(DDTeamCollection* self, AsyncVar* stopSignal, PromiseStream finishStorageWiggleSignal) { - state KeyBackedObjectMap metadataMap( - perpetualStorageWigglePrefixFor(self->primary, PerpetualWigglePrefixType::STORAGE_ID), IncludeVersion()); + state StorageWiggleData wiggleState; + state KeyBackedObjectMap metadataMap = + wiggleState.wigglingStorageServer(PrimaryRegion(self->primary)); state Future nextFuture = Never(); state Future moveFinishFuture = Never(); diff --git a/fdbserver/DataDistribution.actor.cpp b/fdbserver/DataDistribution.actor.cpp index 45d6e428f1..c0731df4b8 100644 --- a/fdbserver/DataDistribution.actor.cpp +++ b/fdbserver/DataDistribution.actor.cpp @@ -27,7 +27,7 @@ #include "fdbclient/FDBTypes.h" #include "fdbclient/Knobs.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/StorageServerInterface.h" #include "fdbclient/SystemData.h" #include "fdbclient/Tenant.h" @@ -182,24 +182,14 @@ Future StorageWiggler::resetStats() { metrics.reset(); return runRYWTransaction( teamCollection->dbContext(), [this](Reference tr) -> Future { - return resetStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary()), metrics); + return wiggleData.resetStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary()), metrics); }); } Future StorageWiggler::restoreStats() { - auto& metricsRef = metrics; - auto assignFunc = [&metricsRef](Optional v) { - if (v.present()) { - metricsRef = v.get(); - } - return Void(); - }; - auto readFuture = - runRYWTransaction(teamCollection->dbContext(), - [this](Reference tr) -> Future> { - return loadStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary())); - }); - return map(readFuture, assignFunc); + auto readFuture = wiggleData.storageWiggleMetrics(PrimaryRegion(teamCollection->isPrimary())) + .getD(teamCollection->dbContext().getReference(), Snapshot::False, metrics); + return store(metrics, readFuture); } Future StorageWiggler::startWiggle() { @@ -209,7 +199,7 @@ Future StorageWiggler::startWiggle() { } return runRYWTransaction( teamCollection->dbContext(), [this](Reference tr) -> Future { - return updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary())); + return wiggleData.updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary())); }); } @@ -227,7 +217,7 @@ Future StorageWiggler::finishWiggle() { } return runRYWTransaction( teamCollection->dbContext(), [this](Reference tr) -> Future { - return updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary())); + return wiggleData.updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary())); }); } diff --git a/fdbserver/OldTLogServer_6_0.actor.cpp b/fdbserver/OldTLogServer_6_0.actor.cpp index f1b3381f9e..e73793e344 100644 --- a/fdbserver/OldTLogServer_6_0.actor.cpp +++ b/fdbserver/OldTLogServer_6_0.actor.cpp @@ -23,7 +23,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/Notified.h" #include "fdbclient/KeyRangeMap.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/SystemData.h" #include "fdbserver/WorkerInterface.actor.h" #include "fdbserver/TLogInterface.h" diff --git a/fdbserver/OldTLogServer_6_2.actor.cpp b/fdbserver/OldTLogServer_6_2.actor.cpp index 58c1f95555..8ffd384571 100644 --- a/fdbserver/OldTLogServer_6_2.actor.cpp +++ b/fdbserver/OldTLogServer_6_2.actor.cpp @@ -24,7 +24,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/Notified.h" #include "fdbclient/KeyRangeMap.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/SystemData.h" #include "fdbserver/WorkerInterface.actor.h" #include "fdbserver/TLogInterface.h" diff --git a/fdbserver/QuietDatabase.actor.cpp b/fdbserver/QuietDatabase.actor.cpp index 8b01c58fdb..6551bc4b16 100644 --- a/fdbserver/QuietDatabase.actor.cpp +++ b/fdbserver/QuietDatabase.actor.cpp @@ -31,7 +31,7 @@ #include "fdbclient/DatabaseContext.h" #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/Knobs.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbserver/WorkerInterface.actor.h" diff --git a/fdbserver/RestoreRoleCommon.actor.cpp b/fdbserver/RestoreRoleCommon.actor.cpp index e52dd1ee7a..b6b57c0d1d 100644 --- a/fdbserver/RestoreRoleCommon.actor.cpp +++ b/fdbserver/RestoreRoleCommon.actor.cpp @@ -21,7 +21,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/MutationList.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/RestoreUtil.h" #include "fdbserver/RestoreRoleCommon.actor.h" diff --git a/fdbserver/Status.actor.cpp b/fdbserver/Status.actor.cpp index 05f5ba5123..ec680be5c9 100644 --- a/fdbserver/Status.actor.cpp +++ b/fdbserver/Status.actor.cpp @@ -2914,13 +2914,16 @@ ACTOR Future, Optional tr(new ReadYourWritesTransaction(cx)); state Optional primaryV; state Optional remoteV; + state StorageWiggleData wiggleState; loop { try { if (use_system_priority) { tr->setOption(FDBTransactionOptions::PRIORITY_SYSTEM_IMMEDIATE); } - wait(store(primaryV, loadStorageWiggleMetrics(tr, PrimaryRegion(true))) && - store(remoteV, loadStorageWiggleMetrics(tr, PrimaryRegion(false)))); + tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS); + tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE); + wait(store(primaryV, wiggleState.storageWiggleMetrics(PrimaryRegion(true)).get(tr)) && + store(remoteV, wiggleState.storageWiggleMetrics(PrimaryRegion(false)).get(tr))); return std::make_pair(primaryV, remoteV); } catch (Error& e) { wait(tr->onError(e)); diff --git a/fdbserver/TLogServer.actor.cpp b/fdbserver/TLogServer.actor.cpp index 07a7ff548e..d899115239 100644 --- a/fdbserver/TLogServer.actor.cpp +++ b/fdbserver/TLogServer.actor.cpp @@ -23,7 +23,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbclient/Notified.h" #include "fdbclient/KeyRangeMap.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/SystemData.h" #include "fdbclient/FDBTypes.h" #include "fdbserver/WorkerInterface.actor.h" diff --git a/fdbserver/include/fdbserver/DDTeamCollection.h b/fdbserver/include/fdbserver/DDTeamCollection.h index 49e522a640..4ce10de722 100644 --- a/fdbserver/include/fdbserver/DDTeamCollection.h +++ b/fdbserver/include/fdbserver/DDTeamCollection.h @@ -30,7 +30,7 @@ #include "fdbclient/SystemData.h" #include "fdbclient/DatabaseContext.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbrpc/Replication.h" #include "fdbserver/DataDistribution.actor.h" #include "fdbserver/FDBExecHelper.actor.h" diff --git a/fdbserver/include/fdbserver/DataDistribution.actor.h b/fdbserver/include/fdbserver/DataDistribution.actor.h index 8679b6d9b5..3327825644 100644 --- a/fdbserver/include/fdbserver/DataDistribution.actor.h +++ b/fdbserver/include/fdbserver/DataDistribution.actor.h @@ -28,7 +28,7 @@ #include "fdbserver/MoveKeys.actor.h" #include "fdbserver/TenantCache.h" #include "fdbserver/TCInfo.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/DDTxnProcessor.h" #include "fdbserver/ShardsAffectedByTeamFailure.h" #include "fdbserver/Knobs.h" @@ -567,6 +567,8 @@ struct StorageWiggler : ReferenceCounted { enum State : uint8_t { INVALID = 0, RUN = 1, PAUSE = 2 }; DDTeamCollection const* teamCollection; + StorageWiggleData wiggleData; // the wiggle related data persistent in database + StorageWiggleMetrics metrics; AsyncVar stopWiggleSignal; // data structures diff --git a/fdbserver/include/fdbserver/RestoreCommon.actor.h b/fdbserver/include/fdbserver/RestoreCommon.actor.h index 4b4dc6f0f9..4f8507fdc0 100644 --- a/fdbserver/include/fdbserver/RestoreCommon.actor.h +++ b/fdbserver/include/fdbserver/RestoreCommon.actor.h @@ -54,10 +54,10 @@ struct RestoreFileFR; // Restore.actor.h and implementation in RestoreCommon.actor.cpp, so that we can use in both the existing restore and // the new fast restore subsystems. We use RestoreConfig as a Reference, which leads to some // non-functional changes in RestoreConfig -class RestoreConfigFR : public KeyBackedConfig, public ReferenceCounted { +class RestoreConfigFR : public KeyBackedTaskConfig, public ReferenceCounted { public: - RestoreConfigFR(UID uid = UID()) : KeyBackedConfig(fileRestorePrefixRange.begin, uid) {} - RestoreConfigFR(Reference task) : KeyBackedConfig(fileRestorePrefixRange.begin, task) {} + RestoreConfigFR(UID uid = UID()) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, uid) {} + RestoreConfigFR(Reference task) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, task) {} KeyBackedProperty stateEnum(); diff --git a/fdbserver/workloads/AtomicOpsApiCorrectness.actor.cpp b/fdbserver/workloads/AtomicOpsApiCorrectness.actor.cpp index c273f947ae..8cc919a792 100644 --- a/fdbserver/workloads/AtomicOpsApiCorrectness.actor.cpp +++ b/fdbserver/workloads/AtomicOpsApiCorrectness.actor.cpp @@ -20,7 +20,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "flow/actorcompiler.h" // This must be the last #include. diff --git a/fdbserver/workloads/AutomaticIdempotencyWorkload.actor.cpp b/fdbserver/workloads/AutomaticIdempotencyWorkload.actor.cpp index c2a82782ed..e0e6232ce6 100644 --- a/fdbserver/workloads/AutomaticIdempotencyWorkload.actor.cpp +++ b/fdbserver/workloads/AutomaticIdempotencyWorkload.actor.cpp @@ -20,7 +20,7 @@ #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "flow/actorcompiler.h" // This must be the last #include. diff --git a/fdbserver/workloads/BackupAndParallelRestoreCorrectness.actor.cpp b/fdbserver/workloads/BackupAndParallelRestoreCorrectness.actor.cpp index 4f8dbc23bb..047040cd2b 100644 --- a/fdbserver/workloads/BackupAndParallelRestoreCorrectness.actor.cpp +++ b/fdbserver/workloads/BackupAndParallelRestoreCorrectness.actor.cpp @@ -23,7 +23,7 @@ #include "fdbclient/BackupContainer.h" #include "fdbclient/ManagementAPI.actor.h" #include "fdbserver/RestoreWorkerInterface.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/RestoreCommon.actor.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbserver/workloads/BulkSetup.actor.h" diff --git a/fdbserver/workloads/ClientTransactionProfileCorrectness.actor.cpp b/fdbserver/workloads/ClientTransactionProfileCorrectness.actor.cpp index fbee454a9d..9efde89269 100644 --- a/fdbserver/workloads/ClientTransactionProfileCorrectness.actor.cpp +++ b/fdbserver/workloads/ClientTransactionProfileCorrectness.actor.cpp @@ -22,7 +22,7 @@ #include "fdbserver/ServerDBInfo.h" #include "fdbclient/GlobalConfig.actor.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/Tuple.h" #include "flow/actorcompiler.h" // has to be last include diff --git a/fdbserver/workloads/ConfigureDatabase.actor.cpp b/fdbserver/workloads/ConfigureDatabase.actor.cpp index 60c339cea9..8938d31c35 100644 --- a/fdbserver/workloads/ConfigureDatabase.actor.cpp +++ b/fdbserver/workloads/ConfigureDatabase.actor.cpp @@ -21,7 +21,7 @@ #include "fdbclient/NativeAPI.actor.h" #include "fdbserver/TesterInterface.actor.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbserver/Knobs.h" #include "fdbserver/workloads/workloads.actor.h" #include "fdbrpc/simulator.h" diff --git a/fdbserver/workloads/DifferentClustersSameRV.actor.cpp b/fdbserver/workloads/DifferentClustersSameRV.actor.cpp index 39873ac490..95774464b5 100644 --- a/fdbserver/workloads/DifferentClustersSameRV.actor.cpp +++ b/fdbserver/workloads/DifferentClustersSameRV.actor.cpp @@ -20,7 +20,7 @@ #include "fdbclient/ClusterConnectionMemoryRecord.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/TenantManagement.actor.h" #include "fdbrpc/simulator.h" #include "fdbserver/workloads/workloads.actor.h" diff --git a/fdbserver/workloads/MetaclusterManagementWorkload.actor.cpp b/fdbserver/workloads/MetaclusterManagementWorkload.actor.cpp index 56c988243f..61c5e23be8 100644 --- a/fdbserver/workloads/MetaclusterManagementWorkload.actor.cpp +++ b/fdbserver/workloads/MetaclusterManagementWorkload.actor.cpp @@ -26,7 +26,7 @@ #include "fdbclient/Metacluster.h" #include "fdbclient/MetaclusterManagement.actor.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/TenantManagement.actor.h" #include "fdbclient/ThreadSafeTransaction.h" #include "fdbrpc/simulator.h" diff --git a/fdbserver/workloads/PerpetualWiggleStatsWorkload.actor.cpp b/fdbserver/workloads/PerpetualWiggleStatsWorkload.actor.cpp index ce8c1fcf10..45d00275d4 100644 --- a/fdbserver/workloads/PerpetualWiggleStatsWorkload.actor.cpp +++ b/fdbserver/workloads/PerpetualWiggleStatsWorkload.actor.cpp @@ -169,7 +169,8 @@ struct PerpetualWiggleStatsWorkload : public TestWorkload { self->lastMetrics = getRandomWiggleMetrics(); auto& lastMetrics = self->lastMetrics; wait(success(runRYWTransaction(cx, [&lastMetrics](Reference tr) -> Future { - return updateStorageWiggleMetrics(tr, lastMetrics, PrimaryRegion(true)); + StorageWiggleData wiggleData; + return wiggleData.updateStorageWiggleMetrics(tr, lastMetrics, PrimaryRegion(true)); }))); return Void(); } diff --git a/fdbserver/workloads/SkewedReadWrite.actor.cpp b/fdbserver/workloads/SkewedReadWrite.actor.cpp index ba37e7ac42..437ee3a048 100644 --- a/fdbserver/workloads/SkewedReadWrite.actor.cpp +++ b/fdbserver/workloads/SkewedReadWrite.actor.cpp @@ -31,7 +31,7 @@ #include "fdbserver/workloads/ReadWriteWorkload.actor.h" #include "fdbclient/ReadYourWrites.h" #include "flow/TDMetric.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "flow/actorcompiler.h" // This must be the last #include. struct SkewedReadWriteWorkload : ReadWriteCommon { diff --git a/fdbserver/workloads/SuspendProcesses.actor.cpp b/fdbserver/workloads/SuspendProcesses.actor.cpp index 5fa2ecfbe6..490de3215a 100644 --- a/fdbserver/workloads/SuspendProcesses.actor.cpp +++ b/fdbserver/workloads/SuspendProcesses.actor.cpp @@ -25,7 +25,7 @@ #include "fdbclient/Status.h" #include "fdbclient/StatusClient.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "flow/actorcompiler.h" // has to be last include struct SuspendProcessesWorkload : TestWorkload { diff --git a/fdbserver/workloads/TenantManagementWorkload.actor.cpp b/fdbserver/workloads/TenantManagementWorkload.actor.cpp index a7c6100214..9a1a495b53 100644 --- a/fdbserver/workloads/TenantManagementWorkload.actor.cpp +++ b/fdbserver/workloads/TenantManagementWorkload.actor.cpp @@ -28,7 +28,7 @@ #include "fdbclient/KeyBackedTypes.h" #include "fdbclient/MetaclusterManagement.actor.h" #include "fdbclient/ReadYourWrites.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "fdbclient/Tenant.h" #include "fdbclient/TenantManagement.actor.h" #include "fdbclient/TenantSpecialKeys.actor.h" diff --git a/fdbserver/workloads/ThreadSafety.actor.cpp b/fdbserver/workloads/ThreadSafety.actor.cpp index 95d6858fd2..b052a1c7d4 100644 --- a/fdbserver/workloads/ThreadSafety.actor.cpp +++ b/fdbserver/workloads/ThreadSafety.actor.cpp @@ -21,7 +21,6 @@ #include "fdbrpc/simulator.h" #include "flow/DeterministicRandom.h" #include "fdbserver/TesterInterface.actor.h" -#include "fdbserver/QuietDatabase.h" #include "fdbserver/ServerDBInfo.h" #include "fdbclient/ThreadSafeTransaction.h" #include "fdbclient/MultiVersionTransaction.h" diff --git a/fdbserver/workloads/TriggerRecovery.actor.cpp b/fdbserver/workloads/TriggerRecovery.actor.cpp index 94c338e390..9ce082bf40 100644 --- a/fdbserver/workloads/TriggerRecovery.actor.cpp +++ b/fdbserver/workloads/TriggerRecovery.actor.cpp @@ -23,7 +23,7 @@ #include "fdbclient/Status.h" #include "fdbclient/StatusClient.h" #include "fdbclient/ManagementAPI.actor.h" -#include "fdbclient/RunTransaction.actor.h" +#include "fdbclient/RunRYWTransaction.actor.h" #include "flow/actorcompiler.h" // has to be last include struct TriggerRecoveryLoopWorkload : TestWorkload {