Merge pull request #9012 from sfc-gh-xwang/feature/main/wiggleDelay

Persist accumulated wiggle delay
This commit is contained in:
Xiaoxi Wang 2023-01-04 16:14:09 -08:00 committed by GitHub
commit 8266f52dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 352 additions and 189 deletions

View File

@ -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"

View File

@ -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 <algorithm>
#include <cinttypes>
#include <time.h>

View File

@ -154,10 +154,10 @@ KeyBackedTag::KeyBackedTag(std::string tagName, StringRef tagMapPrefix)
: KeyBackedProperty<UidAndAbortedFlagT>(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> task) : KeyBackedConfig(fileRestorePrefixRange.begin, task) {}
RestoreConfig(UID uid = UID()) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, uid) {}
RestoreConfig(Reference<Task> task) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, task) {}
KeyBackedProperty<ERestoreState> stateEnum() { return configSpace.pack(__FUNCTION__sr); }
Future<StringRef> stateText(Reference<ReadYourWritesTransaction> tr) {
@ -1285,7 +1285,7 @@ ACTOR Future<Void> checkTaskVersion(Database cx, Reference<Task> 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,

View File

@ -8647,9 +8647,10 @@ Future<Version> DatabaseContext::verifyBlobRange(const KeyRange& range,
ACTOR Future<std::vector<std::pair<UID, StorageWiggleValue>>> readStorageWiggleValues(Database cx,
bool primary,
bool use_system_priority) {
state const Key readKey = perpetualStorageWiggleIDPrefix.withSuffix(primary ? "primary/"_sr : "remote/"_sr);
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap(readKey,
IncludeVersion());
state StorageWiggleData wiggleState;
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap =
wiggleState.wigglingStorageServer(PrimaryRegion(primary));
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
state KeyBackedRangeResult<std::pair<UID, StorageWiggleValue>> res;

View File

@ -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"
@ -868,8 +867,11 @@ const KeyRef configKeysPrefix = configKeys.begin;
const KeyRef perpetualStorageWiggleKey("\xff/conf/perpetual_storage_wiggle"_sr);
const KeyRef perpetualStorageWiggleLocalityKey("\xff/conf/perpetual_storage_wiggle_locality"_sr);
const KeyRef perpetualStorageWiggleIDPrefix("\xff/storageWiggleID/"_sr); // withSuffix /primary or /remote
// 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]". 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);
const KeyRef triggerDDTeamInfoPrintKey("\xff/triggerDDTeamInfoPrint"_sr);

View File

@ -633,34 +633,39 @@ public:
Key prefix;
};
static inline KeyBackedTag makeRestoreTag(std::string tagName) {
return KeyBackedTag(tagName, fileRestorePrefixRange.begin);
}
class KeyBackedTaskConfig : public KeyBackedStruct {
protected:
UID uid;
Subspace configSpace;
static inline KeyBackedTag makeBackupTag(std::string tagName) {
return KeyBackedTag(tagName, fileBackupPrefixRange.begin);
}
static inline Future<std::vector<KeyBackedTag>> getAllRestoreTags(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return TagUidMap(fileRestorePrefixRange.begin).getAll(tr, snapshot);
}
static inline Future<std::vector<KeyBackedTag>> getAllBackupTags(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return TagUidMap(fileBackupPrefixRange.begin).getAll(tr, snapshot);
}
class KeyBackedConfig {
public:
static struct {
static TaskParam<UID> uid() { return __FUNCTION__sr; }
} TaskParams;
KeyBackedConfig(StringRef prefix, UID uid = UID())
: uid(uid), prefix(prefix), configSpace(uidPrefixKey("uid->config/"_sr.withPrefix(prefix), uid)) {}
KeyBackedTaskConfig(StringRef prefix, UID uid = UID())
: KeyBackedStruct(prefix), uid(uid), configSpace(uidPrefixKey("uid->config/"_sr.withPrefix(prefix), uid)) {}
KeyBackedConfig(StringRef prefix, Reference<Task> task) : KeyBackedConfig(prefix, TaskParams.uid().get(task)) {}
KeyBackedTaskConfig(StringRef prefix, Reference<Task> task)
: KeyBackedTaskConfig(prefix, TaskParams.uid().get(task)) {}
KeyBackedProperty<std::string> tag() { return configSpace.pack(__FUNCTION__sr); }
UID getUid() { return uid; }
Key getUidAsKey() { return BinaryWriter::toValue(uid, Unversioned()); }
template <class TrType>
void clear(TrType tr) {
tr->clear(configSpace.range());
}
// lastError is a pair of error message and timestamp expressed as an int64_t
KeyBackedProperty<std::pair<std::string, Version>> lastError() { return configSpace.pack(__FUNCTION__sr); }
KeyBackedMap<int64_t, std::pair<std::string, Version>> lastErrorPerType() {
return configSpace.pack(__FUNCTION__sr);
}
Future<Void> toTask(Reference<ReadYourWritesTransaction> tr,
Reference<Task> task,
@ -687,21 +692,6 @@ public:
});
}
KeyBackedProperty<std::string> tag() { return configSpace.pack(__FUNCTION__sr); }
UID getUid() { return uid; }
Key getUidAsKey() { return BinaryWriter::toValue(uid, Unversioned()); }
void clear(Reference<ReadYourWritesTransaction> tr) { tr->clear(configSpace.range()); }
// lastError is a pair of error message and timestamp expressed as an int64_t
KeyBackedProperty<std::pair<std::string, Version>> lastError() { return configSpace.pack(__FUNCTION__sr); }
KeyBackedMap<int64_t, std::pair<std::string, Version>> lastErrorPerType() {
return configSpace.pack(__FUNCTION__sr);
}
// 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
@ -718,13 +708,26 @@ public:
});
});
}
protected:
UID uid;
Key prefix;
Subspace configSpace;
};
static inline KeyBackedTag makeRestoreTag(std::string tagName) {
return KeyBackedTag(tagName, fileRestorePrefixRange.begin);
}
static inline KeyBackedTag makeBackupTag(std::string tagName) {
return KeyBackedTag(tagName, fileBackupPrefixRange.begin);
}
static inline Future<std::vector<KeyBackedTag>> getAllRestoreTags(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return TagUidMap(fileRestorePrefixRange.begin).getAll(tr, snapshot);
}
static inline Future<std::vector<KeyBackedTag>> getAllBackupTags(Reference<ReadYourWritesTransaction> tr,
Snapshot snapshot = Snapshot::False) {
return TagUidMap(fileBackupPrefixRange.begin).getAll(tr, snapshot);
}
template <>
inline Standalone<StringRef> TupleCodec<Reference<IBackupContainer>>::pack(Reference<IBackupContainer> const& bc) {
Tuple tuple = Tuple::makeTuple(bc->getURL());
@ -763,10 +766,10 @@ inline Reference<IBackupContainer> TupleCodec<Reference<IBackupContainer>>::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> task) : KeyBackedConfig(fileBackupPrefixRange.begin, task) {}
BackupConfig(UID uid = UID()) : KeyBackedTaskConfig(fileBackupPrefixRange.begin, uid) {}
BackupConfig(Reference<Task> task) : KeyBackedTaskConfig(fileBackupPrefixRange.begin, task) {}
// rangeFileMap maps a keyrange file's End to its Begin and Filename
struct RangeSlice {

View File

@ -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"

View File

@ -535,8 +535,9 @@ Future<ConfigurationResult> changeConfig(Reference<DB> db, std::map<std::string,
}
if (!creating && resetPPWStats) {
wait(resetStorageWiggleMetrics(tr, PrimaryRegion(true)));
wait(resetStorageWiggleMetrics(tr, PrimaryRegion(false)));
state StorageWiggleData wiggleData;
wait(wiggleData.resetStorageWiggleMetrics(tr, PrimaryRegion(true)));
wait(wiggleData.resetStorageWiggleMetrics(tr, PrimaryRegion(false)));
}
tr->addReadConflictRange(singleKeyRange(moveKeysLockOwnerKey));

View File

@ -700,3 +700,13 @@ public:
KeyRange subspace;
};
// all fields are under prefix, the schema is like prefix/"packed key"/"packed key2"
class KeyBackedStruct {
public:
KeyBackedStruct(StringRef prefix) : prefix(prefix), rootSpace(prefix) {}
protected:
Key prefix;
Subspace rootSpace;
};

