2021-05-12 07:57:05 +08:00
|
|
|
/*
|
2021-05-14 02:22:25 +08:00
|
|
|
* ConfigBroadcaster.actor.cpp
|
2021-05-12 07:57:05 +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.
|
|
|
|
*/
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2021-05-12 07:57:05 +08:00
|
|
|
#include "fdbserver/ConfigBroadcaster.h"
|
2021-06-01 18:12:47 +08:00
|
|
|
#include "fdbserver/Knobs.h"
|
2021-05-18 06:31:03 +08:00
|
|
|
#include "fdbserver/IConfigConsumer.h"
|
2021-05-23 15:41:15 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2021-05-12 07:57:05 +08:00
|
|
|
#include "flow/actorcompiler.h" // must be last include
|
|
|
|
|
2021-05-14 15:41:02 +08:00
|
|
|
namespace {
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
bool matchesConfigClass(ConfigClassSet const& configClassSet, Optional<KeyRef> configClass) {
|
|
|
|
return !configClass.present() || configClassSet.contains(configClass.get());
|
2021-05-14 15:41:02 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 07:50:35 +08:00
|
|
|
// Helper functions for STL containers, with flow-friendly error handling
|
|
|
|
template <class MapContainer, class K>
|
2021-06-15 11:19:05 +08:00
|
|
|
auto get(MapContainer& m, K const& k) -> decltype(m.at(k)) {
|
|
|
|
auto it = m.find(k);
|
|
|
|
ASSERT(it != m.end());
|
2021-05-23 15:41:15 +08:00
|
|
|
return it->second;
|
|
|
|
}
|
2021-05-24 07:50:35 +08:00
|
|
|
template <class Container, class K>
|
|
|
|
void remove(Container& container, K const& k) {
|
|
|
|
auto it = container.find(k);
|
|
|
|
ASSERT(it != container.end());
|
|
|
|
container.erase(it);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
} // namespace
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-06-19 08:12:32 +08:00
|
|
|
class ConfigBroadcasterImpl {
|
2021-08-10 02:49:57 +08:00
|
|
|
// Holds information about each client connected to the broadcaster.
|
|
|
|
struct BroadcastClientDetails {
|
|
|
|
// Triggered when the worker dies.
|
|
|
|
Future<Void> watcher;
|
|
|
|
ConfigClassSet configClassSet;
|
|
|
|
Version lastSeenVersion;
|
|
|
|
ConfigBroadcastInterface broadcastInterface;
|
|
|
|
|
|
|
|
bool operator==(BroadcastClientDetails const& rhs) const {
|
|
|
|
return configClassSet == rhs.configClassSet && lastSeenVersion == rhs.lastSeenVersion &&
|
|
|
|
broadcastInterface == rhs.broadcastInterface;
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
2021-08-10 02:49:57 +08:00
|
|
|
bool operator!=(BroadcastClientDetails const& rhs) const { return !(*this == rhs); }
|
2021-08-18 02:45:50 +08:00
|
|
|
|
|
|
|
BroadcastClientDetails() = default;
|
|
|
|
BroadcastClientDetails(Future<Void> watcher,
|
|
|
|
ConfigClassSet const& configClassSet,
|
|
|
|
Version lastSeenVersion,
|
|
|
|
ConfigBroadcastInterface broadcastInterface)
|
|
|
|
: watcher(watcher), configClassSet(configClassSet), lastSeenVersion(lastSeenVersion),
|
|
|
|
broadcastInterface(broadcastInterface) {}
|
2021-08-10 02:49:57 +08:00
|
|
|
};
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-06-03 01:04:46 +08:00
|
|
|
std::map<ConfigKey, KnobValue> snapshot;
|
2021-05-24 16:25:50 +08:00
|
|
|
std::deque<VersionedConfigMutation> mutationHistory;
|
|
|
|
std::deque<VersionedConfigCommitAnnotation> annotationHistory;
|
2021-05-12 07:57:05 +08:00
|
|
|
Version lastCompactedVersion;
|
|
|
|
Version mostRecentVersion;
|
|
|
|
std::unique_ptr<IConfigConsumer> consumer;
|
2021-08-11 03:41:41 +08:00
|
|
|
Future<Void> consumerFuture;
|
2021-05-12 07:57:05 +08:00
|
|
|
ActorCollection actors{ false };
|
2021-08-18 02:45:50 +08:00
|
|
|
std::map<UID, BroadcastClientDetails> clients;
|
2021-08-20 08:07:21 +08:00
|
|
|
std::map<UID, Future<Void>> clientFailures;
|
2021-05-12 07:57:05 +08:00
|
|
|
|
2021-05-14 07:39:58 +08:00
|
|
|
UID id;
|
2021-05-12 07:57:05 +08:00
|
|
|
CounterCollection cc;
|
|
|
|
Counter compactRequest;
|
2021-08-06 09:50:11 +08:00
|
|
|
Counter successfulChangeRequest;
|
2021-05-12 07:57:05 +08:00
|
|
|
Counter failedChangeRequest;
|
2021-05-13 02:56:45 +08:00
|
|
|
Counter snapshotRequest;
|
2021-05-12 07:57:05 +08:00
|
|
|
Future<Void> logger;
|
|
|
|
|
2021-08-18 02:45:50 +08:00
|
|
|
Future<Void> pushSnapshot(Version snapshotVersion, BroadcastClientDetails const& client) {
|
2021-08-11 13:59:11 +08:00
|
|
|
if (client.lastSeenVersion >= snapshotVersion) {
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
++snapshotRequest;
|
|
|
|
ConfigBroadcastSnapshotRequest request;
|
2021-08-18 02:45:50 +08:00
|
|
|
for (const auto& [key, value] : snapshot) {
|
2021-08-11 13:59:11 +08:00
|
|
|
if (matchesConfigClass(client.configClassSet, key.configClass)) {
|
|
|
|
request.snapshot[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request.version = snapshotVersion;
|
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterSnapshotRequest", id)
|
|
|
|
.detail("Size", request.snapshot.size())
|
|
|
|
.detail("Version", request.version);
|
2021-08-19 04:24:00 +08:00
|
|
|
return success(brokenPromiseToNever(client.broadcastInterface.snapshot.getReply(request)));
|
2021-08-11 13:59:11 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 11:57:50 +08:00
|
|
|
template <class Changes>
|
2021-08-10 02:49:57 +08:00
|
|
|
Future<Void> pushChanges(BroadcastClientDetails& client, Changes const& changes) {
|
2021-08-07 03:42:07 +08:00
|
|
|
// Skip if client has already seen the latest version.
|
2021-08-10 02:49:57 +08:00
|
|
|
if (client.lastSeenVersion >= mostRecentVersion) {
|
2021-08-07 03:42:07 +08:00
|
|
|
return Void();
|
|
|
|
}
|
2021-05-19 09:32:56 +08:00
|
|
|
|
2021-08-07 03:42:07 +08:00
|
|
|
ConfigBroadcastChangesRequest req;
|
2021-05-19 09:32:56 +08:00
|
|
|
for (const auto& versionedMutation : changes) {
|
2021-08-10 02:49:57 +08:00
|
|
|
if (versionedMutation.version > client.lastSeenVersion &&
|
|
|
|
matchesConfigClass(client.configClassSet, versionedMutation.mutation.getConfigClass())) {
|
2021-06-07 15:29:36 +08:00
|
|
|
TraceEvent te(SevDebug, "ConfigBroadcasterSendingChangeMutation", id);
|
|
|
|
te.detail("Version", versionedMutation.version)
|
2021-08-10 02:49:57 +08:00
|
|
|
.detail("ReqLastSeenVersion", client.lastSeenVersion)
|
2021-05-19 09:32:56 +08:00
|
|
|
.detail("ConfigClass", versionedMutation.mutation.getConfigClass())
|
2021-08-20 05:45:30 +08:00
|
|
|
.detail("KnobName", versionedMutation.mutation.getKnobName())
|
|
|
|
.detail("ClientID", client.broadcastInterface.id());
|
2021-06-07 15:29:36 +08:00
|
|
|
if (versionedMutation.mutation.isSet()) {
|
|
|
|
te.detail("Op", "Set").detail("KnobValue", versionedMutation.mutation.getValue().toString());
|
|
|
|
} else {
|
|
|
|
te.detail("Op", "Clear");
|
|
|
|
}
|
|
|
|
|
2021-08-07 03:42:07 +08:00
|
|
|
req.changes.push_back_deep(req.changes.arena(), versionedMutation);
|
2021-05-19 09:32:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 02:49:57 +08:00
|
|
|
if (req.changes.size() == 0) {
|
|
|
|
return Void();
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
2021-08-07 03:42:07 +08:00
|
|
|
|
2021-08-10 02:49:57 +08:00
|
|
|
client.lastSeenVersion = mostRecentVersion;
|
|
|
|
req.mostRecentVersion = mostRecentVersion;
|
|
|
|
++successfulChangeRequest;
|
2021-08-11 02:03:06 +08:00
|
|
|
return success(client.broadcastInterface.changes.getReply(req));
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-19 01:47:16 +08:00
|
|
|
ConfigBroadcasterImpl()
|
2021-07-25 02:43:19 +08:00
|
|
|
: lastCompactedVersion(0), mostRecentVersion(0), id(deterministicRandom()->randomUniqueID()),
|
2021-05-19 01:47:16 +08:00
|
|
|
cc("ConfigBroadcaster"), compactRequest("CompactRequest", cc),
|
|
|
|
successfulChangeRequest("SuccessfulChangeRequest", cc), failedChangeRequest("FailedChangeRequest", cc),
|
|
|
|
snapshotRequest("SnapshotRequest", cc) {
|
|
|
|
logger = traceCounters(
|
|
|
|
"ConfigBroadcasterMetrics", id, SERVER_KNOBS->WORKER_LOGGING_INTERVAL, &cc, "ConfigBroadcasterMetrics");
|
|
|
|
}
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void addChanges(Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
|
|
|
Version mostRecentVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-05-19 09:32:56 +08:00
|
|
|
this->mostRecentVersion = mostRecentVersion;
|
2021-05-23 15:41:15 +08:00
|
|
|
mutationHistory.insert(mutationHistory.end(), changes.begin(), changes.end());
|
2021-05-24 16:25:50 +08:00
|
|
|
annotationHistory.insert(annotationHistory.end(), annotations.begin(), annotations.end());
|
2021-05-23 15:41:15 +08:00
|
|
|
for (const auto& change : changes) {
|
|
|
|
const auto& mutation = change.mutation;
|
2021-05-18 14:42:55 +08:00
|
|
|
if (mutation.isSet()) {
|
2021-06-03 01:04:46 +08:00
|
|
|
snapshot[mutation.getKey()] = mutation.getValue();
|
2021-05-18 14:42:55 +08:00
|
|
|
} else {
|
|
|
|
snapshot.erase(mutation.getKey());
|
|
|
|
}
|
|
|
|
}
|
2021-08-06 09:50:11 +08:00
|
|
|
|
2021-08-18 02:45:50 +08:00
|
|
|
for (auto& [id, client] : clients) {
|
2021-08-11 06:09:35 +08:00
|
|
|
actors.add(brokenPromiseToNever(pushChanges(client, changes)));
|
2021-08-07 03:42:07 +08:00
|
|
|
}
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-19 06:28:44 +08:00
|
|
|
template <class Snapshot>
|
2021-08-20 05:45:30 +08:00
|
|
|
Future<Void> setSnapshot(Snapshot&& snapshot, Version snapshotVersion) {
|
|
|
|
this->snapshot = std::forward<Snapshot>(snapshot);
|
2021-05-14 15:41:02 +08:00
|
|
|
this->lastCompactedVersion = snapshotVersion;
|
2021-08-12 02:17:51 +08:00
|
|
|
std::vector<Future<Void>> futures;
|
2021-08-18 02:45:50 +08:00
|
|
|
for (const auto& [id, client] : clients) {
|
|
|
|
futures.push_back(brokenPromiseToNever(pushSnapshot(snapshotVersion, client)));
|
2021-08-11 13:59:11 +08:00
|
|
|
}
|
2021-08-12 02:17:51 +08:00
|
|
|
return waitForAll(futures);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR template <class Snapshot>
|
|
|
|
static Future<Void> pushSnapshotAndChanges(ConfigBroadcasterImpl* self,
|
|
|
|
Snapshot snapshot,
|
|
|
|
Version snapshotVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> changes,
|
|
|
|
Version changesVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> annotations) {
|
|
|
|
// Make sure all snapshot messages were received before sending changes.
|
|
|
|
wait(self->setSnapshot(snapshot, snapshotVersion));
|
|
|
|
self->addChanges(changes, changesVersion, annotations);
|
2021-05-14 02:22:25 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-08-18 02:45:50 +08:00
|
|
|
ACTOR static Future<Void> waitForFailure(ConfigBroadcasterImpl* self, Future<Void> watcher, UID clientUID) {
|
|
|
|
wait(watcher);
|
2021-08-20 05:45:30 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcastClientDied", self->id).detail("ClientID", clientUID);
|
2021-08-18 02:45:50 +08:00
|
|
|
self->clients.erase(clientUID);
|
2021-08-24 05:02:41 +08:00
|
|
|
self->clientFailures.erase(clientUID);
|
2021-08-18 02:45:50 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-08-18 03:08:59 +08:00
|
|
|
ACTOR static Future<Void> registerWorker(ConfigBroadcaster* self,
|
|
|
|
ConfigBroadcasterImpl* impl,
|
2021-08-18 02:45:50 +08:00
|
|
|
Version lastSeenVersion,
|
|
|
|
ConfigClassSet configClassSet,
|
2021-08-10 02:49:57 +08:00
|
|
|
Future<Void> watcher,
|
2021-08-18 02:45:50 +08:00
|
|
|
ConfigBroadcastInterface broadcastInterface) {
|
|
|
|
state BroadcastClientDetails client(
|
|
|
|
watcher, std::move(configClassSet), lastSeenVersion, std::move(broadcastInterface));
|
2021-08-18 03:08:59 +08:00
|
|
|
if (!impl->consumerFuture.isValid()) {
|
|
|
|
impl->consumerFuture = impl->consumer->consume(*self);
|
|
|
|
}
|
2021-08-18 02:45:50 +08:00
|
|
|
|
2021-08-18 03:08:59 +08:00
|
|
|
if (impl->clients.count(broadcastInterface.id())) {
|
2021-08-18 02:45:50 +08:00
|
|
|
// Client already registered
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-08-20 05:45:30 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterRegisteringWorker", impl->id)
|
|
|
|
.detail("ClientID", broadcastInterface.id())
|
|
|
|
.detail("MostRecentVersion", impl->mostRecentVersion)
|
|
|
|
.detail("ClientLastSeenVersion", lastSeenVersion);
|
2021-08-18 02:45:50 +08:00
|
|
|
// Push full snapshot to worker if it isn't up to date.
|
2021-08-18 03:08:59 +08:00
|
|
|
wait(impl->pushSnapshot(impl->mostRecentVersion, client));
|
|
|
|
impl->clients[broadcastInterface.id()] = client;
|
2021-08-20 08:07:21 +08:00
|
|
|
impl->clientFailures[broadcastInterface.id()] = waitForFailure(impl, watcher, broadcastInterface.id());
|
2021-05-14 02:22:25 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
public:
|
2021-08-18 03:08:59 +08:00
|
|
|
Future<Void> registerWorker(ConfigBroadcaster& self,
|
|
|
|
Version lastSeenVersion,
|
2021-08-06 09:50:23 +08:00
|
|
|
ConfigClassSet configClassSet,
|
2021-08-10 02:49:57 +08:00
|
|
|
Future<Void> watcher,
|
|
|
|
ConfigBroadcastInterface broadcastInterface) {
|
2021-08-18 03:08:59 +08:00
|
|
|
return registerWorker(&self, this, lastSeenVersion, configClassSet, watcher, broadcastInterface);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void applyChanges(Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
|
|
|
Version mostRecentVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-05-24 07:44:06 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterApplyingChanges", id)
|
|
|
|
.detail("ChangesSize", changes.size())
|
|
|
|
.detail("CurrentMostRecentVersion", this->mostRecentVersion)
|
2021-05-24 16:25:50 +08:00
|
|
|
.detail("NewMostRecentVersion", mostRecentVersion)
|
|
|
|
.detail("AnnotationsSize", annotations.size());
|
|
|
|
addChanges(changes, mostRecentVersion, annotations);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Snapshot>
|
|
|
|
void applySnapshotAndChanges(Snapshot&& snapshot,
|
|
|
|
Version snapshotVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
2021-05-24 16:25:50 +08:00
|
|
|
Version changesVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-05-24 07:44:06 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterApplyingSnapshotAndChanges", id)
|
|
|
|
.detail("CurrentMostRecentVersion", this->mostRecentVersion)
|
|
|
|
.detail("SnapshotSize", snapshot.size())
|
|
|
|
.detail("SnapshotVersion", snapshotVersion)
|
|
|
|
.detail("ChangesSize", changes.size())
|
2021-05-24 16:25:50 +08:00
|
|
|
.detail("ChangesVersion", changesVersion)
|
|
|
|
.detail("AnnotationsSize", annotations.size());
|
2021-08-12 02:17:51 +08:00
|
|
|
actors.add(pushSnapshotAndChanges(this, snapshot, snapshotVersion, changes, changesVersion, annotations));
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
ConfigBroadcasterImpl(ConfigFollowerInterface const& cfi) : ConfigBroadcasterImpl() {
|
|
|
|
consumer = IConfigConsumer::createTestSimple(cfi, 0.5, Optional<double>{});
|
2021-05-24 07:44:06 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterStartingConsumer", id).detail("Consumer", consumer->getID());
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
|
|
|
|
2021-08-07 14:18:10 +08:00
|
|
|
ConfigBroadcasterImpl(ServerCoordinators const& coordinators, ConfigDBType configDBType) : ConfigBroadcasterImpl() {
|
|
|
|
if (configDBType != ConfigDBType::DISABLED) {
|
|
|
|
if (configDBType == ConfigDBType::SIMPLE) {
|
2021-06-11 08:14:37 +08:00
|
|
|
consumer = IConfigConsumer::createSimple(coordinators, 0.5, Optional<double>{});
|
2021-05-19 01:47:16 +08:00
|
|
|
} else {
|
2021-06-11 08:14:37 +08:00
|
|
|
consumer = IConfigConsumer::createPaxos(coordinators, 0.5, Optional<double>{});
|
2021-05-19 01:47:16 +08:00
|
|
|
}
|
2021-08-20 05:45:30 +08:00
|
|
|
TraceEvent(SevDebug, "ConfigBroadcasterStartingConsumer", id)
|
2021-05-19 01:47:16 +08:00
|
|
|
.detail("Consumer", consumer->getID())
|
2021-08-07 14:18:10 +08:00
|
|
|
.detail("UsingSimpleConsumer", configDBType == ConfigDBType::SIMPLE);
|
2021-05-19 01:47:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-18 14:42:55 +08:00
|
|
|
JsonBuilderObject getStatus() const {
|
|
|
|
JsonBuilderObject result;
|
|
|
|
JsonBuilderArray mutationsArray;
|
2021-05-23 15:41:15 +08:00
|
|
|
for (const auto& versionedMutation : mutationHistory) {
|
2021-05-18 14:42:55 +08:00
|
|
|
JsonBuilderObject mutationObject;
|
|
|
|
mutationObject["version"] = versionedMutation.version;
|
|
|
|
const auto& mutation = versionedMutation.mutation;
|
2021-05-19 01:47:16 +08:00
|
|
|
mutationObject["config_class"] = mutation.getConfigClass().orDefault("<global>"_sr);
|
2021-05-18 14:42:55 +08:00
|
|
|
mutationObject["knob_name"] = mutation.getKnobName();
|
2021-06-03 01:04:46 +08:00
|
|
|
mutationObject["knob_value"] = mutation.getValue().toString();
|
2021-05-18 14:42:55 +08:00
|
|
|
mutationsArray.push_back(std::move(mutationObject));
|
|
|
|
}
|
|
|
|
result["mutations"] = std::move(mutationsArray);
|
2021-05-24 16:25:50 +08:00
|
|
|
JsonBuilderArray commitsArray;
|
|
|
|
for (const auto& versionedAnnotation : annotationHistory) {
|
|
|
|
JsonBuilderObject commitObject;
|
|
|
|
commitObject["version"] = versionedAnnotation.version;
|
|
|
|
commitObject["description"] = versionedAnnotation.annotation.description;
|
|
|
|
commitObject["timestamp"] = versionedAnnotation.annotation.timestamp;
|
|
|
|
commitsArray.push_back(std::move(commitObject));
|
|
|
|
}
|
|
|
|
result["commits"] = std::move(commitsArray);
|
2021-05-18 14:42:55 +08:00
|
|
|
JsonBuilderObject snapshotObject;
|
|
|
|
std::map<Optional<Key>, std::vector<std::pair<Key, Value>>> snapshotMap;
|
|
|
|
for (const auto& [configKey, value] : snapshot) {
|
2021-06-03 01:04:46 +08:00
|
|
|
snapshotMap[configKey.configClass.castTo<Key>()].emplace_back(configKey.knobName, value.toString());
|
2021-05-18 14:42:55 +08:00
|
|
|
}
|
|
|
|
for (const auto& [configClass, kvs] : snapshotMap) {
|
|
|
|
JsonBuilderObject kvsObject;
|
|
|
|
for (const auto& [knobName, knobValue] : kvs) {
|
|
|
|
kvsObject[knobName] = knobValue;
|
|
|
|
}
|
2021-05-19 01:47:16 +08:00
|
|
|
snapshotObject[configClass.orDefault("<global>"_sr)] = std::move(kvsObject);
|
2021-05-18 14:42:55 +08:00
|
|
|
}
|
|
|
|
result["snapshot"] = std::move(snapshotObject);
|
|
|
|
result["last_compacted_version"] = lastCompactedVersion;
|
|
|
|
result["most_recent_version"] = mostRecentVersion;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void compact(Version compactionVersion) {
|
|
|
|
{
|
|
|
|
auto it = std::find_if(mutationHistory.begin(), mutationHistory.end(), [compactionVersion](const auto& vm) {
|
|
|
|
return vm.version > compactionVersion;
|
|
|
|
});
|
|
|
|
mutationHistory.erase(mutationHistory.begin(), it);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto it = std::find_if(annotationHistory.begin(),
|
|
|
|
annotationHistory.end(),
|
|
|
|
[compactionVersion](const auto& va) { return va.version > compactionVersion; });
|
|
|
|
annotationHistory.erase(annotationHistory.begin(), it);
|
|
|
|
}
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
|
2021-08-11 04:24:41 +08:00
|
|
|
Future<Void> getError() const { return consumerFuture || actors.getResult(); }
|
2021-08-11 02:21:57 +08:00
|
|
|
|
2021-08-20 08:07:21 +08:00
|
|
|
Future<Void> getClientFailure(UID clientUID) const { return clientFailures.find(clientUID)->second; }
|
|
|
|
|
2021-05-14 15:41:02 +08:00
|
|
|
UID getID() const { return id; }
|
2021-06-19 08:12:32 +08:00
|
|
|
|
|
|
|
static void runPendingRequestStoreTest(bool includeGlobalMutation, int expectedMatches);
|
2021-05-12 07:57:05 +08:00
|
|
|
};
|
|
|
|
|
2021-05-18 06:31:03 +08:00
|
|
|
ConfigBroadcaster::ConfigBroadcaster(ConfigFollowerInterface const& cfi)
|
2021-08-03 03:32:11 +08:00
|
|
|
: impl(PImpl<ConfigBroadcasterImpl>::create(cfi)) {}
|
2021-05-14 02:22:25 +08:00
|
|
|
|
2021-08-07 14:18:10 +08:00
|
|
|
ConfigBroadcaster::ConfigBroadcaster(ServerCoordinators const& coordinators, ConfigDBType configDBType)
|
|
|
|
: impl(PImpl<ConfigBroadcasterImpl>::create(coordinators, configDBType)) {}
|
2021-05-12 07:57:05 +08:00
|
|
|
|
2021-05-17 14:14:46 +08:00
|
|
|
ConfigBroadcaster::ConfigBroadcaster(ConfigBroadcaster&&) = default;
|
|
|
|
|
|
|
|
ConfigBroadcaster& ConfigBroadcaster::operator=(ConfigBroadcaster&&) = default;
|
|
|
|
|
2021-05-12 07:57:05 +08:00
|
|
|
ConfigBroadcaster::~ConfigBroadcaster() = default;
|
|
|
|
|
2021-08-06 09:50:23 +08:00
|
|
|
Future<Void> ConfigBroadcaster::registerWorker(Version lastSeenVersion,
|
2021-08-18 02:45:50 +08:00
|
|
|
ConfigClassSet const& configClassSet,
|
2021-08-10 02:49:57 +08:00
|
|
|
Future<Void> watcher,
|
|
|
|
ConfigBroadcastInterface broadcastInterface) {
|
2021-08-18 03:08:59 +08:00
|
|
|
return impl->registerWorker(*this, lastSeenVersion, configClassSet, watcher, broadcastInterface);
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-23 15:41:15 +08:00
|
|
|
void ConfigBroadcaster::applyChanges(Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
2021-05-24 16:25:50 +08:00
|
|
|
Version mostRecentVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-08-03 03:32:11 +08:00
|
|
|
impl->applyChanges(changes, mostRecentVersion, annotations);
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void ConfigBroadcaster::applySnapshotAndChanges(
|
2021-06-03 01:04:46 +08:00
|
|
|
std::map<ConfigKey, KnobValue> const& snapshot,
|
2021-05-24 16:25:50 +08:00
|
|
|
Version snapshotVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
|
|
|
Version changesVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-08-03 03:32:11 +08:00
|
|
|
impl->applySnapshotAndChanges(snapshot, snapshotVersion, changes, changesVersion, annotations);
|
2021-05-19 06:28:44 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void ConfigBroadcaster::applySnapshotAndChanges(
|
2021-06-03 01:04:46 +08:00
|
|
|
std::map<ConfigKey, KnobValue>&& snapshot,
|
2021-05-24 16:25:50 +08:00
|
|
|
Version snapshotVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> const& changes,
|
|
|
|
Version changesVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigCommitAnnotationRef>> const& annotations) {
|
2021-08-03 03:32:11 +08:00
|
|
|
impl->applySnapshotAndChanges(std::move(snapshot), snapshotVersion, changes, changesVersion, annotations);
|
2021-05-14 15:41:02 +08:00
|
|
|
}
|
|
|
|
|
2021-08-11 02:21:57 +08:00
|
|
|
Future<Void> ConfigBroadcaster::getError() const {
|
2021-08-17 01:49:47 +08:00
|
|
|
return impl->getError();
|
2021-08-11 02:21:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-20 08:07:21 +08:00
|
|
|
Future<Void> ConfigBroadcaster::getClientFailure(UID clientUID) const {
|
|
|
|
return impl->getClientFailure(clientUID);
|
|
|
|
}
|
|
|
|
|
2021-05-14 15:41:02 +08:00
|
|
|
UID ConfigBroadcaster::getID() const {
|
2021-08-03 03:32:11 +08:00
|
|
|
return impl->getID();
|
2021-05-12 07:57:05 +08:00
|
|
|
}
|
2021-05-19 01:47:16 +08:00
|
|
|
|
|
|
|
JsonBuilderObject ConfigBroadcaster::getStatus() const {
|
2021-08-03 03:32:11 +08:00
|
|
|
return impl->getStatus();
|
2021-05-19 01:47:16 +08:00
|
|
|
}
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-05-24 16:25:50 +08:00
|
|
|
void ConfigBroadcaster::compact(Version compactionVersion) {
|
2021-08-03 03:32:11 +08:00
|
|
|
impl->compact(compactionVersion);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|