2021-05-23 15:41:15 +08:00
|
|
|
/*
|
2021-08-06 09:50:11 +08:00
|
|
|
* ConfigBroadcastInterface.h
|
2021-05-23 15:41:15 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "fdbserver/ConfigFollowerInterface.h"
|
|
|
|
|
|
|
|
class ConfigClassSet {
|
|
|
|
std::set<Key> classes;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr FileIdentifier file_identifier = 9854021;
|
|
|
|
|
|
|
|
bool operator==(ConfigClassSet const& rhs) const { return classes == rhs.classes; }
|
|
|
|
bool operator!=(ConfigClassSet const& rhs) const { return !(*this == rhs); }
|
|
|
|
|
|
|
|
ConfigClassSet() = default;
|
|
|
|
ConfigClassSet(VectorRef<KeyRef> configClasses) {
|
|
|
|
for (const auto& configClass : configClasses) {
|
|
|
|
classes.insert(configClass);
|
|
|
|
}
|
|
|
|
}
|
2021-08-10 02:49:57 +08:00
|
|
|
ConfigClassSet(std::vector<KeyRef> configClasses) {
|
|
|
|
for (const auto& configClass : configClasses) {
|
|
|
|
classes.insert(configClass);
|
|
|
|
}
|
|
|
|
}
|
2021-05-23 15:41:15 +08:00
|
|
|
|
|
|
|
bool contains(KeyRef configClass) const { return classes.count(configClass); }
|
|
|
|
std::set<Key> const& getClasses() const { return classes; }
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, classes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
template <>
|
|
|
|
struct Traceable<ConfigClassSet> : std::true_type {
|
|
|
|
static std::string toString(ConfigClassSet const& value) { return describe(value.getClasses()); }
|
|
|
|
};
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
struct ConfigBroadcastSnapshotReply {
|
|
|
|
static constexpr FileIdentifier file_identifier = 8701984;
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ConfigBroadcastSnapshotReply() = default;
|
2021-05-23 15:41:15 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-08-06 09:50:11 +08:00
|
|
|
serializer(ar);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
struct ConfigBroadcastSnapshotRequest {
|
|
|
|
static constexpr FileIdentifier file_identifier = 10911925;
|
|
|
|
Version version{ 0 };
|
|
|
|
std::map<ConfigKey, KnobValue> snapshot;
|
|
|
|
ReplyPromise<ConfigBroadcastSnapshotReply> reply;
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ConfigBroadcastSnapshotRequest() = default;
|
|
|
|
template <class Snapshot>
|
|
|
|
explicit ConfigBroadcastSnapshotRequest(Version version, Snapshot&& snapshot)
|
|
|
|
: version(version), snapshot(std::forward<Snapshot>(snapshot)) {}
|
2021-05-23 15:41:15 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-08-06 09:50:11 +08:00
|
|
|
serializer(ar, version, snapshot, reply);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
struct ConfigBroadcastChangesReply {
|
|
|
|
static constexpr FileIdentifier file_identifier = 4014928;
|
2021-06-06 23:52:07 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ConfigBroadcastChangesReply() = default;
|
2021-06-06 23:52:07 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-08-06 09:50:11 +08:00
|
|
|
serializer(ar);
|
2021-06-06 23:52:07 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
struct ConfigBroadcastChangesRequest {
|
|
|
|
static constexpr FileIdentifier file_identifier = 601281;
|
|
|
|
Version mostRecentVersion;
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> changes;
|
|
|
|
ReplyPromise<ConfigBroadcastChangesReply> reply;
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ConfigBroadcastChangesRequest() = default;
|
2021-08-06 09:50:23 +08:00
|
|
|
explicit ConfigBroadcastChangesRequest(Version mostRecentVersion,
|
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> const& changes)
|
|
|
|
: mostRecentVersion(mostRecentVersion), changes(changes) {}
|
2021-05-23 15:41:15 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-08-06 09:50:11 +08:00
|
|
|
serializer(ar, mostRecentVersion, changes, reply);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-11 08:14:37 +08:00
|
|
|
/*
|
2021-08-06 09:50:11 +08:00
|
|
|
* The ConfigBroadcaster uses a ConfigBroadcastInterface from each worker to
|
|
|
|
* push updates made to the configuration database to the worker.
|
2021-06-11 08:14:37 +08:00
|
|
|
*/
|
2021-08-06 09:50:11 +08:00
|
|
|
class ConfigBroadcastInterface {
|
2021-05-23 15:41:15 +08:00
|
|
|
UID _id;
|
|
|
|
|
|
|
|
public:
|
2021-08-06 09:50:11 +08:00
|
|
|
static constexpr FileIdentifier file_identifier = 1676543;
|
2021-08-11 02:03:06 +08:00
|
|
|
RequestStream<ConfigBroadcastSnapshotRequest> snapshot;
|
|
|
|
RequestStream<ConfigBroadcastChangesRequest> changes;
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
ConfigBroadcastInterface() : _id(deterministicRandom()->randomUniqueID()) {}
|
2021-05-23 15:41:15 +08:00
|
|
|
|
2021-08-06 09:50:11 +08:00
|
|
|
bool operator==(ConfigBroadcastInterface const& rhs) const { return (_id == rhs._id); }
|
|
|
|
bool operator!=(ConfigBroadcastInterface const& rhs) const { return !(*this == rhs); }
|
2021-05-23 15:41:15 +08:00
|
|
|
UID id() const { return _id; }
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-08-11 02:03:06 +08:00
|
|
|
serializer(ar, _id, snapshot, changes);
|
2021-05-23 15:41:15 +08:00
|
|
|
}
|
|
|
|
};
|