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-06-03 14:40:52 +08:00
|
|
|
#include "fdbclient/IKnobCollection.h"
|
2021-05-23 15:41:15 +08:00
|
|
|
#include "fdbrpc/Stats.h"
|
2021-04-25 08:22:58 +08:00
|
|
|
#include "fdbserver/IKeyValueStore.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-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-07-09 20:41:33 +08:00
|
|
|
FDB_DEFINE_BOOLEAN_PARAM(IsTest);
|
2021-07-03 12:41:50 +08:00
|
|
|
|
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-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-06-19 08:12:32 +08:00
|
|
|
} // namespace
|
2021-05-13 01:12:37 +08:00
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
class LocalConfigurationImpl {
|
|
|
|
UID id;
|
|
|
|
OnDemandStore kvStore;
|
|
|
|
Future<Void> initFuture;
|
|
|
|
Version lastSeenVersion{ 0 };
|
|
|
|
std::unique_ptr<IKnobCollection> testKnobCollection;
|
2021-05-13 01:12:37 +08:00
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
class ConfigKnobOverrides {
|
|
|
|
Standalone<VectorRef<KeyRef>> configPath;
|
|
|
|
std::map<Optional<Key>, std::map<Key, KnobValue>> configClassToKnobToValue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigKnobOverrides() = default;
|
|
|
|
explicit ConfigKnobOverrides(std::string const& paramString) {
|
|
|
|
configClassToKnobToValue[{}] = {};
|
|
|
|
if (std::all_of(paramString.begin(), paramString.end(), [](char c) {
|
|
|
|
return isalpha(c) || isdigit(c) || c == '/' || c == '-';
|
|
|
|
})) {
|
|
|
|
StringRef s = stringToKeyRef(paramString);
|
|
|
|
while (s.size()) {
|
|
|
|
configPath.push_back_deep(configPath.arena(), s.eat("/"_sr));
|
|
|
|
configClassToKnobToValue[configPath.back()] = {};
|
2021-06-17 04:10:14 +08:00
|
|
|
}
|
2021-06-19 08:12:32 +08:00
|
|
|
} else {
|
|
|
|
TEST(true); // Invalid configuration path
|
|
|
|
if (!g_network->isSimulated()) {
|
|
|
|
fprintf(stderr, "WARNING: Invalid configuration path: `%s'\n", paramString.c_str());
|
|
|
|
}
|
|
|
|
throw invalid_config_path();
|
2021-06-17 04:10:14 +08:00
|
|
|
}
|
2021-05-22 07:21:31 +08:00
|
|
|
}
|
2021-06-19 08:12:32 +08:00
|
|
|
ConfigClassSet getConfigClassSet() const { return ConfigClassSet(configPath); }
|
|
|
|
void set(Optional<KeyRef> configClass, KeyRef knobName, KnobValueRef value) {
|
|
|
|
configClassToKnobToValue[configClass.castTo<Key>()][knobName] = value;
|
|
|
|
}
|
|
|
|
void remove(Optional<KeyRef> configClass, KeyRef knobName) {
|
|
|
|
configClassToKnobToValue[configClass.castTo<Key>()].erase(knobName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update(IKnobCollection& knobCollection) const {
|
|
|
|
// Apply global overrides
|
|
|
|
const auto& knobToValue = configClassToKnobToValue.at({});
|
2021-05-15 10:34:21 +08:00
|
|
|
for (const auto& [knobName, knobValue] : knobToValue) {
|
2021-06-19 08:12:32 +08:00
|
|
|
try {
|
|
|
|
knobCollection.setKnob(knobName.toString(), knobValue);
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_invalid_option_value) {
|
|
|
|
TEST(true); // invalid knob in configuration database
|
|
|
|
TraceEvent(SevWarnAlways, "InvalidKnobOptionValue")
|
|
|
|
.detail("KnobName", knobName)
|
|
|
|
.detail("KnobValue", knobValue.toString());
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Apply specific overrides
|
|
|
|
for (const auto& configClass : configPath) {
|
|
|
|
const auto& knobToValue = configClassToKnobToValue.at(configClass);
|
|
|
|
for (const auto& [knobName, knobValue] : knobToValue) {
|
|
|
|
knobCollection.setKnob(knobName.toString(), knobValue);
|
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
bool hasSameConfigPath(ConfigKnobOverrides const& other) const { return configPath == other.configPath; }
|
2021-05-13 01:12:37 +08:00
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, configPath);
|
|
|
|
}
|
|
|
|
} configKnobOverrides;
|
|
|
|
|
|
|
|
class ManualKnobOverrides {
|
|
|
|
std::map<Key, KnobValue> overrides;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ManualKnobOverrides(std::map<std::string, std::string> const& overrides) {
|
|
|
|
for (const auto& [knobName, knobValueString] : overrides) {
|
|
|
|
try {
|
|
|
|
auto knobValue =
|
|
|
|
IKnobCollection::parseKnobValue(knobName, knobValueString, IKnobCollection::Type::TEST);
|
|
|
|
this->overrides[stringToKeyRef(knobName)] = knobValue;
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (e.code() == error_code_invalid_option) {
|
|
|
|
TEST(true); // Attempted to manually set invalid knob option
|
|
|
|
if (!g_network->isSimulated()) {
|
|
|
|
fprintf(stderr, "WARNING: Unrecognized knob option '%s'\n", knobName.c_str());
|
|
|
|
}
|
|
|
|
TraceEvent(SevWarnAlways, "UnrecognizedKnobOption").detail("Knob", printable(knobName));
|
|
|
|
} else if (e.code() == error_code_invalid_option_value) {
|
|
|
|
TEST(true); // Invalid manually set knob value
|
|
|
|
if (!g_network->isSimulated()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: Invalid value '%s' for knob option '%s'\n",
|
|
|
|
knobValueString.c_str(),
|
|
|
|
knobName.c_str());
|
|
|
|
}
|
|
|
|
TraceEvent(SevWarnAlways, "InvalidKnobValue")
|
|
|
|
.detail("Knob", printable(knobName))
|
|
|
|
.detail("Value", printable(knobValueString));
|
|
|
|
} else {
|
|
|
|
throw e;
|
2021-06-18 13:05:28 +08:00
|
|
|
}
|
2021-06-03 14:40:52 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-18 10:14:32 +08:00
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
void update(IKnobCollection& knobCollection) {
|
|
|
|
for (const auto& [knobName, knobValue] : overrides) {
|
|
|
|
knobCollection.setKnob(knobName.toString(), knobValue);
|
|
|
|
}
|
2021-05-13 01:12:37 +08:00
|
|
|
}
|
2021-06-19 08:12:32 +08:00
|
|
|
} manualKnobOverrides;
|
2021-06-03 01:04:46 +08:00
|
|
|
|
2021-06-07 15:29:36 +08:00
|
|
|
IKnobCollection& getKnobs() {
|
2021-06-10 13:33:00 +08:00
|
|
|
return testKnobCollection ? *testKnobCollection : IKnobCollection::getMutableGlobalKnobCollection();
|
2021-06-07 15:29:36 +08:00
|
|
|
}
|
2021-06-03 01:04:46 +08:00
|
|
|
|
2021-06-07 15:29:36 +08:00
|
|
|
IKnobCollection const& getKnobs() const {
|
2021-06-10 13:33:00 +08:00
|
|
|
return testKnobCollection ? *testKnobCollection : IKnobCollection::getGlobalKnobCollection();
|
2021-06-07 15:29:36 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-14 07:08:02 +08:00
|
|
|
CounterCollection cc;
|
|
|
|
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-06-17 02:34:20 +08:00
|
|
|
TEST(true); // All local information is outdated
|
2021-04-25 08:22:58 +08:00
|
|
|
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-07-19 05:26:15 +08:00
|
|
|
RangeResult 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-06-03 01:04:46 +08:00
|
|
|
self->configKnobOverrides.set(configKey.configClass,
|
|
|
|
configKey.knobName,
|
|
|
|
ObjectReader::fromStringRef<KnobValue>(kv.value, IncludeVersion()));
|
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-14 15:41:02 +08:00
|
|
|
void updateInMemoryState(Version lastSeenVersion) {
|
|
|
|
this->lastSeenVersion = lastSeenVersion;
|
2021-06-10 11:50:00 +08:00
|
|
|
// TODO: Support randomization?
|
2021-07-17 15:11:40 +08:00
|
|
|
getKnobs().reset(Randomize::False, g_network->isSimulated() ? IsSimulated::True : IsSimulated::False);
|
2021-06-03 01:04:46 +08:00
|
|
|
configKnobOverrides.update(getKnobs());
|
|
|
|
manualKnobOverrides.update(getKnobs());
|
2021-04-27 04:12:30 +08:00
|
|
|
// Must reinitialize in order to update dependent knobs
|
2021-07-17 15:11:40 +08:00
|
|
|
getKnobs().initialize(Randomize::False, g_network->isSimulated() ? IsSimulated::True : IsSimulated::False);
|
2021-04-27 04:12:30 +08:00
|
|
|
}
|
|
|
|
|
2021-05-13 08:23:32 +08:00
|
|
|
ACTOR static Future<Void> setSnapshot(LocalConfigurationImpl* self,
|
2021-06-03 01:04:46 +08:00
|
|
|
std::map<ConfigKey, KnobValue> 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-06-03 01:04:46 +08:00
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(BinaryWriter::toValue(configKey, IncludeVersion()).withPrefix(knobOverrideKeys.begin),
|
|
|
|
ObjectWriter::toValue(knobValue, IncludeVersion())));
|
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-06-15 11:19:05 +08:00
|
|
|
ASSERT_GT(versionedMutation.version, self->lastSeenVersion);
|
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-06-03 01:04:46 +08:00
|
|
|
self->kvStore->set(KeyValueRef(serializedKey.withPrefix(knobOverrideKeys.begin),
|
|
|
|
ObjectWriter::toValue(mutation.getValue(), IncludeVersion())));
|
|
|
|
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-05-14 15:41:02 +08:00
|
|
|
self->updateInMemoryState(mostRecentVersion);
|
2021-04-26 16:06:16 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ACTOR static Future<Void> consumeInternal(LocalConfigurationImpl* self, ConfigBroadcastInterface broadcaster) {
|
2021-05-23 15:41:15 +08:00
|
|
|
loop {
|
2021-08-06 09:50:11 +08:00
|
|
|
choose {
|
|
|
|
when(state ConfigBroadcastChangesRequest req = waitNext(broadcaster.getChanges.getFuture())) {
|
|
|
|
wait(self->addChanges(req.changes, req.mostRecentVersion));
|
|
|
|
req.reply.send(ConfigBroadcastChangesReply());
|
|
|
|
}
|
|
|
|
when(ConfigBroadcastSnapshotRequest snapshotReq = waitNext(broadcaster.getSnapshot.getFuture())) {
|
|
|
|
// TODO: Implement
|
|
|
|
// ASSERT_GT(snapshotReply.version, self->lastSeenVersion);
|
|
|
|
// ++self->snapshots;
|
|
|
|
// wait(setSnapshot(self, std::move(snapshotReply.snapshot), snapshotReply.version));
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-13 08:23:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ACTOR static Future<Void> consume(LocalConfigurationImpl* self, ConfigBroadcastInterface broadcaster) {
|
2021-05-23 15:41:15 +08:00
|
|
|
ASSERT(self->initFuture.isValid() && self->initFuture.isReady());
|
|
|
|
loop {
|
|
|
|
choose {
|
2021-08-06 09:50:11 +08:00
|
|
|
when(wait(consumeInternal(self, broadcaster))) { ASSERT(false); }
|
2021-05-30 23:14:22 +08:00
|
|
|
when(wait(self->kvStore->getError())) { ASSERT(false); }
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
}
|
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,
|
2021-06-10 11:50:00 +08:00
|
|
|
IsTest isTest)
|
2021-07-25 02:20:51 +08:00
|
|
|
: id(deterministicRandom()->randomUniqueID()), kvStore(dataFolder, id, "localconf-"),
|
2021-07-25 02:43:19 +08:00
|
|
|
configKnobOverrides(configPath), manualKnobOverrides(manualKnobOverrides), cc("LocalConfiguration"),
|
2021-08-06 09:50:23 +08:00
|
|
|
snapshots("Snapshots", cc), changeRequestsFetched("ChangeRequestsFetched", cc), mutations("Mutations", cc) {
|
2021-07-03 12:41:50 +08:00
|
|
|
if (isTest) {
|
|
|
|
testKnobCollection =
|
|
|
|
IKnobCollection::create(IKnobCollection::Type::TEST,
|
2021-07-17 15:11:40 +08:00
|
|
|
Randomize::False,
|
|
|
|
g_network->isSimulated() ? IsSimulated::True : IsSimulated::False);
|
2021-06-03 01:04:46 +08:00
|
|
|
}
|
2021-05-24 12:03:15 +08:00
|
|
|
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-06-03 01:04:46 +08:00
|
|
|
return getKnobs().getFlowKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientKnobs const& getClientKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-06-03 01:04:46 +08:00
|
|
|
return getKnobs().getClientKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ServerKnobs const& getServerKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-06-03 01:04:46 +08:00
|
|
|
return getKnobs().getServerKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs const& getTestKnobs() const {
|
2021-05-16 13:28:12 +08:00
|
|
|
ASSERT(initFuture.isValid() && initFuture.isReady());
|
2021-06-03 01:04:46 +08:00
|
|
|
return getKnobs().getTestKnobs();
|
2021-04-25 08:22:58 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
Future<Void> consume(ConfigBroadcastInterface const& broadcastInterface) {
|
|
|
|
return consume(this, broadcastInterface);
|
2021-04-26 10:01:17 +08:00
|
|
|
}
|
2021-05-14 15:41:02 +08:00
|
|
|
|
|
|
|
UID getID() const { return id; }
|
2021-06-19 08:12:32 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
Version getLastSeenVersion() const { return lastSeenVersion; }
|
|
|
|
|
|
|
|
ConfigClassSet configClassSet() const { return configKnobOverrides.getConfigClassSet(); }
|
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
static void testManualKnobOverridesInvalidName() {
|
|
|
|
std::map<std::string, std::string> invalidOverrides;
|
|
|
|
invalidOverrides["knob_name_that_does_not_exist"] = "";
|
|
|
|
// Should only trace and not throw an error:
|
|
|
|
ManualKnobOverrides manualKnobOverrides(invalidOverrides);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testManualKnobOverridesInvalidValue() {
|
|
|
|
std::map<std::string, std::string> invalidOverrides;
|
|
|
|
invalidOverrides["test_int"] = "not_an_int";
|
|
|
|
// Should only trace and not throw an error:
|
|
|
|
ManualKnobOverrides manualKnobOverrides(invalidOverrides);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testConfigKnobOverridesInvalidConfigPath() {
|
|
|
|
try {
|
|
|
|
ConfigKnobOverrides configKnobOverrides("#invalid_config_path");
|
|
|
|
ASSERT(false);
|
|
|
|
} catch (Error& e) {
|
|
|
|
ASSERT_EQ(e.code(), error_code_invalid_config_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testConfigKnobOverridesInvalidName() {
|
|
|
|
ConfigKnobOverrides configKnobOverrides;
|
|
|
|
configKnobOverrides.set(
|
|
|
|
{}, "knob_name_that_does_not_exist"_sr, KnobValueRef::create(ParsedKnobValue(int{ 1 })));
|
2021-07-03 12:41:50 +08:00
|
|
|
auto testKnobCollection =
|
2021-07-17 15:11:40 +08:00
|
|
|
IKnobCollection::create(IKnobCollection::Type::TEST, Randomize::False, IsSimulated::False);
|
2021-06-19 08:12:32 +08:00
|
|
|
// Should only trace and not throw an error:
|
|
|
|
configKnobOverrides.update(*testKnobCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testConfigKnobOverridesInvalidValue() {
|
|
|
|
ConfigKnobOverrides configKnobOverrides;
|
|
|
|
configKnobOverrides.set({}, "test_int"_sr, KnobValueRef::create(ParsedKnobValue("not_an_int")));
|
2021-07-03 12:41:50 +08:00
|
|
|
auto testKnobCollection =
|
2021-07-17 15:11:40 +08:00
|
|
|
IKnobCollection::create(IKnobCollection::Type::TEST, Randomize::False, IsSimulated::False);
|
2021-06-19 08:12:32 +08:00
|
|
|
// Should only trace and not throw an error:
|
|
|
|
configKnobOverrides.update(*testKnobCollection);
|
|
|
|
}
|
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,
|
2021-06-10 11:50:00 +08:00
|
|
|
IsTest isTest)
|
2021-06-11 05:49:05 +08:00
|
|
|
: _impl(std::make_unique<LocalConfigurationImpl>(dataFolder, configPath, manualKnobOverrides, isTest)) {}
|
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() {
|
2021-06-11 05:49:05 +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 {
|
2021-06-11 05:49:05 +08:00
|
|
|
return impl().getFlowKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClientKnobs const& LocalConfiguration::getClientKnobs() const {
|
2021-06-11 05:49:05 +08:00
|
|
|
return impl().getClientKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ServerKnobs const& LocalConfiguration::getServerKnobs() const {
|
2021-06-11 05:49:05 +08:00
|
|
|
return impl().getServerKnobs();
|
2021-05-12 04:33:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestKnobs const& LocalConfiguration::getTestKnobs() const {
|
2021-06-11 05:49:05 +08:00
|
|
|
return impl().getTestKnobs();
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
Future<Void> LocalConfiguration::consume(ConfigBroadcastInterface const& broadcaster) {
|
2021-06-11 05:49:05 +08:00
|
|
|
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) {
|
2021-06-11 05:49:05 +08:00
|
|
|
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 {
|
2021-06-11 05:49:05 +08:00
|
|
|
return impl().getID();
|
2021-05-14 15:41:02 +08:00
|
|
|
}
|
2021-06-17 02:34:20 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
Version LocalConfiguration::lastSeenVersion() const {
|
|
|
|
return impl().getLastSeenVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigClassSet LocalConfiguration::configClassSet() const {
|
|
|
|
return impl().configClassSet();
|
|
|
|
}
|
|
|
|
|
2021-06-17 04:10:14 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ManualKnobOverrides/InvalidName") {
|
2021-06-19 08:12:32 +08:00
|
|
|
LocalConfigurationImpl::testManualKnobOverridesInvalidName();
|
2021-06-17 02:34:20 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2021-06-17 03:16:12 +08:00
|
|
|
|
2021-06-17 04:10:14 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ManualKnobOverrides/InvalidValue") {
|
2021-06-19 08:12:32 +08:00
|
|
|
LocalConfigurationImpl::testManualKnobOverridesInvalidValue();
|
2021-06-17 03:16:12 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2021-06-17 04:10:14 +08:00
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ConfigKnobOverrides/InvalidConfigPath") {
|
2021-06-19 08:12:32 +08:00
|
|
|
LocalConfigurationImpl::testConfigKnobOverridesInvalidConfigPath();
|
2021-06-17 04:10:14 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ConfigKnobOverrides/InvalidName") {
|
2021-06-19 08:12:32 +08:00
|
|
|
LocalConfigurationImpl::testConfigKnobOverridesInvalidName();
|
2021-06-17 04:10:14 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ConfigKnobOverrides/InvalidValue") {
|
2021-06-19 08:12:32 +08:00
|
|
|
LocalConfigurationImpl::testConfigKnobOverridesInvalidValue();
|
2021-06-17 04:10:14 +08:00
|
|
|
return Void();
|
|
|
|
}
|