View File

@ -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 <utility>
#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 <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())> runRYWTransaction(
Database cx,
Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
loop {
try {
// func should be idempotent; otherwise, retry will get undefined result
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue()) result =
wait(func(tr));
wait(tr->commit());
return result;
} catch (Error& e) {
wait(tr->onError(e));
}
}
}
ACTOR template <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())>
runRYWTransactionFailIfLocked(Database cx, Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
loop {
try {
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).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 <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())> runRYWTransactionNoRetry(
Database cx,
Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue()) result = wait(func(tr));
wait(tr->commit());
return result;
}
#include "flow/unactorcompiler.h"
#endif

View File

@ -31,27 +31,8 @@
#include <utility>
#include "flow/flow.h"
#include "fdbclient/ReadYourWrites.h"
#include "flow/actorcompiler.h" // This must be the last #include.
ACTOR template <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())> runRYWTransaction(
Database cx,
Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
loop {
try {
// func should be idempotent; otherwise, retry will get undefined result
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue()) result =
wait(func(tr));
wait(tr->commit());
return result;
} catch (Error& e) {
wait(tr->onError(e));
}
}
}
ACTOR template <class Function, class DB>
Future<decltype(std::declval<Function>()(Reference<typename DB::TransactionT>()).getValue())> runTransaction(
Reference<DB> db,
@ -70,33 +51,5 @@ Future<decltype(std::declval<Function>()(Reference<typename DB::TransactionT>())
}
}
ACTOR template <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())>
runRYWTransactionFailIfLocked(Database cx, Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
loop {
try {
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).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 <class Function>
Future<decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue())> runRYWTransactionNoRetry(
Database cx,
Function func) {
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
state decltype(std::declval<Function>()(Reference<ReadYourWritesTransaction>()).getValue()) result = wait(func(tr));
wait(tr->commit());
return result;
}
#include "flow/unactorcompiler.h"
#endif

View File

@ -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/KeyBackedTypes.h"
#include "fdbclient/RunTransaction.actor.h"
#include "flow/actorcompiler.h"
FDB_DECLARE_BOOLEAN_PARAM(PrimaryRegion);
@ -103,55 +105,142 @@ struct StorageWiggleMetrics {
}
};
// read from DB
ACTOR template <typename TxnType>
Future<Optional<StorageWiggleMetrics>> loadStorageWiggleMetrics(TxnType tr, PrimaryRegion primary) {
tr->setOption(FDBTransactionOptions::READ_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::READ_LOCK_AWARE);
auto f = tr->get(perpetualStorageWiggleStatsPrefix.withSuffix(primary ? "primary"_sr : "remote"_sr));
Optional<Value> value = wait(safeThreadFutureToFuture(f));
if (!value.present()) {
return Optional<StorageWiggleMetrics>();
}
return ObjectReader::fromStringRef<StorageWiggleMetrics>(value.get(), IncludeVersion());
}
struct StorageWiggleDelay {
constexpr static FileIdentifier file_identifier = 102937;
double delaySeconds = 0;
explicit StorageWiggleDelay(double sec = 0) : delaySeconds(sec) {}
// update the serialized metrics when the perpetual wiggle is enabled
ACTOR template <typename TxnType>
Future<Void> updateStorageWiggleMetrics(TxnType tr, StorageWiggleMetrics metrics, PrimaryRegion primary) {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
auto f = tr->get(perpetualStorageWiggleKey);
Optional<Value> v = wait(safeThreadFutureToFuture(f));
if (v.present() && v == "1"_sr) {
tr->set(perpetualStorageWiggleStatsPrefix.withSuffix(primary ? "primary"_sr : "remote"_sr),
ObjectWriter::toValue(metrics, IncludeVersion()));
} else {
CODE_PROBE(true, "Intend to update StorageWiggleMetrics after PW disabled");
template <class Ar>
void serialize(Ar& ar) {
serializer(ar, delaySeconds);
}
return Void();
};
namespace {
// Persistent the total delay time to the database, and return accumulated delay time.
ACTOR template <class TrType>
Future<double> addPerpetualWiggleDelay_impl(
TrType tr,
KeyBackedObjectProperty<StorageWiggleDelay, decltype(IncludeVersion())> 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 <class TrType>
Future<Void> resetStorageWiggleMetrics(TrType tr,
PrimaryRegion primary,
Optional<StorageWiggleMetrics> metrics = Optional<StorageWiggleMetrics>()) {
Future<Void> resetStorageWiggleMetrics_impl(
TrType tr,
KeyBackedObjectProperty<StorageWiggleMetrics, decltype(IncludeVersion())> metricsProperty,
Optional<StorageWiggleMetrics> metrics) {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
if (!metrics.present()) {
wait(store(metrics, loadStorageWiggleMetrics(tr, primary)));
wait(store(metrics, metricsProperty.get(tr)));
}
if (metrics.present()) {
metrics.get().reset();
tr->set(perpetualStorageWiggleStatsPrefix.withSuffix(primary ? "primary"_sr : "remote"_sr),
ObjectWriter::toValue(metrics.get(), IncludeVersion()));
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 {
protected:
Key prefix;
public:
struct DataForDc : public KeyBackedStruct {
DataForDc(StringRef prefix) : KeyBackedStruct(prefix) {}
auto storageWiggleDelay() const {
auto key = rootSpace.pack("storageWiggleDelay"_sr);
return KeyBackedObjectProperty<StorageWiggleDelay, decltype(IncludeVersion())>(key, IncludeVersion());
}
};
StorageWiggleData() : prefix(perpetualStorageWigglePrefix) {}
auto perpetualWiggleSpeed() const { return KeyBackedProperty<Value, NullCodec>(perpetualStorageWiggleKey); }
auto wigglingStorageServer(PrimaryRegion primaryDc) const {
Key mapPrefix = perpetualStorageWiggleIDPrefix.withSuffix(primaryDc ? "primary/"_sr : "remote/"_sr);
return KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())>(mapPrefix, IncludeVersion());
}
auto storageWiggleMetrics(PrimaryRegion primaryDc) const {
Key key = perpetualStorageWiggleStatsPrefix.withSuffix(primaryDc ? "primary"_sr : "remote"_sr);
return KeyBackedObjectProperty<StorageWiggleMetrics, decltype(IncludeVersion())>(key, IncludeVersion());
}
DataForDc forDc(PrimaryRegion primaryDc) const {
return DataForDc(primaryDc ? prefix.withSuffix("primary/"_sr) : prefix.withSuffix("remote/"_sr));
}
// Persistent the total delay time to the database, and return accumulated delay time.
template <class DB>
Future<double> addPerpetualWiggleDelay(Reference<DB> db, PrimaryRegion primary, double secDelta) {
return runTransaction(db, [=, self = *this](Reference<typename DB::TransactionT> tr) {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
return addPerpetualWiggleDelay_impl(tr, self.forDc(primary).storageWiggleDelay(), secDelta);
});
}
// clear the persistent total delay in database
template <class DB>
Future<Void> clearPerpetualWiggleDelay(Reference<DB> db, PrimaryRegion primary) {
return runTransaction(db, [=, self = *this](Reference<typename DB::TransactionT> tr) {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
self.forDc(primary).storageWiggleDelay().clear(tr);
return Future<Void>(Void());
});
}
// set all fields except for smoothed durations to default values. If the metrics is not given, load from system key
// space
template <class TrType>
Future<Void> resetStorageWiggleMetrics(TrType tr,
PrimaryRegion primary,
Optional<StorageWiggleMetrics> metrics = Optional<StorageWiggleMetrics>()) {
return resetStorageWiggleMetrics_impl(tr, storageWiggleMetrics(primary), metrics);
}
ACTOR template <typename TrType>
static Future<Void> updateStorageWiggleMetrics_impl(
KeyBackedProperty<Value, NullCodec> wiggleSpeed,
KeyBackedObjectProperty<StorageWiggleMetrics, decltype(IncludeVersion())> storageMetrics,
TrType tr,
StorageWiggleMetrics metrics,
PrimaryRegion primary) {
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
Optional<Value> 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 <typename TrType>
Future<Void> updateStorageWiggleMetrics(TrType tr, StorageWiggleMetrics metrics, PrimaryRegion primary) {
return updateStorageWiggleMetrics_impl(
perpetualWiggleSpeed(), storageWiggleMetrics(primary), tr, metrics, primary);
}
};
#include "flow/unactorcompiler.h"
#endif

View File

@ -277,6 +277,7 @@ extern const KeyRef perpetualStorageWiggleKey;
extern const KeyRef perpetualStorageWiggleLocalityKey;
extern const KeyRef perpetualStorageWiggleIDPrefix;
extern const KeyRef perpetualStorageWiggleStatsPrefix;
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;

View File

@ -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"

View File

@ -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"

View File

@ -1945,9 +1945,10 @@ public:
}
ACTOR static Future<Void> updateNextWigglingStorageID(DDTeamCollection* self) {
state Key writeKey = perpetualStorageWiggleIDPrefix.withSuffix(self->primary ? "primary/"_sr : "remote/"_sr);
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap(writeKey,
IncludeVersion());
state StorageWiggleData wiggleState;
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap =
wiggleState.wigglingStorageServer(PrimaryRegion(self->primary));
state UID nextId = wait(self->getNextWigglingServerID());
state StorageWiggleValue value(nextId);
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(self->dbContext()));
@ -1971,12 +1972,33 @@ public:
return Void();
}
ACTOR static Future<Void> waitPerpetualWiggleDelay(DDTeamCollection* self) {
if (SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY <= 60.0) {
wait(delay(SERVER_KNOBS->PERPETUAL_WIGGLE_DELAY));
return Void();
}
state double nextDelay = 60.0;
while (true) {
wait(delay(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(self->storageWiggler->wiggleData.clearPerpetualWiggleDelay(self->dbContext().getReference(),
PrimaryRegion(self->primary)));
return Void();
}
}
}
ACTOR static Future<Void> perpetualStorageWiggleRest(DDTeamCollection* self) {
state bool takeRest = true;
state Promise<int64_t> 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);
@ -2057,8 +2079,9 @@ public:
ACTOR static Future<Void> perpetualStorageWiggler(DDTeamCollection* self,
AsyncVar<bool>* stopSignal,
PromiseStream<Void> finishStorageWiggleSignal) {
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap(
perpetualStorageWiggleIDPrefix.withSuffix(self->primary ? "primary/"_sr : "remote/"_sr), IncludeVersion());
state StorageWiggleData wiggleState;
state KeyBackedObjectMap<UID, StorageWiggleValue, decltype(IncludeVersion())> metadataMap =
wiggleState.wigglingStorageServer(PrimaryRegion(self->primary));
state Future<StorageWiggleValue> nextFuture = Never();
state Future<Void> moveFinishFuture = Never();

View File

@ -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<Void> StorageWiggler::resetStats() {
metrics.reset();
return runRYWTransaction(
teamCollection->dbContext(), [this](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return resetStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary()), metrics);
return wiggleData.resetStorageWiggleMetrics(tr, PrimaryRegion(teamCollection->isPrimary()), metrics);
});
}
Future<Void> StorageWiggler::restoreStats() {
auto& metricsRef = metrics;
auto assignFunc = [&metricsRef](Optional<StorageWiggleMetrics> v) {
if (v.present()) {
metricsRef = v.get();
}
return Void();
};
auto readFuture =
runRYWTransaction(teamCollection->dbContext(),
[this](Reference<ReadYourWritesTransaction> tr) -> Future<Optional<StorageWiggleMetrics>> {
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<Void> StorageWiggler::startWiggle() {
@ -209,7 +199,7 @@ Future<Void> StorageWiggler::startWiggle() {
}
return runRYWTransaction(
teamCollection->dbContext(), [this](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary()));
return wiggleData.updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary()));
});
}
@ -227,7 +217,7 @@ Future<Void> StorageWiggler::finishWiggle() {
}
return runRYWTransaction(
teamCollection->dbContext(), [this](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary()));
return wiggleData.updateStorageWiggleMetrics(tr, metrics, PrimaryRegion(teamCollection->isPrimary()));
});
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -2920,13 +2920,16 @@ ACTOR Future<std::pair<Optional<StorageWiggleMetrics>, Optional<StorageWiggleMet
state Reference<ReadYourWritesTransaction> tr(new ReadYourWritesTransaction(cx));
state Optional<StorageWiggleMetrics> primaryV;
state Optional<StorageWiggleMetrics> 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));

