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-13 08:23:32 +08:00
|
|
|
#include "fdbclient/Tuple.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-13 08:23:32 +08:00
|
|
|
#include "fdbserver/SimpleConfigConsumer.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...);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigKnobOverrides {
|
|
|
|
Standalone<VectorRef<KeyRef>> configPath;
|
|
|
|
std::map<Key, std::map<Key, Value>> configClassToKnobToValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigKnobOverrides() = default;
|
2021-05-13 02:56:45 +08:00
|
|
|
explicit ConfigKnobOverrides(std::string const& paramString) {
|
2021-05-13 01:12:37 +08:00
|
|
|
// TODO: Validate string
|
2021-05-13 02:56:45 +08:00
|
|
|
StringRef s(reinterpret_cast<uint8_t const*>(paramString.c_str()), paramString.size());
|
|
|
|
while (s.size()) {
|
|
|
|
configPath.push_back_deep(configPath.arena(), s.eat("/"_sr));
|
|
|
|
configClassToKnobToValue[configPath.back()] = {};
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ConfigClassSet getConfigClassSet() const { return ConfigClassSet(configPath); }
|
|
|
|
void set(KeyRef configClass, KeyRef knobName, ValueRef value) {
|
|
|
|
configClassToKnobToValue[configClass][knobName] = value;
|
|
|
|
}
|
|
|
|
void remove(KeyRef configClass, KeyRef knobName) { configClassToKnobToValue[configClass].erase(knobName); }
|
|
|
|
|
|
|
|
template <class... KS>
|
|
|
|
void update(KS&... knobCollections) const {
|
|
|
|
for (const auto& configClass : configPath) {
|
|
|
|
const auto& knobToValue = configClassToKnobToValue.find(configClass);
|
2021-05-13 02:56:45 +08:00
|
|
|
ASSERT(knobToValue != configClassToKnobToValue.end());
|
|
|
|
for (const auto& [knobName, knobValue] : knobToValue->second) {
|
|
|
|
// Assert here because we should be validating on the client
|
|
|
|
ASSERT(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-13 02:56:45 +08:00
|
|
|
explicit ManualKnobOverrides(std::map<Key, Value>&& overrides) : overrides(std::move(overrides)) {}
|
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-13 10:56:16 +08:00
|
|
|
class LocalConfigurationImpl : public NonCopyable {
|
|
|
|
IKeyValueStore* 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-13 01:12:37 +08:00
|
|
|
ManualKnobOverrides manualKnobOverrides;
|
|
|
|
ConfigKnobOverrides configKnobOverrides;
|
2021-05-13 08:23:32 +08:00
|
|
|
ActorCollection actors{ false };
|
2021-04-17 08:58:00 +08:00
|
|
|
|
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-04-25 08:22:58 +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-13 10:56:16 +08:00
|
|
|
ACTOR static Future<Void> initialize(LocalConfigurationImpl* self) {
|
2021-04-25 08:22:58 +08:00
|
|
|
wait(self->kvStore->init());
|
2021-05-13 01:12:37 +08:00
|
|
|
state Optional<Value> storedConfigPathValue = wait(self->kvStore->readValue(configPathKey));
|
|
|
|
if (!storedConfigPathValue.present()) {
|
|
|
|
wait(saveConfigPath(self));
|
2021-04-27 04:12:30 +08:00
|
|
|
self->updateInMemoryKnobs();
|
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-04-27 04:12:30 +08:00
|
|
|
self->updateInMemoryKnobs();
|
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-04-25 08:22:58 +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-04-27 04:12:30 +08:00
|
|
|
self->updateInMemoryKnobs();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetKnobs() {
|
|
|
|
flowKnobs.reset();
|
2021-05-13 01:12:37 +08:00
|
|
|
clientKnobs.reset();
|
2021-05-13 02:56:45 +08:00
|
|
|
serverKnobs.reset(&clientKnobs);
|
2021-05-13 01:12:37 +08:00
|
|
|
testKnobs.reset();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 04:12:30 +08:00
|
|
|
void updateInMemoryKnobs() {
|
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,
|
|
|
|
Version lastCompactedVersion) {
|
|
|
|
// TODO: Concurrency control?
|
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-13 08:23:32 +08:00
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(lastSeenVersionKey, BinaryWriter::toValue(lastCompactedVersion, IncludeVersion())));
|
2021-04-26 16:06:16 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-04-27 04:12:30 +08:00
|
|
|
self->updateInMemoryKnobs();
|
2021-04-26 16:06:16 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
ACTOR static Future<Void> addVersionedMutations(
|
|
|
|
LocalConfigurationImpl* self,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations,
|
|
|
|
Version mostRecentVersion) {
|
|
|
|
// TODO: Concurrency control?
|
|
|
|
for (const auto& versionedMutation : versionedMutations) {
|
2021-04-26 16:06:16 +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()) {
|
|
|
|
self->kvStore->set(KeyValueRef(serializedKey.withPrefix(knobOverrideKeys.begin), mutation.getValue()));
|
2021-05-13 01:12:37 +08:00
|
|
|
self->configKnobOverrides.set(mutation.getConfigClass(), mutation.getKnobName(), mutation.getValue());
|
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-04-27 04:12:30 +08:00
|
|
|
self->updateInMemoryKnobs();
|
2021-04-26 16:06:16 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-04-27 09:46:22 +08:00
|
|
|
ACTOR static Future<Void> monitorBroadcaster(Reference<AsyncVar<ServerDBInfo> const> serverDBInfo,
|
|
|
|
Reference<AsyncVar<ConfigFollowerInterface>> broadcaster) {
|
|
|
|
loop {
|
|
|
|
wait(serverDBInfo->onChange());
|
|
|
|
broadcaster->set(serverDBInfo->get().configBroadcaster);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
ACTOR static Future<Void> consumeLoopIteration(LocalConfiguration* self,
|
|
|
|
LocalConfigurationImpl* impl,
|
|
|
|
Reference<AsyncVar<ConfigFollowerInterface>> broadcaster) {
|
|
|
|
// TODO: Cache lastSeenVersion in memory
|
|
|
|
// state Version lastSeenVersion = wait(impl->getLastSeenVersion());
|
|
|
|
state SimpleConfigConsumer consumer(broadcaster->get());
|
|
|
|
choose {
|
|
|
|
when(wait(broadcaster->onChange())) {}
|
|
|
|
when(wait(brokenPromiseToNever(consumer.consume(*self)))) { ASSERT(false); }
|
|
|
|
when(wait(impl->actors.getResult())) { ASSERT(false); }
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> consume(LocalConfiguration* self,
|
|
|
|
LocalConfigurationImpl* impl,
|
2021-04-26 10:01:17 +08:00
|
|
|
Reference<AsyncVar<ServerDBInfo> const> serverDBInfo) {
|
2021-05-13 08:23:32 +08:00
|
|
|
wait(impl->initFuture);
|
2021-04-27 09:46:22 +08:00
|
|
|
state Reference<AsyncVar<ConfigFollowerInterface>> broadcaster =
|
|
|
|
makeReference<AsyncVar<ConfigFollowerInterface>>(serverDBInfo->get().configBroadcaster);
|
2021-05-13 08:23:32 +08:00
|
|
|
impl->actors.add(monitorBroadcaster(serverDBInfo, broadcaster));
|
|
|
|
loop { wait(consumeLoopIteration(self, impl, broadcaster)); }
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-05-13 01:12:37 +08:00
|
|
|
LocalConfigurationImpl(std::string const& configPath,
|
2021-04-27 04:12:30 +08:00
|
|
|
std::string const& dataFolder,
|
2021-05-13 01:12:37 +08:00
|
|
|
std::map<Key, Value>&& manualKnobOverrides,
|
2021-05-01 02:01:44 +08:00
|
|
|
UID id)
|
2021-05-13 01:12:37 +08:00
|
|
|
: configKnobOverrides(configPath), manualKnobOverrides(std::move(manualKnobOverrides)) {
|
2021-04-17 08:58:00 +08:00
|
|
|
platform::createDirectory(dataFolder);
|
2021-05-01 02:01:44 +08:00
|
|
|
kvStore = keyValueStoreMemory(joinPath(dataFolder, "localconf-" + id.toString()), id, 500e6);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-05-13 10:56:16 +08:00
|
|
|
~LocalConfigurationImpl() { kvStore->close(); }
|
|
|
|
|
|
|
|
Future<Void> initialize() {
|
2021-04-25 08:22:58 +08:00
|
|
|
ASSERT(!initFuture.isValid());
|
2021-05-13 10:56:16 +08:00
|
|
|
initFuture = initialize(this);
|
2021-04-25 08:22:58 +08:00
|
|
|
return initFuture;
|
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
Future<Void> setSnapshot(std::map<ConfigKey, Value>&& snapshot, Version lastCompactedVersion) {
|
|
|
|
// TODO: Remove unnecessary copy
|
|
|
|
auto f = setSnapshot(this, std::move(snapshot), lastCompactedVersion);
|
|
|
|
actors.add(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> addVersionedMutations(Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations,
|
|
|
|
Version mostRecentVersion) {
|
|
|
|
auto f = addVersionedMutations(this, versionedMutations, mostRecentVersion);
|
|
|
|
actors.add(f);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2021-05-12 04:33:39 +08:00
|
|
|
FlowKnobs const& getFlowKnobs() const {
|
|
|
|
ASSERT(initFuture.isReady());
|
|
|
|
return flowKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientKnobs const& getClientKnobs() const {
|
|
|
|
ASSERT(initFuture.isReady());
|
|
|
|
return clientKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerKnobs const& getServerKnobs() const {
|
|
|
|
ASSERT(initFuture.isReady());
|
|
|
|
return serverKnobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs const& getTestKnobs() const {
|
2021-04-25 08:22:58 +08:00
|
|
|
ASSERT(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-13 08:23:32 +08:00
|
|
|
Future<Void> consume(LocalConfiguration& self, Reference<AsyncVar<ServerDBInfo> const> const& serverDBInfo) {
|
|
|
|
return consume(&self, this, serverDBInfo);
|
2021-04-26 10:01:17 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
};
|
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
LocalConfiguration::LocalConfiguration(std::string const& configPath,
|
2021-04-27 04:12:30 +08:00
|
|
|
std::string const& dataFolder,
|
2021-05-13 01:12:37 +08:00
|
|
|
std::map<Key, Value>&& manualKnobOverrides,
|
2021-05-01 02:01:44 +08:00
|
|
|
UID id)
|
2021-05-13 01:12:37 +08:00
|
|
|
: impl(std::make_unique<LocalConfigurationImpl>(configPath, dataFolder, std::move(manualKnobOverrides), id)) {}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
LocalConfiguration::~LocalConfiguration() = default;
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
Future<Void> LocalConfiguration::initialize() {
|
2021-05-13 10:56:16 +08:00
|
|
|
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-04-26 10:01:17 +08:00
|
|
|
Future<Void> LocalConfiguration::consume(Reference<AsyncVar<ServerDBInfo> const> const& serverDBInfo) {
|
2021-05-13 08:23:32 +08:00
|
|
|
return impl->consume(*this, serverDBInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> LocalConfiguration::setSnapshot(std::map<ConfigKey, Value>&& snapshot, Version lastCompactedVersion) {
|
|
|
|
return impl->setSnapshot(std::move(snapshot), lastCompactedVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> LocalConfiguration::addVersionedMutations(
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations,
|
|
|
|
Version mostRecentVersion) {
|
|
|
|
return impl->addVersionedMutations(versionedMutations, mostRecentVersion);
|
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
|
|
|
|
|
|
|
void TestKnobs::reset() {
|
|
|
|
explicitlySetKnobs.clear();
|
|
|
|
initialize();
|
|
|
|
}
|
2021-05-13 03:25:43 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TestKnobs2 : public Knobs {
|
|
|
|
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(); }
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
explicitlySetKnobs.clear();
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/updateSingleKnob") {
|
|
|
|
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);
|
|
|
|
ASSERT(k1.TEST_LONG == 5);
|
|
|
|
ASSERT(k1.TEST_INT == 5);
|
|
|
|
ASSERT(k1.TEST_DOUBLE == 5.0);
|
|
|
|
ASSERT(k1.TEST_BOOL);
|
|
|
|
ASSERT(k1.TEST_STRING == "5");
|
|
|
|
ASSERT(k2.TEST2_LONG == 10);
|
|
|
|
ASSERT(k2.TEST2_INT == 10);
|
|
|
|
ASSERT(k2.TEST2_DOUBLE == 10.0);
|
|
|
|
ASSERT(k2.TEST2_BOOL);
|
|
|
|
ASSERT(k2.TEST2_STRING == "10");
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/ManualKnobOverrides") {
|
|
|
|
TestKnobs k1;
|
|
|
|
TestKnobs2 k2;
|
|
|
|
std::map<Key, Value> m;
|
|
|
|
m["test_int"_sr] = "5"_sr;
|
|
|
|
m["test2_int"_sr] = "10"_sr;
|
|
|
|
ManualKnobOverrides manualKnobOverrides(std::move(m));
|
|
|
|
manualKnobOverrides.update(k1, k2);
|
|
|
|
ASSERT(k1.TEST_INT == 5);
|
|
|
|
ASSERT(k2.TEST2_INT == 10);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/ConfigKnobOverrides") {
|
|
|
|
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-13 08:23:32 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-05-13 12:33:32 +08:00
|
|
|
ACTOR Future<Void> setTestSnapshot(LocalConfiguration* localConfiguration, Version* version) {
|
|
|
|
std::map<ConfigKey, Value> snapshot = {
|
|
|
|
{ ConfigKeyRef("class-A"_sr, "test_int"_sr), "1"_sr },
|
|
|
|
{ ConfigKeyRef("class-B"_sr, "test_int"_sr), "2"_sr },
|
|
|
|
{ ConfigKeyRef("class-C"_sr, "test_int"_sr), "3"_sr },
|
|
|
|
{ ConfigKeyRef("class-A"_sr, "test_string"_sr), "x"_sr },
|
|
|
|
};
|
|
|
|
wait(localConfiguration->setSnapshot(std::move(snapshot), ++(*version)));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendVersionedMutation(Standalone<VectorRef<VersionedConfigMutationRef>>& versionedMutations,
|
|
|
|
Version version,
|
|
|
|
KeyRef configClass,
|
|
|
|
KeyRef knobName,
|
|
|
|
ValueRef knobValue) {
|
|
|
|
Tuple tuple;
|
|
|
|
tuple << configClass;
|
|
|
|
tuple << knobName;
|
|
|
|
auto mutation = ConfigMutationRef::createConfigMutation(tuple.pack(), knobValue);
|
|
|
|
versionedMutations.emplace_back_deep(versionedMutations.arena(), version, mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> addTestUpdates(LocalConfiguration* localConfiguration, Version* version) {
|
2021-05-13 08:23:32 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations;
|
2021-05-13 12:33:32 +08:00
|
|
|
++(*version);
|
|
|
|
appendVersionedMutation(versionedMutations, *version, "class-A"_sr, "test_bool"_sr, "true"_sr);
|
|
|
|
appendVersionedMutation(versionedMutations, *version, "class-B"_sr, "test_long"_sr, "100"_sr);
|
|
|
|
appendVersionedMutation(versionedMutations, *version, "class-C"_sr, "test_double"_sr, "1.0"_sr);
|
|
|
|
appendVersionedMutation(versionedMutations, *version, "class-A"_sr, "test_int"_sr, "10"_sr);
|
|
|
|
wait(localConfiguration->addVersionedMutations(versionedMutations, *version));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> runTestUpdates(LocalConfiguration* localConfiguration, Version* version) {
|
|
|
|
wait(localConfiguration->initialize());
|
|
|
|
wait(setTestSnapshot(localConfiguration, version));
|
|
|
|
wait(addTestUpdates(localConfiguration, version));
|
2021-05-13 10:56:16 +08:00
|
|
|
// TODO: Clean up on-disk state
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:56:16 +08:00
|
|
|
ACTOR Future<Void> runFirstLocalConfiguration(std::string configPath, UID uid) {
|
|
|
|
state LocalConfiguration localConfiguration(configPath, "./", {}, uid);
|
2021-05-13 12:33:32 +08:00
|
|
|
state Version version = 1;
|
|
|
|
wait(runTestUpdates(&localConfiguration, &version));
|
|
|
|
ASSERT(localConfiguration.getTestKnobs().TEST_INT == 2);
|
|
|
|
ASSERT(localConfiguration.getTestKnobs().TEST_BOOL);
|
|
|
|
ASSERT(localConfiguration.getTestKnobs().TEST_STRING == "x");
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:33:32 +08:00
|
|
|
ACTOR template <class F>
|
|
|
|
Future<Void> runSecondLocalConfiguration(std::string configPath, UID uid, F validate) {
|
2021-05-13 10:56:16 +08:00
|
|
|
state LocalConfiguration localConfiguration(configPath, "./", {}, uid);
|
|
|
|
wait(localConfiguration.initialize());
|
2021-05-13 12:33:32 +08:00
|
|
|
validate(localConfiguration.getTestKnobs());
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:56:16 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Simple") {
|
|
|
|
wait(runFirstLocalConfiguration("class-A/class-B", deterministicRandom()->randomUniqueID()));
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:56:16 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Restart") {
|
|
|
|
state UID uid = deterministicRandom()->randomUniqueID();
|
|
|
|
wait(runFirstLocalConfiguration("class-A/class-B", uid));
|
2021-05-13 12:33:32 +08:00
|
|
|
wait(runSecondLocalConfiguration("class-A/class-B", uid, [](TestKnobs const& testKnobs) {
|
|
|
|
ASSERT(testKnobs.TEST_INT == 2);
|
|
|
|
ASSERT(testKnobs.TEST_BOOL);
|
|
|
|
ASSERT(testKnobs.TEST_STRING == "x");
|
|
|
|
ASSERT(testKnobs.TEST_DOUBLE == 0.0);
|
|
|
|
ASSERT(testKnobs.TEST_LONG == 100);
|
|
|
|
}));
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:56:16 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/FreshRestart") {
|
|
|
|
state UID uid = deterministicRandom()->randomUniqueID();
|
|
|
|
wait(runFirstLocalConfiguration("class-A/class-B", uid));
|
2021-05-13 12:33:32 +08:00
|
|
|
wait(runSecondLocalConfiguration("class-B/class-A", uid, [](TestKnobs const& testKnobs) {
|
|
|
|
ASSERT(testKnobs.TEST_INT == 0);
|
|
|
|
ASSERT(!testKnobs.TEST_BOOL);
|
|
|
|
ASSERT(testKnobs.TEST_STRING == "");
|
|
|
|
ASSERT(testKnobs.TEST_DOUBLE == 0.0);
|
|
|
|
ASSERT(testKnobs.TEST_LONG == 0);
|
|
|
|
}));
|
2021-05-13 08:23:32 +08:00
|
|
|
return Void();
|
|
|
|
}
|