diff --git a/fdbserver/ConfigDatabaseUnitTests.actor.cpp b/fdbserver/ConfigDatabaseUnitTests.actor.cpp index 8b3710051b..f0be724e10 100644 --- a/fdbserver/ConfigDatabaseUnitTests.actor.cpp +++ b/fdbserver/ConfigDatabaseUnitTests.actor.cpp @@ -98,18 +98,18 @@ Future runTestUpdates(ConfigStore* configStore, Version* version) { return Void(); } -ACTOR Future runFirstLocalConfiguration(std::string configPath, UID uid) { - state LocalConfiguration localConfiguration(configPath, "./", testManualKnobOverrides, uid); +ACTOR Future runFirstLocalConfiguration(std::string configPath, UID id) { + state LocalConfiguration localConfiguration(configPath, testManualKnobOverrides); state Version version = 1; - wait(localConfiguration.initialize()); + wait(localConfiguration.initialize("./", id)); wait(runTestUpdates(&localConfiguration, &version)); ASSERT(localConfiguration.getTestKnobs() == getExpectedTestKnobsFinal()); return Void(); } -ACTOR Future runSecondLocalConfiguration(std::string configPath, UID uid, TestKnobs const* expectedTestKnobs) { - state LocalConfiguration localConfiguration(configPath, "./", testManualKnobOverrides, uid); - wait(localConfiguration.initialize()); +ACTOR Future runSecondLocalConfiguration(std::string configPath, UID id, TestKnobs const* expectedTestKnobs) { + state LocalConfiguration localConfiguration(configPath, testManualKnobOverrides); + wait(localConfiguration.initialize("./", id)); ASSERT(localConfiguration.getTestKnobs() == *expectedTestKnobs); return Void(); } @@ -131,16 +131,16 @@ TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Simple") { } TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/Restart") { - state UID uid = deterministicRandom()->randomUniqueID(); - wait(runFirstLocalConfiguration("class-A/class-B", uid)); - wait(runSecondLocalConfiguration("class-A/class-B", uid, &getExpectedTestKnobsFinal())); + state UID id = deterministicRandom()->randomUniqueID(); + wait(runFirstLocalConfiguration("class-A/class-B", id)); + wait(runSecondLocalConfiguration("class-A/class-B", id, &getExpectedTestKnobsFinal())); return Void(); } TEST_CASE("/fdbserver/ConfigDB/LocalConfiguration/FreshRestart") { - state UID uid = deterministicRandom()->randomUniqueID(); - wait(runFirstLocalConfiguration("class-A/class-B", uid)); - wait(runSecondLocalConfiguration("class-B/class-A", uid, &getExpectedTestKnobsEmptyConfig())); + state UID id = deterministicRandom()->randomUniqueID(); + wait(runFirstLocalConfiguration("class-A/class-B", id)); + wait(runSecondLocalConfiguration("class-B/class-A", id, &getExpectedTestKnobsEmptyConfig())); return Void(); } @@ -148,10 +148,10 @@ TEST_CASE("/fdbserver/ConfigDB/ConfigBroadcaster/Simple") { state ConfigBroadcaster broadcaster(ConfigFollowerInterface{}); state Reference> cfi = IDependentAsyncVar::create(makeReference>()); - state LocalConfiguration localConfiguration("class-A/class-B", "./", {}, deterministicRandom()->randomUniqueID()); + state LocalConfiguration localConfiguration("class-A/class-B", testManualKnobOverrides); state Version version = 1; state ActorCollection actors(false); - wait(localConfiguration.initialize()); + wait(localConfiguration.initialize("./", deterministicRandom()->randomUniqueID())); actors.add(broadcaster.serve(cfi->get())); actors.add(localConfiguration.consume(cfi)); Future updater = runTestUpdates(&broadcaster, &version); diff --git a/fdbserver/LocalConfiguration.actor.cpp b/fdbserver/LocalConfiguration.actor.cpp index 8136f625ae..8bbf580fb2 100644 --- a/fdbserver/LocalConfiguration.actor.cpp +++ b/fdbserver/LocalConfiguration.actor.cpp @@ -108,16 +108,24 @@ public: } // namespace class LocalConfigurationImpl : public NonCopyable { - IKeyValueStore* kvStore; + IKeyValueStore* kvStore{ nullptr }; Future initFuture; FlowKnobs flowKnobs; ClientKnobs clientKnobs; ServerKnobs serverKnobs; TestKnobs testKnobs; + Version mostRecentVersion{ 0 }; ManualKnobOverrides manualKnobOverrides; ConfigKnobOverrides configKnobOverrides; ActorCollection actors{ false }; + CounterCollection cc; + Counter broadcasterChanges; + Counter snapshots; + Counter changeRequestsFetched; + Counter mutations; + Future logger; + ACTOR static Future saveConfigPath(LocalConfigurationImpl* self) { self->kvStore->set( KeyValueRef(configPathKey, BinaryWriter::toValue(self->configKnobOverrides, IncludeVersion()))); @@ -144,7 +152,14 @@ class LocalConfigurationImpl : public NonCopyable { return result; } - ACTOR static Future initialize(LocalConfigurationImpl* self) { + ACTOR static Future initialize(LocalConfigurationImpl* self, std::string dataFolder, UID id) { + platform::createDirectory(dataFolder); + self->kvStore = keyValueStoreMemory(joinPath(dataFolder, "localconf-" + id.toString()), id, 500e6); + self->logger = traceCounters("LocalConfigurationMetrics", + id, + SERVER_KNOBS->WORKER_LOGGING_INTERVAL, + &self->cc, + "LocalConfigurationMetrics"); wait(self->kvStore->init()); state Optional storedConfigPathValue = wait(self->kvStore->readValue(configPathKey)); if (!storedConfigPathValue.present()) { @@ -197,6 +212,7 @@ class LocalConfigurationImpl : public NonCopyable { std::map snapshot, Version lastCompactedVersion) { // TODO: Concurrency control? + ++self->snapshots; self->kvStore->clear(knobOverrideKeys); for (const auto& [configKey, knobValue] : snapshot) { self->configKnobOverrides.set(configKey.configClass, configKey.knobName, knobValue); @@ -215,7 +231,9 @@ class LocalConfigurationImpl : public NonCopyable { Standalone> versionedMutations, Version mostRecentVersion) { // TODO: Concurrency control? + ++self->changeRequestsFetched; for (const auto& versionedMutation : versionedMutations) { + ++self->mutations; const auto &mutation = versionedMutation.mutation; auto serializedKey = BinaryWriter::toValue(mutation.getKey(), IncludeVersion()); if (mutation.isSet()) { @@ -240,7 +258,7 @@ class LocalConfigurationImpl : public NonCopyable { // state Version lastSeenVersion = wait(impl->getLastSeenVersion()); state SimpleConfigConsumer consumer(broadcaster->get()); choose { - when(wait(broadcaster->onChange())) {} + when(wait(broadcaster->onChange())) { ++impl->broadcasterChanges; } when(wait(brokenPromiseToNever(consumer.consume(*self)))) { ASSERT(false); } when(wait(impl->actors.getResult())) { ASSERT(false); } } @@ -256,20 +274,20 @@ class LocalConfigurationImpl : public NonCopyable { public: template - LocalConfigurationImpl(std::string const& configPath, - std::string const& dataFolder, - ManualKnobOverrides&& manualKnobOverrides, - UID id) - : configKnobOverrides(configPath), manualKnobOverrides(std::forward(manualKnobOverrides)) { - platform::createDirectory(dataFolder); - kvStore = keyValueStoreMemory(joinPath(dataFolder, "localconf-" + id.toString()), id, 500e6); + LocalConfigurationImpl(std::string const& configPath, ManualKnobOverrides&& manualKnobOverrides) + : cc("LocalConfiguration"), broadcasterChanges("BroadcasterChanges", cc), snapshots("Snapshots", cc), + changeRequestsFetched("ChangeRequestsFetched", cc), mutations("Mutations", cc), configKnobOverrides(configPath), + manualKnobOverrides(std::forward(manualKnobOverrides)) {} + + ~LocalConfigurationImpl() { + if (kvStore) { + kvStore->close(); + } } - ~LocalConfigurationImpl() { kvStore->close(); } - - Future initialize() { + Future initialize(std::string const& dataFolder, UID id) { ASSERT(!initFuture.isValid()); - initFuture = initialize(this); + initFuture = initialize(this, dataFolder, id); return initFuture; } @@ -308,22 +326,16 @@ public: } }; -LocalConfiguration::LocalConfiguration(std::string const& configPath, - std::string const& dataFolder, - std::map&& manualKnobOverrides, - UID id) - : impl(std::make_unique(configPath, dataFolder, std::move(manualKnobOverrides), id)) {} +LocalConfiguration::LocalConfiguration(std::string const& configPath, std::map&& manualKnobOverrides) + : impl(std::make_unique(configPath, std::move(manualKnobOverrides))) {} -LocalConfiguration::LocalConfiguration(std::string const& configPath, - std::string const& dataFolder, - std::map const& manualKnobOverrides, - UID id) - : impl(std::make_unique(configPath, dataFolder, manualKnobOverrides, id)) {} +LocalConfiguration::LocalConfiguration(std::string const& configPath, std::map const& manualKnobOverrides) + : impl(std::make_unique(configPath, manualKnobOverrides)) {} LocalConfiguration::~LocalConfiguration() = default; -Future LocalConfiguration::initialize() { - return impl->initialize(); +Future LocalConfiguration::initialize(std::string const& dataFolder, UID id) { + return impl->initialize(dataFolder, id); } FlowKnobs const& LocalConfiguration::getFlowKnobs() const { diff --git a/fdbserver/LocalConfiguration.h b/fdbserver/LocalConfiguration.h index 90fcbe0dcc..7ecdcce15d 100644 --- a/fdbserver/LocalConfiguration.h +++ b/fdbserver/LocalConfiguration.h @@ -45,16 +45,10 @@ class LocalConfiguration { std::unique_ptr impl; public: - LocalConfiguration(std::string const& configPath, - std::string const& dataFolder, - std::map const& manualKnobOverrides, - UID id); - LocalConfiguration(std::string const& configPath, - std::string const& dataFolder, - std::map&& manualKnobOverrides, - UID id); + LocalConfiguration(std::string const& configPath, std::map const& manualKnobOverrides); + LocalConfiguration(std::string const& configPath, std::map&& manualKnobOverrides); ~LocalConfiguration(); - Future initialize(); + Future initialize(std::string const& dataFolder, UID id); FlowKnobs const& getFlowKnobs() const; ClientKnobs const& getClientKnobs() const; ServerKnobs const& getServerKnobs() const; diff --git a/fdbserver/worker.actor.cpp b/fdbserver/worker.actor.cpp index dcc697de15..f5c0ea4acc 100644 --- a/fdbserver/worker.actor.cpp +++ b/fdbserver/worker.actor.cpp @@ -2023,8 +2023,8 @@ ACTOR Future fdbd(Reference connFile, std::string configPath) { state vector> actors; state Promise recoveredDiskFiles; - state LocalConfiguration localConfig(configPath, dataFolder, {}, UID{}); - wait(localConfig.initialize()); + state LocalConfiguration localConfig(configPath, {}); + wait(localConfig.initialize(dataFolder, deterministicRandom()->randomUniqueID())); actors.push_back(serveProtocolInfo());