View File

@ -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"

View File

@ -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"

View File

@ -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"
@ -573,6 +573,8 @@ struct StorageWiggler : ReferenceCounted<StorageWiggler> {
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<bool> stopWiggleSignal;
// data structures

View File

@ -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<RestoreConfig>, which leads to some
// non-functional changes in RestoreConfig
class RestoreConfigFR : public KeyBackedConfig, public ReferenceCounted<RestoreConfigFR> {
class RestoreConfigFR : public KeyBackedTaskConfig, public ReferenceCounted<RestoreConfigFR> {
public:
RestoreConfigFR(UID uid = UID()) : KeyBackedConfig(fileRestorePrefixRange.begin, uid) {}
RestoreConfigFR(Reference<Task> task) : KeyBackedConfig(fileRestorePrefixRange.begin, task) {}
RestoreConfigFR(UID uid = UID()) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, uid) {}
RestoreConfigFR(Reference<Task> task) : KeyBackedTaskConfig(fileRestorePrefixRange.begin, task) {}
KeyBackedProperty<ERestoreState> stateEnum();

View File

@ -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.

View File

@ -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.

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -169,7 +169,8 @@ struct PerpetualWiggleStatsWorkload : public TestWorkload {
self->lastMetrics = getRandomWiggleMetrics();
auto& lastMetrics = self->lastMetrics;
wait(success(runRYWTransaction(cx, [&lastMetrics](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
return updateStorageWiggleMetrics(tr, lastMetrics, PrimaryRegion(true));
StorageWiggleData wiggleData;
return wiggleData.updateStorageWiggleMetrics(tr, lastMetrics, PrimaryRegion(true));
})));
return Void();
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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"

View File

@ -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"

View File

@ -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 {