2021-04-15 13:06:37 +08:00
|
|
|
/*
|
2021-07-19 09:25:06 +08:00
|
|
|
* ConfigNode.actor.cpp
|
2021-04-15 13:06:37 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2021-06-07 15:29:36 +08:00
|
|
|
#include "fdbclient/SystemData.h"
|
2021-07-19 09:25:06 +08:00
|
|
|
#include "fdbserver/ConfigNode.h"
|
2021-04-15 13:06:37 +08:00
|
|
|
#include "fdbserver/IKeyValueStore.h"
|
2021-05-24 09:01:50 +08:00
|
|
|
#include "fdbserver/OnDemandStore.h"
|
2021-04-17 11:20:41 +08:00
|
|
|
#include "flow/Arena.h"
|
2021-04-15 13:06:37 +08:00
|
|
|
#include "flow/genericactors.actor.h"
|
2021-04-23 12:29:40 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2021-04-15 13:06:37 +08:00
|
|
|
|
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
|
|
|
|
2021-04-17 11:20:41 +08:00
|
|
|
namespace {
|
|
|
|
|
2021-05-19 09:32:56 +08:00
|
|
|
const KeyRef lastCompactedVersionKey = "lastCompactedVersion"_sr;
|
2021-07-19 03:23:34 +08:00
|
|
|
const KeyRef currentGenerationKey = "currentGeneration"_sr;
|
2022-02-02 14:27:12 +08:00
|
|
|
const KeyRef registeredKey = "registered"_sr;
|
2021-05-19 09:32:56 +08:00
|
|
|
const KeyRangeRef kvKeys = KeyRangeRef("kv/"_sr, "kv0"_sr);
|
|
|
|
const KeyRangeRef mutationKeys = KeyRangeRef("mutation/"_sr, "mutation0"_sr);
|
2021-05-24 16:25:50 +08:00
|
|
|
const KeyRangeRef annotationKeys = KeyRangeRef("annotation/"_sr, "annotation0"_sr);
|
|
|
|
|
|
|
|
Key versionedAnnotationKey(Version version) {
|
|
|
|
ASSERT_GE(version, 0);
|
|
|
|
return BinaryWriter::toValue(bigEndian64(version), IncludeVersion()).withPrefix(annotationKeys.begin);
|
|
|
|
}
|
|
|
|
|
|
|
|
Version getVersionFromVersionedAnnotationKey(KeyRef versionedAnnotationKey) {
|
|
|
|
return fromBigEndian64(BinaryReader::fromStringRef<uint64_t>(
|
|
|
|
versionedAnnotationKey.removePrefix(annotationKeys.begin), IncludeVersion()));
|
|
|
|
}
|
2021-04-17 11:20:41 +08:00
|
|
|
|
2021-04-23 14:00:42 +08:00
|
|
|
Key versionedMutationKey(Version version, uint32_t index) {
|
2021-05-24 16:25:50 +08:00
|
|
|
ASSERT_GE(version, 0);
|
2021-04-17 11:20:41 +08:00
|
|
|
BinaryWriter bw(IncludeVersion());
|
2021-04-23 12:29:40 +08:00
|
|
|
bw << bigEndian64(version);
|
|
|
|
bw << bigEndian32(index);
|
2021-04-17 11:20:41 +08:00
|
|
|
return bw.toValue().withPrefix(mutationKeys.begin);
|
|
|
|
}
|
|
|
|
|
2021-04-22 04:03:34 +08:00
|
|
|
Version getVersionFromVersionedMutationKey(KeyRef versionedMutationKey) {
|
2021-04-23 14:00:42 +08:00
|
|
|
uint64_t bigEndianResult;
|
2021-04-25 04:37:15 +08:00
|
|
|
ASSERT(versionedMutationKey.startsWith(mutationKeys.begin));
|
2021-04-23 14:00:42 +08:00
|
|
|
BinaryReader br(versionedMutationKey.removePrefix(mutationKeys.begin), IncludeVersion());
|
|
|
|
br >> bigEndianResult;
|
|
|
|
return fromBigEndian64(bigEndianResult);
|
2021-04-22 04:03:34 +08:00
|
|
|
}
|
|
|
|
|
2021-10-26 01:17:22 +08:00
|
|
|
template <typename T>
|
|
|
|
void assertCommitted(RangeResult const& range, VectorRef<T> versionedConfigs, std::function<Version(KeyRef)> fn) {
|
|
|
|
if (range.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Verify every versioned value read from disk (minus the last one which
|
|
|
|
// may not be committed on a quorum) exists in the rollforward changes.
|
|
|
|
for (auto it = range.begin(); it != std::prev(range.end()); ++it) {
|
|
|
|
Version version = fn(it->key);
|
|
|
|
auto resultIt = std::find_if(
|
|
|
|
versionedConfigs.begin(), versionedConfigs.end(), [version](T const& o) { return o.version == version; });
|
|
|
|
ASSERT(resultIt != versionedConfigs.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
} // namespace
|
2021-04-15 13:06:37 +08:00
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ConfigNode/Internal/versionedMutationKeys") {
|
2021-04-23 12:29:40 +08:00
|
|
|
std::vector<Key> keys;
|
|
|
|
for (Version version = 0; version < 1000; ++version) {
|
|
|
|
for (int index = 0; index < 5; ++index) {
|
|
|
|
keys.push_back(versionedMutationKey(version, index));
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 14:00:42 +08:00
|
|
|
for (int i = 0; i < 5000; ++i) {
|
|
|
|
ASSERT(getVersionFromVersionedMutationKey(keys[i]) == i / 5);
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
TEST_CASE("/fdbserver/ConfigDB/ConfigNode/Internal/versionedMutationKeyOrdering") {
|
2021-04-23 14:00:42 +08:00
|
|
|
Standalone<VectorRef<KeyRef>> keys;
|
|
|
|
for (Version version = 0; version < 1000; ++version) {
|
|
|
|
for (auto index = 0; index < 5; ++index) {
|
|
|
|
keys.push_back_deep(keys.arena(), versionedMutationKey(version, index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto index = 0; index < 1000; ++index) {
|
|
|
|
keys.push_back_deep(keys.arena(), versionedMutationKey(1000, index));
|
2021-04-23 12:29:40 +08:00
|
|
|
}
|
|
|
|
ASSERT(std::is_sorted(keys.begin(), keys.end()));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
class ConfigNodeImpl {
|
2021-05-24 09:01:50 +08:00
|
|
|
UID id;
|
|
|
|
OnDemandStore kvStore;
|
2021-05-14 07:39:58 +08:00
|
|
|
CounterCollection cc;
|
|
|
|
|
|
|
|
// Follower counters
|
|
|
|
Counter compactRequests;
|
2021-08-25 08:31:28 +08:00
|
|
|
Counter rollbackRequests;
|
|
|
|
Counter rollforwardRequests;
|
2021-05-14 07:39:58 +08:00
|
|
|
Counter successfulChangeRequests;
|
|
|
|
Counter failedChangeRequests;
|
|
|
|
Counter snapshotRequests;
|
2021-07-19 08:56:44 +08:00
|
|
|
Counter getCommittedVersionRequests;
|
2021-05-14 07:39:58 +08:00
|
|
|
|
|
|
|
// Transaction counters
|
|
|
|
Counter successfulCommits;
|
|
|
|
Counter failedCommits;
|
|
|
|
Counter setMutations;
|
|
|
|
Counter clearMutations;
|
|
|
|
Counter getValueRequests;
|
2021-08-07 06:20:12 +08:00
|
|
|
Counter getGenerationRequests;
|
2021-05-14 07:39:58 +08:00
|
|
|
Future<Void> logger;
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<ConfigGeneration> getGeneration(ConfigNodeImpl* self) {
|
2021-07-19 03:23:34 +08:00
|
|
|
state ConfigGeneration generation;
|
|
|
|
Optional<Value> value = wait(self->kvStore->readValue(currentGenerationKey));
|
2021-04-17 11:20:41 +08:00
|
|
|
if (value.present()) {
|
2021-07-19 03:23:34 +08:00
|
|
|
generation = BinaryReader::fromStringRef<ConfigGeneration>(value.get(), IncludeVersion());
|
2021-04-17 11:20:41 +08:00
|
|
|
} else {
|
2021-07-19 03:23:34 +08:00
|
|
|
self->kvStore->set(KeyValueRef(currentGenerationKey, BinaryWriter::toValue(generation, IncludeVersion())));
|
2021-04-17 11:20:41 +08:00
|
|
|
wait(self->kvStore->commit());
|
|
|
|
}
|
2021-07-19 03:23:34 +08:00
|
|
|
return generation;
|
2021-04-22 12:37:42 +08:00
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Version> getLastCompactedVersion(ConfigNodeImpl* self) {
|
2021-04-25 04:37:15 +08:00
|
|
|
Optional<Value> value = wait(self->kvStore->readValue(lastCompactedVersionKey));
|
|
|
|
state Version lastCompactedVersion = 0;
|
|
|
|
if (value.present()) {
|
|
|
|
lastCompactedVersion = BinaryReader::fromStringRef<Version>(value.get(), IncludeVersion());
|
|
|
|
} else {
|
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(lastCompactedVersionKey, BinaryWriter::toValue(lastCompactedVersion, IncludeVersion())));
|
|
|
|
wait(self->kvStore->commit());
|
|
|
|
}
|
|
|
|
return lastCompactedVersion;
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// Returns all commit annotations between for commits with version in [startVersion, endVersion]
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Standalone<VectorRef<VersionedConfigCommitAnnotationRef>>> getAnnotations(ConfigNodeImpl* self,
|
|
|
|
Version startVersion,
|
|
|
|
Version endVersion) {
|
2021-05-24 16:25:50 +08:00
|
|
|
Key startKey = versionedAnnotationKey(startVersion);
|
|
|
|
Key endKey = versionedAnnotationKey(endVersion + 1);
|
|
|
|
state KeyRangeRef keys(startKey, endKey);
|
2021-07-19 05:26:15 +08:00
|
|
|
RangeResult range = wait(self->kvStore->readRange(keys));
|
2021-05-24 16:25:50 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> result;
|
|
|
|
for (const auto& kv : range) {
|
|
|
|
auto version = getVersionFromVersionedAnnotationKey(kv.key);
|
|
|
|
ASSERT_LE(version, endVersion);
|
|
|
|
auto annotation = BinaryReader::fromStringRef<ConfigCommitAnnotation>(kv.value, IncludeVersion());
|
|
|
|
result.emplace_back_deep(result.arena(), version, annotation);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// Returns all mutations with version in [startVersion, endVersion]
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Standalone<VectorRef<VersionedConfigMutationRef>>> getMutations(ConfigNodeImpl* self,
|
|
|
|
Version startVersion,
|
|
|
|
Version endVersion) {
|
2021-05-24 16:25:50 +08:00
|
|
|
Key startKey = versionedMutationKey(startVersion, 0);
|
|
|
|
Key endKey = versionedMutationKey(endVersion + 1, 0);
|
|
|
|
state KeyRangeRef keys(startKey, endKey);
|
2021-07-19 05:26:15 +08:00
|
|
|
RangeResult range = wait(self->kvStore->readRange(keys));
|
2021-05-12 02:12:19 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> result;
|
2021-07-19 09:25:06 +08:00
|
|
|
for (const auto& kv : range) {
|
2021-04-23 14:00:42 +08:00
|
|
|
auto version = getVersionFromVersionedMutationKey(kv.key);
|
2021-05-24 16:25:50 +08:00
|
|
|
ASSERT_LE(version, endVersion);
|
2021-06-03 01:04:46 +08:00
|
|
|
auto mutation = ObjectReader::fromStringRef<ConfigMutation>(kv.value, IncludeVersion());
|
2021-04-17 11:20:41 +08:00
|
|
|
result.emplace_back_deep(result.arena(), version, mutation);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getChanges(ConfigNodeImpl* self, ConfigFollowerGetChangesRequest req) {
|
2021-04-25 04:37:15 +08:00
|
|
|
Version lastCompactedVersion = wait(getLastCompactedVersion(self));
|
|
|
|
if (req.lastSeenVersion < lastCompactedVersion) {
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->failedChangeRequests;
|
2021-04-24 08:49:57 +08:00
|
|
|
req.reply.sendError(version_already_compacted());
|
2021-04-24 09:40:32 +08:00
|
|
|
return Void();
|
2021-04-24 08:49:57 +08:00
|
|
|
}
|
2021-07-19 03:23:34 +08:00
|
|
|
state Version committedVersion =
|
|
|
|
wait(map(getGeneration(self), [](auto const& gen) { return gen.committedVersion; }));
|
2022-02-02 14:27:12 +08:00
|
|
|
if (committedVersion < req.mostRecentVersion) {
|
|
|
|
// Handle a very rare case where a ConfigNode loses data between
|
|
|
|
// responding with a committed version and responding to the
|
|
|
|
// subsequent get changes request.
|
|
|
|
TEST(true); // ConfigNode data loss occurred on a minority of coordinators
|
|
|
|
req.reply.sendError(process_behind()); // Reuse the process_behind error
|
|
|
|
return Void();
|
|
|
|
}
|
2021-05-24 16:25:50 +08:00
|
|
|
state Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations =
|
2021-04-25 04:37:15 +08:00
|
|
|
wait(getMutations(self, req.lastSeenVersion + 1, committedVersion));
|
2021-05-24 16:25:50 +08:00
|
|
|
state Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> versionedAnnotations =
|
|
|
|
wait(getAnnotations(self, req.lastSeenVersion + 1, committedVersion));
|
2021-08-03 06:50:10 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigNodeSendingChanges", self->id)
|
2021-04-26 05:35:56 +08:00
|
|
|
.detail("ReqLastSeenVersion", req.lastSeenVersion)
|
|
|
|
.detail("CommittedVersion", committedVersion)
|
2021-05-24 16:25:50 +08:00
|
|
|
.detail("NumMutations", versionedMutations.size())
|
|
|
|
.detail("NumCommits", versionedAnnotations.size());
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->successfulChangeRequests;
|
2021-05-24 16:25:50 +08:00
|
|
|
req.reply.send(ConfigFollowerGetChangesReply{ committedVersion, versionedMutations, versionedAnnotations });
|
2021-04-22 12:37:42 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// New transactions increment the database's current live version. This effectively serves as a lock, providing
|
|
|
|
// serializability
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getNewGeneration(ConfigNodeImpl* self, ConfigTransactionGetGenerationRequest req) {
|
2021-07-19 03:23:34 +08:00
|
|
|
state ConfigGeneration generation = wait(getGeneration(self));
|
|
|
|
++generation.liveVersion;
|
2021-08-08 09:35:12 +08:00
|
|
|
if (req.lastSeenLiveVersion.present()) {
|
|
|
|
TEST(req.lastSeenLiveVersion.get() >= generation.liveVersion); // Node is lagging behind some other node
|
|
|
|
generation.liveVersion = std::max(generation.liveVersion, req.lastSeenLiveVersion.get() + 1);
|
|
|
|
}
|
2021-07-19 03:23:34 +08:00
|
|
|
self->kvStore->set(KeyValueRef(currentGenerationKey, BinaryWriter::toValue(generation, IncludeVersion())));
|
2021-04-15 13:06:37 +08:00
|
|
|
wait(self->kvStore->commit());
|
2021-07-19 03:23:34 +08:00
|
|
|
req.reply.send(ConfigTransactionGetGenerationReply{ generation });
|
2021-04-15 13:06:37 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> get(ConfigNodeImpl* self, ConfigTransactionGetRequest req) {
|
2021-07-19 03:23:34 +08:00
|
|
|
ConfigGeneration currentGeneration = wait(getGeneration(self));
|
|
|
|
if (req.generation != currentGeneration) {
|
|
|
|
// TODO: Also send information about highest seen version
|
2021-04-15 13:06:37 +08:00
|
|
|
req.reply.sendError(transaction_too_old());
|
|
|
|
return Void();
|
|
|
|
}
|
2021-06-03 01:04:46 +08:00
|
|
|
state Optional<Value> serializedValue =
|
2021-05-12 03:00:44 +08:00
|
|
|
wait(self->kvStore->readValue(BinaryWriter::toValue(req.key, IncludeVersion()).withPrefix(kvKeys.begin)));
|
2021-06-03 01:04:46 +08:00
|
|
|
state Optional<KnobValue> value;
|
|
|
|
if (serializedValue.present()) {
|
|
|
|
value = ObjectReader::fromStringRef<KnobValue>(serializedValue.get(), IncludeVersion());
|
|
|
|
}
|
2021-07-19 03:23:34 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations =
|
|
|
|
wait(getMutations(self, 0, req.generation.committedVersion));
|
2021-07-19 09:25:06 +08:00
|
|
|
for (const auto& versionedMutation : versionedMutations) {
|
|
|
|
const auto& mutation = versionedMutation.mutation;
|
2021-05-15 10:34:21 +08:00
|
|
|
if (mutation.getKey() == req.key) {
|
2021-06-07 15:29:36 +08:00
|
|
|
if (mutation.isSet()) {
|
|
|
|
value = mutation.getValue();
|
|
|
|
} else {
|
|
|
|
value = {};
|
|
|
|
}
|
2021-04-17 11:20:41 +08:00
|
|
|
}
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-06-03 01:04:46 +08:00
|
|
|
req.reply.send(ConfigTransactionGetReply{ value });
|
2021-04-15 13:06:37 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// Retrieve all configuration classes that contain explicitly defined knobs
|
|
|
|
// TODO: Currently it is possible that extra configuration classes may be returned, we
|
|
|
|
// may want to fix this to clean up the contract
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getConfigClasses(ConfigNodeImpl* self, ConfigTransactionGetConfigClassesRequest req) {
|
2021-07-19 03:23:34 +08:00
|
|
|
ConfigGeneration currentGeneration = wait(getGeneration(self));
|
|
|
|
if (req.generation != currentGeneration) {
|
2021-05-29 18:58:18 +08:00
|
|
|
req.reply.sendError(transaction_too_old());
|
|
|
|
return Void();
|
|
|
|
}
|
2021-07-19 05:26:15 +08:00
|
|
|
state RangeResult snapshot = wait(self->kvStore->readRange(kvKeys));
|
2021-05-29 18:58:18 +08:00
|
|
|
state std::set<Key> configClassesSet;
|
|
|
|
for (const auto& kv : snapshot) {
|
|
|
|
auto configKey =
|
|
|
|
BinaryReader::fromStringRef<ConfigKey>(kv.key.removePrefix(kvKeys.begin), IncludeVersion());
|
|
|
|
if (configKey.configClass.present()) {
|
|
|
|
configClassesSet.insert(configKey.configClass.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state Version lastCompactedVersion = wait(getLastCompactedVersion(self));
|
|
|
|
state Standalone<VectorRef<VersionedConfigMutationRef>> mutations =
|
2021-07-19 03:23:34 +08:00
|
|
|
wait(getMutations(self, lastCompactedVersion + 1, req.generation.committedVersion));
|
2021-05-29 18:58:18 +08:00
|
|
|
for (const auto& versionedMutation : mutations) {
|
|
|
|
auto configClass = versionedMutation.mutation.getConfigClass();
|
|
|
|
if (configClass.present()) {
|
|
|
|
configClassesSet.insert(configClass.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Standalone<VectorRef<KeyRef>> configClasses;
|
|
|
|
for (const auto& configClass : configClassesSet) {
|
|
|
|
configClasses.push_back_deep(configClasses.arena(), configClass);
|
|
|
|
}
|
|
|
|
req.reply.send(ConfigTransactionGetConfigClassesReply{ configClasses });
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// Retrieve all knobs explicitly defined for the specified configuration class
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getKnobs(ConfigNodeImpl* self, ConfigTransactionGetKnobsRequest req) {
|
2021-07-19 03:23:34 +08:00
|
|
|
ConfigGeneration currentGeneration = wait(getGeneration(self));
|
|
|
|
if (req.generation != currentGeneration) {
|
2021-05-29 18:58:18 +08:00
|
|
|
req.reply.sendError(transaction_too_old());
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
// FIXME: Filtering after reading from disk is very inefficient
|
2021-07-19 05:26:15 +08:00
|
|
|
state RangeResult snapshot = wait(self->kvStore->readRange(kvKeys));
|
2021-05-29 18:58:18 +08:00
|
|
|
state std::set<Key> knobSet;
|
|
|
|
for (const auto& kv : snapshot) {
|
|
|
|
auto configKey =
|
|
|
|
BinaryReader::fromStringRef<ConfigKey>(kv.key.removePrefix(kvKeys.begin), IncludeVersion());
|
2021-06-22 11:19:36 +08:00
|
|
|
if (configKey.configClass.template castTo<Key>() == req.configClass) {
|
2021-05-29 18:58:18 +08:00
|
|
|
knobSet.insert(configKey.knobName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state Version lastCompactedVersion = wait(getLastCompactedVersion(self));
|
|
|
|
state Standalone<VectorRef<VersionedConfigMutationRef>> mutations =
|
2021-07-19 03:23:34 +08:00
|
|
|
wait(getMutations(self, lastCompactedVersion + 1, req.generation.committedVersion));
|
2021-05-29 18:58:18 +08:00
|
|
|
for (const auto& versionedMutation : mutations) {
|
2021-06-22 11:19:36 +08:00
|
|
|
if (versionedMutation.mutation.getConfigClass().template castTo<Key>() == req.configClass) {
|
2021-06-17 07:43:19 +08:00
|
|
|
if (versionedMutation.mutation.isSet()) {
|
|
|
|
knobSet.insert(versionedMutation.mutation.getKnobName());
|
|
|
|
} else {
|
|
|
|
knobSet.erase(versionedMutation.mutation.getKnobName());
|
|
|
|
}
|
2021-05-29 18:58:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Standalone<VectorRef<KeyRef>> knobNames;
|
|
|
|
for (const auto& knobName : knobSet) {
|
|
|
|
knobNames.push_back_deep(knobNames.arena(), knobName);
|
|
|
|
}
|
|
|
|
req.reply.send(ConfigTransactionGetKnobsReply{ knobNames });
|
|
|
|
return Void();
|
2021-04-24 02:39:26 +08:00
|
|
|
}
|
|
|
|
|
2021-08-26 07:21:22 +08:00
|
|
|
ACTOR static Future<Void> commitMutations(ConfigNodeImpl* self,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> mutations,
|
2021-08-28 08:52:33 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> annotations,
|
2021-08-27 03:17:58 +08:00
|
|
|
Version commitVersion) {
|
|
|
|
Version latestVersion = 0;
|
|
|
|
int index = 0;
|
2021-08-26 07:21:22 +08:00
|
|
|
for (const auto& mutation : mutations) {
|
|
|
|
if (mutation.version > commitVersion) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-27 03:17:58 +08:00
|
|
|
// Mutations should be in ascending version order.
|
2021-09-17 00:24:38 +08:00
|
|
|
ASSERT_GE(mutation.version, latestVersion);
|
2021-08-27 03:17:58 +08:00
|
|
|
if (mutation.version > latestVersion) {
|
|
|
|
latestVersion = mutation.version;
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
Key key = versionedMutationKey(mutation.version, index++);
|
2021-08-26 07:21:22 +08:00
|
|
|
Value value = ObjectWriter::toValue(mutation.mutation, IncludeVersion());
|
|
|
|
if (mutation.mutation.isSet()) {
|
|
|
|
TraceEvent("ConfigNodeSetting")
|
|
|
|
.detail("ConfigClass", mutation.mutation.getConfigClass())
|
|
|
|
.detail("KnobName", mutation.mutation.getKnobName())
|
|
|
|
.detail("Value", mutation.mutation.getValue().toString())
|
|
|
|
.detail("Version", mutation.version);
|
|
|
|
++self->setMutations;
|
|
|
|
} else {
|
|
|
|
++self->clearMutations;
|
|
|
|
}
|
|
|
|
self->kvStore->set(KeyValueRef(key, value));
|
|
|
|
}
|
2021-08-28 08:52:33 +08:00
|
|
|
for (const auto& annotation : annotations) {
|
|
|
|
self->kvStore->set(KeyValueRef(versionedAnnotationKey(annotation.version),
|
|
|
|
BinaryWriter::toValue(annotation.annotation, IncludeVersion())));
|
2021-08-27 03:17:58 +08:00
|
|
|
}
|
2021-08-26 07:21:22 +08:00
|
|
|
ConfigGeneration newGeneration = { commitVersion, commitVersion };
|
|
|
|
self->kvStore->set(KeyValueRef(currentGenerationKey, BinaryWriter::toValue(newGeneration, IncludeVersion())));
|
|
|
|
wait(self->kvStore->commit());
|
|
|
|
++self->successfulCommits;
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> commit(ConfigNodeImpl* self, ConfigTransactionCommitRequest req) {
|
2021-07-19 03:23:34 +08:00
|
|
|
ConfigGeneration currentGeneration = wait(getGeneration(self));
|
2021-08-27 15:44:12 +08:00
|
|
|
if (req.generation.committedVersion != currentGeneration.committedVersion) {
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->failedCommits;
|
2021-08-27 15:44:12 +08:00
|
|
|
req.reply.sendError(commit_unknown_result());
|
|
|
|
return Void();
|
|
|
|
} else if (req.generation.liveVersion != currentGeneration.liveVersion) {
|
|
|
|
++self->failedCommits;
|
|
|
|
req.reply.sendError(not_committed());
|
2021-04-15 13:06:37 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2021-08-26 07:21:22 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> mutations;
|
2021-07-19 09:25:06 +08:00
|
|
|
for (const auto& mutation : req.mutations) {
|
2021-08-26 07:21:22 +08:00
|
|
|
mutations.emplace_back_deep(mutations.arena(), req.generation.liveVersion, mutation);
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-08-28 08:52:33 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> annotations;
|
|
|
|
annotations.emplace_back_deep(annotations.arena(), req.generation.liveVersion, req.annotation);
|
|
|
|
wait(commitMutations(self, mutations, annotations, req.generation.liveVersion));
|
2021-04-15 13:06:37 +08:00
|
|
|
req.reply.send(Void());
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> serve(ConfigNodeImpl* self, ConfigTransactionInterface const* cti) {
|
2021-04-15 13:06:37 +08:00
|
|
|
loop {
|
|
|
|
choose {
|
2021-07-19 03:23:34 +08:00
|
|
|
when(ConfigTransactionGetGenerationRequest req = waitNext(cti->getGeneration.getFuture())) {
|
2021-08-07 06:20:12 +08:00
|
|
|
++self->getGenerationRequests;
|
2021-07-19 03:23:34 +08:00
|
|
|
wait(getNewGeneration(self, req));
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
when(ConfigTransactionGetRequest req = waitNext(cti->get.getFuture())) {
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->getValueRequests;
|
2021-05-17 14:14:46 +08:00
|
|
|
wait(get(self, req));
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
when(ConfigTransactionCommitRequest req = waitNext(cti->commit.getFuture())) {
|
2021-05-17 14:14:46 +08:00
|
|
|
wait(commit(self, req));
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-05-29 18:58:18 +08:00
|
|
|
when(ConfigTransactionGetConfigClassesRequest req = waitNext(cti->getClasses.getFuture())) {
|
|
|
|
wait(getConfigClasses(self, req));
|
|
|
|
}
|
|
|
|
when(ConfigTransactionGetKnobsRequest req = waitNext(cti->getKnobs.getFuture())) {
|
|
|
|
wait(getKnobs(self, req));
|
2021-04-24 02:39:26 +08:00
|
|
|
}
|
2021-05-30 23:14:22 +08:00
|
|
|
when(wait(self->kvStore->getError())) { ASSERT(false); }
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getSnapshotAndChanges(ConfigNodeImpl* self,
|
2021-05-19 06:28:44 +08:00
|
|
|
ConfigFollowerGetSnapshotAndChangesRequest req) {
|
|
|
|
state ConfigFollowerGetSnapshotAndChangesReply reply;
|
2021-07-19 05:26:15 +08:00
|
|
|
RangeResult data = wait(self->kvStore->readRange(kvKeys));
|
2021-04-22 04:03:34 +08:00
|
|
|
for (const auto& kv : data) {
|
2021-05-12 02:12:19 +08:00
|
|
|
reply
|
2021-05-13 02:56:45 +08:00
|
|
|
.snapshot[BinaryReader::fromStringRef<ConfigKey>(kv.key.removePrefix(kvKeys.begin), IncludeVersion())] =
|
2021-06-03 01:04:46 +08:00
|
|
|
ObjectReader::fromStringRef<KnobValue>(kv.value, IncludeVersion());
|
2021-04-22 04:03:34 +08:00
|
|
|
}
|
2021-05-19 06:28:44 +08:00
|
|
|
wait(store(reply.snapshotVersion, getLastCompactedVersion(self)));
|
2021-07-19 08:07:10 +08:00
|
|
|
wait(store(reply.changes, getMutations(self, reply.snapshotVersion + 1, req.mostRecentVersion)));
|
|
|
|
wait(store(reply.annotations, getAnnotations(self, reply.snapshotVersion + 1, req.mostRecentVersion)));
|
2021-08-03 06:50:10 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigNodeGettingSnapshot", self->id)
|
2021-05-19 06:28:44 +08:00
|
|
|
.detail("SnapshotVersion", reply.snapshotVersion)
|
|
|
|
.detail("SnapshotSize", reply.snapshot.size())
|
2022-02-02 14:27:12 +08:00
|
|
|
.detail("ChangesSize", reply.changes.size());
|
2021-04-22 04:03:34 +08:00
|
|
|
req.reply.send(reply);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
// Apply mutations from the WAL in mutationKeys into the kvKeys key space.
|
|
|
|
// Periodic compaction prevents the database from growing too large, and improve read performance.
|
|
|
|
// However, commit annotations for compacted mutations are lost
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> compact(ConfigNodeImpl* self, ConfigFollowerCompactRequest req) {
|
2021-04-25 04:37:15 +08:00
|
|
|
state Version lastCompactedVersion = wait(getLastCompactedVersion(self));
|
2021-08-03 06:50:10 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigNodeCompacting", self->id)
|
2021-04-26 05:35:56 +08:00
|
|
|
.detail("Version", req.version)
|
|
|
|
.detail("LastCompacted", lastCompactedVersion);
|
2021-04-25 04:37:15 +08:00
|
|
|
if (req.version <= lastCompactedVersion) {
|
|
|
|
req.reply.send(Void());
|
|
|
|
return Void();
|
|
|
|
}
|
2021-05-12 02:12:19 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations =
|
2021-04-25 04:37:15 +08:00
|
|
|
wait(getMutations(self, lastCompactedVersion + 1, req.version));
|
2021-04-24 00:22:47 +08:00
|
|
|
self->kvStore->clear(
|
2021-04-25 04:37:15 +08:00
|
|
|
KeyRangeRef(versionedMutationKey(lastCompactedVersion + 1, 0), versionedMutationKey(req.version + 1, 0)));
|
2021-05-24 16:25:50 +08:00
|
|
|
self->kvStore->clear(
|
|
|
|
KeyRangeRef(versionedAnnotationKey(lastCompactedVersion + 1), versionedAnnotationKey(req.version + 1)));
|
2021-04-24 00:22:47 +08:00
|
|
|
for (const auto& versionedMutation : versionedMutations) {
|
|
|
|
const auto& version = versionedMutation.version;
|
|
|
|
const auto& mutation = versionedMutation.mutation;
|
|
|
|
if (version > req.version) {
|
2021-04-26 05:35:56 +08:00
|
|
|
break;
|
2021-04-24 00:22:47 +08:00
|
|
|
} else {
|
2021-08-03 06:50:10 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigNodeCompactionApplyingMutation", self->id)
|
2021-05-12 02:12:19 +08:00
|
|
|
.detail("IsSet", mutation.isSet())
|
2021-04-26 05:35:56 +08:00
|
|
|
.detail("MutationVersion", version)
|
|
|
|
.detail("LastCompactedVersion", lastCompactedVersion)
|
|
|
|
.detail("ReqVersion", req.version);
|
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(kvKeys.begin),
|
|
|
|
ObjectWriter::toValue(mutation.getValue(), IncludeVersion())));
|
2021-04-26 05:35:56 +08:00
|
|
|
} else {
|
2021-05-12 02:12:19 +08:00
|
|
|
self->kvStore->clear(singleKeyRange(serializedKey.withPrefix(kvKeys.begin)));
|
2021-04-26 05:35:56 +08:00
|
|
|
}
|
|
|
|
lastCompactedVersion = version;
|
2021-04-24 00:22:47 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-25 04:37:15 +08:00
|
|
|
self->kvStore->set(
|
|
|
|
KeyValueRef(lastCompactedVersionKey, BinaryWriter::toValue(lastCompactedVersion, IncludeVersion())));
|
2021-04-24 00:22:47 +08:00
|
|
|
wait(self->kvStore->commit());
|
|
|
|
req.reply.send(Void());
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-08-26 07:21:22 +08:00
|
|
|
ACTOR static Future<Void> rollforward(ConfigNodeImpl* self, ConfigFollowerRollforwardRequest req) {
|
2021-10-22 14:47:05 +08:00
|
|
|
Version lastCompactedVersion = wait(getLastCompactedVersion(self));
|
|
|
|
if (req.lastKnownCommitted < lastCompactedVersion) {
|
|
|
|
req.reply.sendError(version_already_compacted());
|
|
|
|
return Void();
|
|
|
|
}
|
2021-10-20 08:36:43 +08:00
|
|
|
state ConfigGeneration currentGeneration = wait(getGeneration(self));
|
2021-08-28 08:52:33 +08:00
|
|
|
if (req.lastKnownCommitted != currentGeneration.committedVersion) {
|
2021-10-22 14:47:05 +08:00
|
|
|
req.reply.sendError(transaction_too_old());
|
2021-08-27 03:17:58 +08:00
|
|
|
return Void();
|
2021-08-26 07:21:22 +08:00
|
|
|
}
|
2022-02-02 14:27:12 +08:00
|
|
|
TraceEvent("ConfigNodeRollforward")
|
|
|
|
.detail("RollbackTo", req.rollback)
|
|
|
|
.detail("Target", req.target)
|
|
|
|
.detail("LastKnownCommitted", req.lastKnownCommitted)
|
|
|
|
.detail("Committed", currentGeneration.committedVersion);
|
2021-10-20 08:36:43 +08:00
|
|
|
// Rollback to prior known committed version to erase any commits not
|
|
|
|
// made on a quorum.
|
|
|
|
if (req.rollback.present() && req.rollback.get() < currentGeneration.committedVersion) {
|
2021-10-22 14:47:05 +08:00
|
|
|
if (g_network->isSimulated()) {
|
2021-10-26 01:17:22 +08:00
|
|
|
RangeResult mutationRange = wait(self->kvStore->readRange(
|
|
|
|
KeyRangeRef(versionedMutationKey(req.rollback.get() + 1, 0),
|
|
|
|
versionedMutationKey(currentGeneration.committedVersion + 1, 0))));
|
|
|
|
// assertCommitted(mutationRange, req.mutations, getVersionFromVersionedMutationKey);
|
|
|
|
RangeResult annotationRange = wait(self->kvStore->readRange(
|
|
|
|
KeyRangeRef(versionedAnnotationKey(req.rollback.get() + 1),
|
|
|
|
versionedAnnotationKey(currentGeneration.committedVersion + 1))));
|
|
|
|
// assertCommitted(annotationRange, req.annotations, getVersionFromVersionedAnnotationKey);
|
2021-10-22 14:47:05 +08:00
|
|
|
}
|
2021-10-26 01:17:22 +08:00
|
|
|
self->kvStore->clear(KeyRangeRef(versionedMutationKey(req.rollback.get() + 1, 0),
|
|
|
|
versionedMutationKey(currentGeneration.committedVersion + 1, 0)));
|
|
|
|
self->kvStore->clear(KeyRangeRef(versionedAnnotationKey(req.rollback.get() + 1),
|
|
|
|
versionedAnnotationKey(currentGeneration.committedVersion + 1)));
|
2021-10-20 08:36:43 +08:00
|
|
|
|
|
|
|
currentGeneration.committedVersion = req.rollback.get();
|
|
|
|
// The mutation commit loop below should persist the new generation
|
|
|
|
// to disk, so we don't need to do it here.
|
|
|
|
}
|
|
|
|
// Now rollforward by applying all mutations between last known
|
|
|
|
// committed version and rollforward version.
|
2021-09-17 00:24:48 +08:00
|
|
|
ASSERT_GT(req.mutations[0].version, currentGeneration.committedVersion);
|
2021-08-28 08:52:33 +08:00
|
|
|
wait(commitMutations(self, req.mutations, req.annotations, req.target));
|
2021-08-26 07:21:22 +08:00
|
|
|
req.reply.send(Void());
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> getCommittedVersion(ConfigNodeImpl* self, ConfigFollowerGetCommittedVersionRequest req) {
|
2021-07-19 08:56:44 +08:00
|
|
|
ConfigGeneration generation = wait(getGeneration(self));
|
2021-10-19 03:02:39 +08:00
|
|
|
req.reply.send(ConfigFollowerGetCommittedVersionReply{ generation.committedVersion });
|
2021-07-19 08:56:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ACTOR static Future<Void> serve(ConfigNodeImpl* self, ConfigFollowerInterface const* cfi) {
|
2021-04-17 11:20:41 +08:00
|
|
|
loop {
|
|
|
|
choose {
|
2021-05-19 06:28:44 +08:00
|
|
|
when(ConfigFollowerGetSnapshotAndChangesRequest req =
|
|
|
|
waitNext(cfi->getSnapshotAndChanges.getFuture())) {
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->snapshotRequests;
|
2021-05-19 06:28:44 +08:00
|
|
|
wait(getSnapshotAndChanges(self, req));
|
2021-04-17 11:20:41 +08:00
|
|
|
}
|
|
|
|
when(ConfigFollowerGetChangesRequest req = waitNext(cfi->getChanges.getFuture())) {
|
2021-05-17 14:14:46 +08:00
|
|
|
wait(getChanges(self, req));
|
2021-04-17 11:20:41 +08:00
|
|
|
}
|
2021-04-22 03:18:52 +08:00
|
|
|
when(ConfigFollowerCompactRequest req = waitNext(cfi->compact.getFuture())) {
|
2021-05-14 07:39:58 +08:00
|
|
|
++self->compactRequests;
|
2021-05-17 14:14:46 +08:00
|
|
|
wait(compact(self, req));
|
2021-04-22 03:18:52 +08:00
|
|
|
}
|
2021-08-26 07:21:22 +08:00
|
|
|
when(ConfigFollowerRollforwardRequest req = waitNext(cfi->rollforward.getFuture())) {
|
|
|
|
++self->rollforwardRequests;
|
|
|
|
wait(rollforward(self, req));
|
|
|
|
}
|
2021-07-19 08:56:44 +08:00
|
|
|
when(ConfigFollowerGetCommittedVersionRequest req = waitNext(cfi->getCommittedVersion.getFuture())) {
|
|
|
|
++self->getCommittedVersionRequests;
|
|
|
|
wait(getCommittedVersion(self, req));
|
|
|
|
}
|
2021-05-30 23:14:22 +08:00
|
|
|
when(wait(self->kvStore->getError())) { ASSERT(false); }
|
2021-04-17 11:20:41 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2022-02-02 14:27:12 +08:00
|
|
|
ACTOR static Future<Void> serve(ConfigNodeImpl* self, ConfigBroadcastInterface const* cbi, bool infinite) {
|
|
|
|
loop {
|
2022-02-09 08:05:45 +08:00
|
|
|
// Normally, the ConfigBroadcaster will first send a
|
|
|
|
// ConfigBroadcastRegisteredRequest, followed by a
|
|
|
|
// ConfigBroadcastReadyRequest. However, if the cluster controller
|
|
|
|
// the broadcaster is running on fails in between sending these two
|
|
|
|
// messages, the new broadcaster may need to resend its registered
|
|
|
|
// request. So we need to listen for either message in a loop to
|
|
|
|
// guarantee no pattern of failure will result in a stuck
|
|
|
|
// ConfigNode.
|
2022-02-02 14:27:12 +08:00
|
|
|
choose {
|
|
|
|
when(state ConfigBroadcastRegisteredRequest req = waitNext(cbi->registered.getFuture())) {
|
|
|
|
bool isRegistered = wait(registered(self));
|
|
|
|
req.reply.send(ConfigBroadcastRegisteredReply{ isRegistered });
|
|
|
|
}
|
|
|
|
when(ConfigBroadcastReadyRequest readyReq = waitNext(cbi->ready.getFuture())) {
|
|
|
|
readyReq.reply.send(ConfigBroadcastReadyReply{});
|
|
|
|
if (!infinite) {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> serve(ConfigNodeImpl* self,
|
|
|
|
ConfigBroadcastInterface const* cbi,
|
|
|
|
ConfigTransactionInterface const* cti,
|
|
|
|
ConfigFollowerInterface const* cfi) {
|
|
|
|
wait(serve(self, cbi, false));
|
|
|
|
|
|
|
|
self->kvStore->set(KeyValueRef(registeredKey, BinaryWriter::toValue(true, IncludeVersion())));
|
|
|
|
wait(self->kvStore->commit());
|
|
|
|
|
|
|
|
// Shouldn't return (coordinationServer will throw an error if it does).
|
|
|
|
wait(serve(self, cbi, true) || serve(self, cti) || serve(self, cfi));
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<bool> registered(ConfigNodeImpl* self) {
|
|
|
|
Optional<Value> value = wait(self->kvStore->readValue(registeredKey));
|
|
|
|
return value.present();
|
|
|
|
}
|
|
|
|
|
2021-04-15 13:06:37 +08:00
|
|
|
public:
|
2021-07-19 09:25:06 +08:00
|
|
|
ConfigNodeImpl(std::string const& folder)
|
2021-10-19 03:02:39 +08:00
|
|
|
: id(deterministicRandom()->randomUniqueID()), kvStore(folder, id, "globalconf-"), cc("ConfigNode"),
|
|
|
|
compactRequests("CompactRequests", cc), rollbackRequests("RollbackRequests", cc),
|
2021-08-25 08:31:28 +08:00
|
|
|
rollforwardRequests("RollforwardRequests", cc), successfulChangeRequests("SuccessfulChangeRequests", cc),
|
2021-05-24 09:01:50 +08:00
|
|
|
failedChangeRequests("FailedChangeRequests", cc), snapshotRequests("SnapshotRequests", cc),
|
2021-07-19 08:56:44 +08:00
|
|
|
getCommittedVersionRequests("GetCommittedVersionRequests", cc), successfulCommits("SuccessfulCommits", cc),
|
|
|
|
failedCommits("FailedCommits", cc), setMutations("SetMutations", cc), clearMutations("ClearMutations", cc),
|
2021-08-07 06:20:12 +08:00
|
|
|
getValueRequests("GetValueRequests", cc), getGenerationRequests("GetGenerationRequests", cc) {
|
2021-08-03 06:50:10 +08:00
|
|
|
logger = traceCounters("ConfigNodeMetrics", id, SERVER_KNOBS->WORKER_LOGGING_INTERVAL, &cc, "ConfigNode");
|
2021-07-19 09:25:06 +08:00
|
|
|
TraceEvent(SevDebug, "StartingConfigNode", id).detail("KVStoreAlreadyExists", kvStore.exists());
|
2021-05-17 14:14:46 +08:00
|
|
|
}
|
|
|
|
|
2022-02-02 14:27:12 +08:00
|
|
|
Future<Void> serve(ConfigBroadcastInterface const& cbi,
|
|
|
|
ConfigTransactionInterface const& cti,
|
|
|
|
ConfigFollowerInterface const& cfi) {
|
|
|
|
return serve(this, &cbi, &cti, &cfi);
|
|
|
|
}
|
|
|
|
|
2022-02-09 04:56:36 +08:00
|
|
|
Future<Void> serve(ConfigTransactionInterface const& cti) { return serve(this, &cti); }
|
|
|
|
|
|
|
|
Future<Void> serve(ConfigFollowerInterface const& cfi) { return serve(this, &cfi); }
|
|
|
|
|
2021-09-10 04:50:07 +08:00
|
|
|
void close() { kvStore.close(); }
|
|
|
|
|
|
|
|
Future<Void> onClosed() { return kvStore.onClosed(); }
|
2021-04-15 13:06:37 +08:00
|
|
|
};
|
|
|
|
|
2021-08-03 03:32:11 +08:00
|
|
|
ConfigNode::ConfigNode(std::string const& folder) : impl(PImpl<ConfigNodeImpl>::create(folder)) {}
|
2021-04-15 13:06:37 +08:00
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
ConfigNode::~ConfigNode() = default;
|
2021-04-15 13:06:37 +08:00
|
|
|
|
2022-02-09 04:56:36 +08:00
|
|
|
Future<Void> ConfigNode::serve(ConfigBroadcastInterface const& cbi,
|
|
|
|
ConfigTransactionInterface const& cti,
|
|
|
|
ConfigFollowerInterface const& cfi) {
|
|
|
|
return impl->serve(cbi, cti, cfi);
|
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
Future<Void> ConfigNode::serve(ConfigTransactionInterface const& cti) {
|
2021-08-03 03:32:11 +08:00
|
|
|
return impl->serve(cti);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2021-07-19 09:25:06 +08:00
|
|
|
Future<Void> ConfigNode::serve(ConfigFollowerInterface const& cfi) {
|
2021-08-03 03:32:11 +08:00
|
|
|
return impl->serve(cfi);
|
2021-04-15 13:06:37 +08:00
|
|
|
}
|
2021-09-10 04:50:07 +08:00
|
|
|
|
|
|
|
void ConfigNode::close() {
|
|
|
|
impl->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> ConfigNode::onClosed() {
|
|
|
|
return impl->onClosed();
|
|
|
|
}
|