2021-04-17 08:58:00 +08:00
|
|
|
/*
|
|
|
|
* LocalConfiguration.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 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.
|
|
|
|
*/
|
|
|
|
|
2021-05-12 04:33:39 +08:00
|
|
|
#include "fdbclient/Knobs.h"
|
2021-05-23 15:41:15 +08:00
|
|
|
#include "fdbrpc/Stats.h"
|
|
|
|
#include "fdbserver/ConfigBroadcastFollowerInterface.h"
|
2021-04-25 08:22:58 +08:00
|
|
|
#include "fdbserver/IKeyValueStore.h"
|
2021-05-13 08:23:32 +08:00
|
|
|
#include "fdbserver/Knobs.h"
|
2021-04-17 08:58:00 +08:00
|
|
|
#include "fdbserver/LocalConfiguration.h"
|
2021-05-24 12:03:15 +08:00
|
|
|
#include "fdbserver/OnDemandStore.h"
|
2021-05-12 04:33:39 +08:00
|
|
|
#include "flow/Knobs.h"
|
2021-05-13 02:56:45 +08:00
|
|
|
#include "flow/UnitTest.h"
|
|
|
|
|
2021-04-17 08:58:00 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
2021-04-25 08:22:58 +08:00
|
|
|
namespace {
|
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
const KeyRef configPathKey = "configPath"_sr;
|
2021-04-25 10:42:00 +08:00
|
|
|
const KeyRef lastSeenVersionKey = "lastSeenVersion"_sr;
|
2021-04-26 16:06:16 +08:00
|
|
|
const KeyRangeRef knobOverrideKeys = KeyRangeRef("knobOverride/"_sr, "knobOverride0"_sr);
|
2021-04-25 08:22:58 +08:00
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
bool updateSingleKnob(Key knobName, Value knobValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class K, class... Rest>
|
|
|
|
bool updateSingleKnob(Key knobName, Value knobValue, K& k, Rest&... rest) {
|
|
|
|
if (k.setKnob(knobName.toString(), knobValue.toString())) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return updateSingleKnob(knobName, knobValue, rest...);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 10:14:32 +08:00
|
|
|
KeyRef stringToKeyRef(std::string const& s) {
|
|
|
|
return StringRef(reinterpret_cast<uint8_t const*>(s.c_str()), s.size());
|
|
|
|
}
|
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
class ConfigKnobOverrides {
|
|
|
|
Standalone<VectorRef<KeyRef>> configPath;
|
2021-05-15 10:34:21 +08:00
|
|
|
std::map<Optional<Key>, std::map<Key, Value>> configClassToKnobToValue;
|
2021-05-13 01:12:37 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigKnobOverrides() = default;
|
2021-05-13 02:56:45 +08:00
|
|
|
explicit ConfigKnobOverrides(std::string const& paramString) {
|
2021-05-15 10:34:21 +08:00
|
|
|
configClassToKnobToValue[{}] = {};
|
2021-05-21 12:51:54 +08:00
|
|
|
if (std::all_of(paramString.begin(), paramString.end(), [](char c) {
|
|
|
|
return isalpha(c) || isdigit(c) || c == '/' || c == '-';
|
|
|
|
})) {
|
2021-05-19 12:29:40 +08:00
|
|
|
StringRef s = stringToKeyRef(paramString);
|
|
|
|
while (s.size()) {
|
|
|
|
configPath.push_back_deep(configPath.arena(), s.eat("/"_sr));
|
|
|
|
configClassToKnobToValue[configPath.back()] = {};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "WARNING: Invalid configuration path: `%s'\n", paramString.c_str());
|
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
|
|
|
ConfigClassSet getConfigClassSet() const { return ConfigClassSet(configPath); }
|
2021-05-15 10:34:21 +08:00
|
|
|
void set(Optional<KeyRef> configClass, KeyRef knobName, ValueRef value) {
|
|
|
|
configClassToKnobToValue[configClass.castTo<Key>()][knobName] = value;
|
|
|
|
}
|
|
|
|
void remove(Optional<KeyRef> configClass, KeyRef knobName) {
|
|
|
|
configClassToKnobToValue[configClass.castTo<Key>()].erase(knobName);
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... KS>
|
|
|
|
void update(KS&... knobCollections) const {
|
2021-05-22 07:21:31 +08:00
|
|
|
// Apply global overrides
|
|
|
|
const auto& knobToValue = configClassToKnobToValue.at({});
|
|
|
|
for (const auto& [knobName, knobValue] : knobToValue) {
|
|
|
|
updateSingleKnob(knobName, knobValue, knobCollections...);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply specific overrides
|
2021-05-13 01:12:37 +08:00
|
|
|
for (const auto& configClass : configPath) {
|
2021-05-15 10:34:21 +08:00
|
|
|
const auto& knobToValue = configClassToKnobToValue.at(configClass);
|
|
|
|
for (const auto& [knobName, knobValue] : knobToValue) {
|
2021-05-19 12:29:40 +08:00
|
|
|
updateSingleKnob(knobName, knobValue, knobCollections...);
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSameConfigPath(ConfigKnobOverrides const& other) const { return configPath == other.configPath; }
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, configPath);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ManualKnobOverrides {
|
|
|
|
std::map<Key, Value> overrides;
|
|
|
|
|
|
|
|
public:
|
2021-05-18 10:14:32 +08:00
|
|
|
explicit ManualKnobOverrides(std::map<std::string, std::string> const& overrides) {
|
|
|
|
for (const auto& [knobName, knobValue] : overrides) {
|
|
|
|
this->overrides[stringToKeyRef(knobName)] = stringToKeyRef(knobValue);
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
|
|
|
|
template <class... KS>
|
|
|
|
void update(KS&... knobCollections) const {
|
|
|
|
for (const auto& [knobName, knobValue] : overrides) {
|
|
|
|
if (!updateSingleKnob(knobName, knobValue, knobCollections...)) {
|
|
|
|
fprintf(stderr, "WARNING: Unrecognized knob option '%s'\n", knobName.toString().c_str());
|
|
|
|
TraceEvent(SevWarnAlways, "UnrecognizedKnobOption").detail("Knob", printable(knobName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-25 08:22:58 +08:00
|
|
|
} // namespace
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-24 12:03:15 +08:00
|
|
|
class LocalConfigurationImpl {
|
|
|
|
UID id;
|
|
|
|
// TODO: Listen for errors
|
|
|
|
OnDemandStore kvStore;
|
2021-04-25 08:22:58 +08:00
|
|
|
Future<Void> initFuture;
|
2021-05-12 04:33:39 +08:00
|
|
|
FlowKnobs flowKnobs;
|
|
|
|
ClientKnobs clientKnobs;
|
|
|
|
ServerKnobs serverKnobs;
|
|
|
|
TestKnobs testKnobs;
|
2021-05-14 15:41:02 +08:00
|
|
|
Version lastSeenVersion{ 0 };
|
2021-05-13 01:12:37 +08:00
|
|
|
ManualKnobOverrides manualKnobOverrides;
|
|
|
|
ConfigKnobOverrides configKnobOverrides;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-14 07:08:02 +08:00
|
|
|
CounterCollection cc;
|
|
|
|
Counter broadcasterChanges;
|
|
|
|
Counter snapshots;
|
|
|
|
Counter changeRequestsFetched;
|
|
|
|
Counter mutations;
|
|
|
|
Future<Void> logger;
|
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
ACTOR static Future<Void> saveConfigPath(LocalConfigurationImpl* self) {
|
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(configPathKey, BinaryWriter::toValue(self->configKnobOverrides, IncludeVersion())));
|
2021-04-25 08:22:58 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-04-17 08:58:00 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
ACTOR static Future<Void> clearKVStore(LocalConfigurationImpl* self) {
|
2021-05-13 01:12:37 +08:00
|
|
|
self->kvStore->clear(singleKeyRange(configPathKey));
|
2021-04-26 16:06:16 +08:00
|
|
|
self->kvStore->clear(knobOverrideKeys);
|
2021-04-25 08:22:58 +08:00
|
|
|
wait(self->kvStore->commit());
|
|
|
|
return Void();
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
ACTOR static Future<Version> getLastSeenVersion(LocalConfigurationImpl* self) {
|
|
|
|
state Version result = 0;
|
2021-04-25 10:42:00 +08:00
|
|
|
state Optional<Value> lastSeenVersionValue = wait(self->kvStore->readValue(lastSeenVersionKey));
|
|
|
|
if (!lastSeenVersionValue.present()) {
|
2021-05-13 08:23:32 +08:00
|
|
|
self->kvStore->set(KeyValueRef(lastSeenVersionKey, BinaryWriter::toValue(result, IncludeVersion())));
|
2021-04-25 10:42:00 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-05-13 08:23:32 +08:00
|
|
|
} else {
|
|
|
|
result = BinaryReader::fromStringRef<Version>(lastSeenVersionValue.get(), IncludeVersion());
|
2021-04-25 10:42:00 +08:00
|
|
|
}
|
2021-05-13 08:23:32 +08:00
|
|
|
return result;
|
2021-04-25 10:42:00 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 12:03:15 +08:00
|
|
|
ACTOR static Future<Void> initialize(LocalConfigurationImpl* self) {
|
2021-05-14 15:41:02 +08:00
|
|
|
state Version lastSeenVersion = wait(getLastSeenVersion(self));
|
2021-05-13 01:12:37 +08:00
|
|
|
state Optional<Value> storedConfigPathValue = wait(self->kvStore->readValue(configPathKey));
|
|
|
|
if (!storedConfigPathValue.present()) {
|
|
|
|
wait(saveConfigPath(self));
|
2021-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(lastSeenVersion);
|
2021-04-25 08:22:58 +08:00
|
|
|
return Void();
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
state ConfigKnobOverrides storedConfigPath =
|
|
|
|
BinaryReader::fromStringRef<ConfigKnobOverrides>(storedConfigPathValue.get(), IncludeVersion());
|
|
|
|
if (!storedConfigPath.hasSameConfigPath(self->configKnobOverrides)) {
|
2021-04-25 08:22:58 +08:00
|
|
|
// All local information is outdated
|
|
|
|
wait(clearKVStore(self));
|
2021-05-13 01:12:37 +08:00
|
|
|
wait(saveConfigPath(self));
|
2021-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(lastSeenVersion);
|
2021-04-25 08:22:58 +08:00
|
|
|
return Void();
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
2021-04-26 16:06:16 +08:00
|
|
|
Standalone<RangeResultRef> range = wait(self->kvStore->readRange(knobOverrideKeys));
|
2021-05-23 15:41:15 +08:00
|
|
|
for (const auto& kv : range) {
|
2021-05-13 08:48:07 +08:00
|
|
|
auto configKey =
|
|
|
|
BinaryReader::fromStringRef<ConfigKey>(kv.key.removePrefix(knobOverrideKeys.begin), IncludeVersion());
|
2021-05-13 01:12:37 +08:00
|
|
|
self->configKnobOverrides.set(configKey.configClass, configKey.knobName, kv.value);
|
2021-04-25 08:22:58 +08:00
|
|
|
}
|
2021-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(lastSeenVersion);
|
2021-04-25 08:22:58 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
void initializeKnobs(bool randomize = false, bool isSimulated = false) {
|
|
|
|
flowKnobs.initialize(randomize, isSimulated);
|
|
|
|
clientKnobs.initialize(randomize);
|
|
|
|
serverKnobs.initialize(randomize, &clientKnobs, isSimulated);
|
2021-05-12 04:33:39 +08:00
|
|
|
testKnobs.initialize();
|
|
|
|
}
|
|
|
|
|
2021-05-15 14:02:40 +08:00
|
|
|
void resetKnobs(bool randomize = false, bool isSimulated = false) {
|
|
|
|
flowKnobs.reset(randomize, isSimulated);
|
|
|
|
clientKnobs.reset(randomize);
|
|
|
|
serverKnobs.reset(randomize, &clientKnobs, isSimulated);
|
2021-05-13 01:12:37 +08:00
|
|
|
testKnobs.reset();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
2021-05-14 15:41:02 +08:00
|
|
|
void updateInMemoryState(Version lastSeenVersion) {
|
|
|
|
this->lastSeenVersion = lastSeenVersion;
|
2021-05-12 04:33:39 +08:00
|
|
|
resetKnobs();
|
2021-05-13 01:12:37 +08:00
|
|
|
configKnobOverrides.update(flowKnobs, clientKnobs, serverKnobs, testKnobs);
|
|
|
|
manualKnobOverrides.update(flowKnobs, clientKnobs, serverKnobs, testKnobs);
|
2021-04-27 04:12:30 +08:00
|
|
|
// Must reinitialize in order to update dependent knobs
|
2021-05-12 04:33:39 +08:00
|
|
|
initializeKnobs();
|
2021-04-27 04:12:30 +08:00
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
ACTOR static Future<Void> setSnapshot(LocalConfigurationImpl* self,
|
|
|
|
std::map<ConfigKey, Value> snapshot,
|
2021-05-14 15:41:02 +08:00
|
|
|
Version snapshotVersion) {
|
2021-05-13 08:23:32 +08:00
|
|
|
// TODO: Concurrency control?
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(self->initFuture.isValid() && self->initFuture.isReady());
|
2021-05-14 07:08:02 +08:00
|
|
|
++self->snapshots;
|
2021-04-26 16:06:16 +08:00
|
|
|
self->kvStore->clear(knobOverrideKeys);
|
2021-05-13 08:23:32 +08:00
|
|
|
for (const auto& [configKey, knobValue] : snapshot) {
|
2021-05-13 01:12:37 +08:00
|
|
|
self->configKnobOverrides.set(configKey.configClass, configKey.knobName, knobValue);
|
2021-05-13 12:33:32 +08:00
|
|
|
self->kvStore->set(KeyValueRef(
|
|
|
|
BinaryWriter::toValue(configKey, IncludeVersion()).withPrefix(knobOverrideKeys.begin), knobValue));
|
2021-04-26 10:01:17 +08:00
|
|
|
}
|
2021-05-14 15:41:02 +08:00
|
|
|
ASSERT_GE(snapshotVersion, self->lastSeenVersion);
|
|
|
|
self->kvStore->set(KeyValueRef(lastSeenVersionKey, BinaryWriter::toValue(snapshotVersion, IncludeVersion())));
|
2021-04-26 16:06:16 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(snapshotVersion);
|
2021-04-26 16:06:16 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
ACTOR static Future<Void> addChanges(LocalConfigurationImpl* self,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> changes,
|
|
|
|
Version mostRecentVersion) {
|
2021-05-13 08:23:32 +08:00
|
|
|
// TODO: Concurrency control?
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(self->initFuture.isValid() && self->initFuture.isReady());
|
2021-05-14 07:08:02 +08:00
|
|
|
++self->changeRequestsFetched;
|
2021-05-23 15:41:15 +08:00
|
|
|
for (const auto& versionedMutation : changes) {
|
2021-05-14 07:08:02 +08:00
|
|
|
++self->mutations;
|
2021-05-23 15:41:15 +08:00
|
|
|
const auto& mutation = versionedMutation.mutation;
|
2021-05-12 02:12:19 +08:00
|
|
|
auto serializedKey = BinaryWriter::toValue(mutation.getKey(), IncludeVersion());
|
|
|
|
if (mutation.isSet()) {
|
2021-05-15 10:34:21 +08:00
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(serializedKey.withPrefix(knobOverrideKeys.begin), mutation.getValue().get()));
|
|
|
|
self->configKnobOverrides.set(
|
|
|
|
mutation.getConfigClass(), mutation.getKnobName(), mutation.getValue().get());
|
2021-04-26 16:06:16 +08:00
|
|
|
} else {
|
2021-05-12 02:12:19 +08:00
|
|
|
self->kvStore->clear(singleKeyRange(serializedKey.withPrefix(knobOverrideKeys.begin)));
|
2021-05-13 01:12:37 +08:00
|
|
|
self->configKnobOverrides.remove(mutation.getConfigClass(), mutation.getKnobName());
|
2021-04-26 16:06:16 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-13 08:23:32 +08:00
|
|
|
self->kvStore->set(KeyValueRef(lastSeenVersionKey, BinaryWriter::toValue(mostRecentVersion, IncludeVersion())));
|
2021-04-26 16:06:16 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(mostRecentVersion);
|
2021-04-26 16:06:16 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
ACTOR static Future<Void> consumeInternal(LocalConfigurationImpl* self,
|
|
|
|
ConfigBroadcastFollowerInterface broadcaster) {
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
state ConfigFollowerGetChangesReply changesReply =
|
|
|
|
wait(broadcaster.getChanges.getReply(ConfigBroadcastFollowerGetChangesRequest{
|
|
|
|
self->lastSeenVersion, self->configKnobOverrides.getConfigClassSet() }));
|
|
|
|
TraceEvent(SevDebug, "LocalConfigGotChanges", self->id); // TODO: Add more fields
|
|
|
|
wait(self->addChanges(changesReply.changes, changesReply.mostRecentVersion));
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_version_already_compacted) {
|
|
|
|
// TODO: Collect stats
|
|
|
|
state ConfigBroadcastFollowerGetSnapshotReply snapshotReply = wait(broadcaster.getSnapshot.getReply(
|
|
|
|
ConfigBroadcastFollowerGetSnapshotRequest{ self->configKnobOverrides.getConfigClassSet() }));
|
|
|
|
ASSERT_GT(snapshotReply.version, self->lastSeenVersion);
|
|
|
|
wait(setSnapshot(self, std::move(snapshotReply.snapshot), snapshotReply.version));
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait(yield()); // Necessary to not immediately trigger retry?
|
2021-05-13 08:23:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
ACTOR static Future<Void> consume(
|
|
|
|
LocalConfigurationImpl* self,
|
|
|
|
Reference<IDependentAsyncVar<ConfigBroadcastFollowerInterface> const> broadcaster) {
|
|
|
|
ASSERT(self->initFuture.isValid() && self->initFuture.isReady());
|
|
|
|
loop {
|
|
|
|
choose {
|
|
|
|
when(wait(brokenPromiseToNever(consumeInternal(self, broadcaster->get())))) { ASSERT(false); }
|
|
|
|
when(wait(broadcaster->onChange())) { ++self->broadcasterChanges; }
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-05-24 12:03:15 +08:00
|
|
|
LocalConfigurationImpl(std::string const& dataFolder,
|
|
|
|
std::string const& configPath,
|
|
|
|
std::map<std::string, std::string> const& manualKnobOverrides,
|
|
|
|
Optional<UID> testID)
|
|
|
|
: id(testID.present() ? testID.get() : deterministicRandom()->randomUniqueID()),
|
|
|
|
kvStore(dataFolder, id, "localconf-" + (testID.present() ? id.toString() : "")), cc("LocalConfiguration"),
|
|
|
|
broadcasterChanges("BroadcasterChanges", cc), snapshots("Snapshots", cc),
|
2021-05-14 07:08:02 +08:00
|
|
|
changeRequestsFetched("ChangeRequestsFetched", cc), mutations("Mutations", cc), configKnobOverrides(configPath),
|
2021-05-24 12:03:15 +08:00
|
|
|
manualKnobOverrides(manualKnobOverrides) {
|
|
|
|
logger = traceCounters(
|
|
|
|
"LocalConfigurationMetrics", id, SERVER_KNOBS->WORKER_LOGGING_INTERVAL, &cc, "LocalConfigurationMetrics");
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 12:03:15 +08:00
|
|
|
Future<Void> initialize() {
|
2021-04-25 08:22:58 +08:00
|
|
|
ASSERT(!initFuture.isValid());
|
2021-05-24 12:03:15 +08:00
|
|
|
initFuture = initialize(this);
|
2021-04-25 08:22:58 +08:00
|
|
|
return initFuture;
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
Future<Void> addChanges(Standalone<VectorRef<VersionedConfigMutationRef>> changes, Version mostRecentVersion) {
|
|
|
|
return addChanges(this, changes, mostRecentVersion);
|
2021-05-13 08:23:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-12 04:33:39 +08:00
|
|
|
FlowKnobs const& getFlowKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-05-12 04:33:39 +08:00
|
|
|
return flowKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientKnobs const& getClientKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-05-12 04:33:39 +08:00
|
|
|
return clientKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerKnobs const& getServerKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-05-12 04:33:39 +08:00
|
|
|
return serverKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs const& getTestKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-05-12 04:33:39 +08:00
|
|
|
return testKnobs;
|
2021-04-25 08:22:58 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
Future<Void> consume(Reference<IDependentAsyncVar<ConfigBroadcastFollowerInterface> const> const& broadcaster) {
|
|
|
|
return consume(this, broadcaster);
|
2021-04-26 10:01:17 +08:00
|
|
|
}
|
2021-05-14 15:41:02 +08:00
|
|
|
|
|
|
|
UID getID() const { return id; }
|
2021-04-17 08:58:00 +08:00
|
|
|
};
|
|
|
|
|
2021-05-24 12:03:15 +08:00
|
|
|
LocalConfiguration::LocalConfiguration(std::string const& dataFolder,
|
|
|
|
std::string const& configPath,
|
|
|
|
std::map<std::string, std::string> const& manualKnobOverrides,
|
|
|
|
Optional<UID> testID)
|
|
|
|
: impl(std::make_unique<LocalConfigurationImpl>(dataFolder, configPath, manualKnobOverrides, testID)) {}
|
2021-05-14 05:17:52 +08:00
|
|
|
|
2021-05-17 08:25:41 +08:00
|
|
|
LocalConfiguration::LocalConfiguration(LocalConfiguration&&) = default;
|
|
|
|
|
|
|
|
LocalConfiguration& LocalConfiguration::operator=(LocalConfiguration&&) = default;
|
|
|
|
|
2021-04-17 08:58:00 +08:00
|
|
|
LocalConfiguration::~LocalConfiguration() = default;
|
|
|
|
|
2021-05-24 12:03:15 +08:00
|
|
|
Future<Void> LocalConfiguration::initialize() {
|
|
|
|
return impl->initialize();
|
2021-04-25 08:22:58 +08:00
|
|
|
}
|
|
|
|
|
2021-05-12 04:33:39 +08:00
|
|
|
FlowKnobs const& LocalConfiguration::getFlowKnobs() const {
|
|
|
|
return impl->getFlowKnobs();
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientKnobs const& LocalConfiguration::getClientKnobs() const {
|
|
|
|
return impl->getClientKnobs();
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerKnobs const& LocalConfiguration::getServerKnobs() const {
|
|
|
|
return impl->getServerKnobs();
|
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs const& LocalConfiguration::getTestKnobs() const {
|
|
|
|
return impl->getTestKnobs();
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-05-13 15:51:19 +08:00
|
|
|
Future<Void> LocalConfiguration::consume(
|
2021-05-23 15:41:15 +08:00
|
|
|
Reference<IDependentAsyncVar<ConfigBroadcastFollowerInterface> const> const& broadcaster) {
|
|
|
|
return impl->consume(broadcaster);
|
2021-05-13 08:23:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
Future<Void> LocalConfiguration::addChanges(Standalone<VectorRef<VersionedConfigMutationRef>> changes,
|
|
|
|
Version mostRecentVersion) {
|
|
|
|
return impl->addChanges(changes, mostRecentVersion);
|
2021-04-25 08:22:58 +08:00
|
|
|
}
|
|
|
|
|
2021-05-14 15:41:02 +08:00
|
|
|
UID LocalConfiguration::getID() const {
|
|
|
|
return impl->getID();
|
|
|
|
}
|
|
|
|
|
2021-04-25 08:22:58 +08:00
|
|
|
#define init(knob, value) initKnob(knob, value, #knob)
|
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
TestKnobs::TestKnobs() {
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
2021-04-25 08:22:58 +08:00
|
|
|
void TestKnobs::initialize() {
|
2021-05-13 03:25:43 +08:00
|
|
|
init(TEST_LONG, 0);
|
|
|
|
init(TEST_INT, 0);
|
|
|
|
init(TEST_DOUBLE, 0.0);
|
|
|
|
init(TEST_BOOL, false);
|
|
|
|
init(TEST_STRING, "");
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
|
2021-05-14 03:55:33 +08:00
|
|
|
bool TestKnobs::operator==(TestKnobs const& rhs) const {
|
|
|
|
return (TEST_LONG == rhs.TEST_LONG) && (TEST_INT == rhs.TEST_INT) && (TEST_DOUBLE == rhs.TEST_DOUBLE) &&
|
|
|
|
(TEST_BOOL == rhs.TEST_BOOL) && (TEST_STRING == rhs.TEST_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestKnobs::operator!=(TestKnobs const& rhs) const {
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
|
2021-05-13 03:25:43 +08:00
|
|
|
namespace {
|
|
|
|
|
2021-05-15 14:02:40 +08:00
|
|
|
class TestKnobs2 : public Knobs<TestKnobs2> {
|
2021-05-13 03:25:43 +08:00
|
|
|
public:
|
|
|
|
int64_t TEST2_LONG;
|
|
|
|
int TEST2_INT;
|
|
|
|
double TEST2_DOUBLE;
|
|
|
|
bool TEST2_BOOL;
|
|
|
|
std::string TEST2_STRING;
|
|
|
|
|
|
|
|
void initialize() {
|
|
|
|
init(TEST2_LONG, 0);
|
|
|
|
init(TEST2_INT, 0);
|
|
|
|
init(TEST2_DOUBLE, 0.0);
|
|
|
|
init(TEST2_BOOL, false);
|
|
|
|
init(TEST2_STRING, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs2() { initialize(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-05-14 02:22:25 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Internal/updateSingleKnob") {
|
2021-05-13 03:25:43 +08:00
|
|
|
TestKnobs k1;
|
|
|
|
TestKnobs2 k2;
|
|
|
|
updateSingleKnob("test_long"_sr, "5"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test_int"_sr, "5"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test_double"_sr, "5.0"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test_bool"_sr, "true"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test_string"_sr, "5"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test2_long"_sr, "10"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test2_int"_sr, "10"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test2_double"_sr, "10.0"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test2_bool"_sr, "true"_sr, k1, k2);
|
|
|
|
updateSingleKnob("test2_string"_sr, "10"_sr, k1, k2);
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT_EQ(k1.TEST_LONG, 5);
|
|
|
|
ASSERT_EQ(k1.TEST_INT, 5);
|
|
|
|
ASSERT_EQ(k1.TEST_DOUBLE, 5.0);
|
2021-05-13 03:25:43 +08:00
|
|
|
ASSERT(k1.TEST_BOOL);
|
|
|
|
ASSERT(k1.TEST_STRING == "5");
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT_EQ(k2.TEST2_LONG, 10);
|
|
|
|
ASSERT_EQ(k2.TEST2_INT, 10);
|
|
|
|
ASSERT_EQ(k2.TEST2_DOUBLE, 10.0);
|
2021-05-13 03:25:43 +08:00
|
|
|
ASSERT(k2.TEST2_BOOL);
|
|
|
|
ASSERT(k2.TEST2_STRING == "10");
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-14 02:22:25 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Internal/ManualKnobOverrides") {
|
2021-05-13 03:25:43 +08:00
|
|
|
TestKnobs k1;
|
|
|
|
TestKnobs2 k2;
|
2021-05-18 10:14:32 +08:00
|
|
|
std::map<std::string, std::string> m = { { "test_int", "5" }, { "test2_int", "10" } };
|
2021-05-13 03:25:43 +08:00
|
|
|
ManualKnobOverrides manualKnobOverrides(std::move(m));
|
|
|
|
manualKnobOverrides.update(k1, k2);
|
|
|
|
ASSERT(k1.TEST_INT == 5);
|
|
|
|
ASSERT(k2.TEST2_INT == 10);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-19 12:29:40 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Internal/GlobalKnobOverride") {
|
|
|
|
TestKnobs k1;
|
|
|
|
ConfigKnobOverrides configKnobOverrides("class-A");
|
|
|
|
configKnobOverrides.set({}, "test_int"_sr, "5"_sr);
|
|
|
|
configKnobOverrides.update(k1);
|
|
|
|
ASSERT_EQ(k1.TEST_INT, 5);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-14 02:22:25 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Internal/ConfigKnobOverrides") {
|
2021-05-13 03:25:43 +08:00
|
|
|
TestKnobs k1;
|
|
|
|
TestKnobs2 k2;
|
|
|
|
ConfigKnobOverrides configKnobOverrides("class-A/class-B");
|
|
|
|
configKnobOverrides.update(k1, k2);
|
|
|
|
ASSERT(k1.TEST_INT == 0);
|
|
|
|
ASSERT(k2.TEST2_INT == 0);
|
|
|
|
configKnobOverrides.set("class-B"_sr, "test_int"_sr, "7"_sr);
|
|
|
|
configKnobOverrides.set("class-A"_sr, "test_int"_sr, "5"_sr);
|
|
|
|
configKnobOverrides.set("class-A"_sr, "test2_int"_sr, "10"_sr);
|
|
|
|
configKnobOverrides.update(k1, k2);
|
|
|
|
ASSERT(k1.TEST_INT == 7);
|
|
|
|
ASSERT(k2.TEST2_INT == 10);
|
|
|
|
return Void();
|
|
|
|
}
|
2021-05-19 12:29:40 +08:00
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Internal/InvalidKnobName") {
|
|
|
|
TestKnobs k1;
|
|
|
|
ConfigKnobOverrides configKnobOverrides("class-A");
|
|
|
|
// Noop with a SevWarnAlways trace
|
|
|
|
configKnobOverrides.set("class-A", "thisknobdoesnotexist"_sr, "5"_sr);
|
|
|
|
configKnobOverrides.update(k1);
|
|
|
|
return Void();
|
|
|
|
}
|