2021-04-17 08:58:00 +08:00
|
|
|
/*
|
|
|
|
* ConfigFollowerInterface.h
|
|
|
|
*
|
|
|
|
* 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 "fdbclient/CommitTransaction.h"
|
2021-05-12 02:12:19 +08:00
|
|
|
#include "fdbclient/ConfigKnobs.h"
|
2021-04-17 08:58:00 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
|
|
|
#include "fdbrpc/fdbrpc.h"
|
|
|
|
|
2021-05-12 09:23:33 +08:00
|
|
|
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); }
|
|
|
|
|
2021-05-13 01:12:37 +08:00
|
|
|
ConfigClassSet();
|
|
|
|
ConfigClassSet(VectorRef<KeyRef> configClasses);
|
2021-05-12 09:23:33 +08:00
|
|
|
|
2021-05-12 09:54:37 +08:00
|
|
|
bool contains(KeyRef configClass) const;
|
|
|
|
|
2021-05-12 09:23:33 +08:00
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, classes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-17 08:58:00 +08:00
|
|
|
struct ConfigFollowerGetVersionReply {
|
|
|
|
static constexpr FileIdentifier file_identifier = 1028349;
|
|
|
|
Version version;
|
|
|
|
|
|
|
|
explicit ConfigFollowerGetVersionReply(Version version = -1) : version(version) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, version);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigFollowerGetVersionRequest {
|
|
|
|
static constexpr FileIdentifier file_identifier = 9840156;
|
2021-04-17 11:20:41 +08:00
|
|
|
ReplyPromise<ConfigFollowerGetVersionReply> reply;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, reply);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
struct ConfigFollowerGetSnapshotReply {
|
2021-04-17 08:58:00 +08:00
|
|
|
static constexpr FileIdentifier file_identifier = 1734095;
|
2021-05-13 02:56:45 +08:00
|
|
|
std::map<ConfigKey, Value> snapshot;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
ConfigFollowerGetSnapshotReply() = default;
|
|
|
|
explicit ConfigFollowerGetSnapshotReply(std::map<ConfigKey, Value> const& snapshot) : snapshot(snapshot) {
|
2021-04-17 08:58:00 +08:00
|
|
|
// TODO: Support move constructor as well
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-05-13 02:56:45 +08:00
|
|
|
serializer(ar, snapshot);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
struct ConfigFollowerGetSnapshotRequest {
|
2021-04-17 08:58:00 +08:00
|
|
|
static constexpr FileIdentifier file_identifier = 294811;
|
|
|
|
Version version;
|
2021-05-14 15:41:02 +08:00
|
|
|
Optional<ConfigClassSet> configClassSet;
|
2021-05-13 02:56:45 +08:00
|
|
|
ReplyPromise<ConfigFollowerGetSnapshotReply> reply;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-05-13 02:56:45 +08:00
|
|
|
ConfigFollowerGetSnapshotRequest() : version(-1) {}
|
2021-05-14 15:41:02 +08:00
|
|
|
explicit ConfigFollowerGetSnapshotRequest(Version version, Optional<ConfigClassSet> const& configClassSet)
|
2021-05-12 09:23:33 +08:00
|
|
|
: version(version), configClassSet(configClassSet) {}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-05-12 09:23:33 +08:00
|
|
|
serializer(ar, version, configClassSet, reply);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-12 02:12:19 +08:00
|
|
|
struct VersionedConfigMutationRef {
|
2021-04-22 12:37:42 +08:00
|
|
|
Version version;
|
2021-05-12 02:12:19 +08:00
|
|
|
ConfigMutationRef mutation;
|
2021-04-22 12:37:42 +08:00
|
|
|
|
2021-05-12 02:12:19 +08:00
|
|
|
VersionedConfigMutationRef() = default;
|
|
|
|
explicit VersionedConfigMutationRef(Arena& arena, Version version, ConfigMutationRef mutation)
|
|
|
|
: version(version), mutation(arena, mutation) {}
|
|
|
|
explicit VersionedConfigMutationRef(Arena& arena, VersionedConfigMutationRef const& rhs)
|
2021-04-24 00:22:47 +08:00
|
|
|
: version(rhs.version), mutation(arena, rhs.mutation) {}
|
|
|
|
|
|
|
|
size_t expectedSize() const { return sizeof(Version) + mutation.expectedSize(); }
|
2021-04-22 12:37:42 +08:00
|
|
|
|
|
|
|
template<class Ar>
|
|
|
|
void serialize(Ar &ar) {
|
|
|
|
serializer(ar, version, mutation);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-17 08:58:00 +08:00
|
|
|
struct ConfigFollowerGetChangesReply {
|
|
|
|
static constexpr FileIdentifier file_identifier = 234859;
|
|
|
|
Version mostRecentVersion;
|
2021-05-12 02:12:19 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> versionedMutations;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-04-26 16:06:16 +08:00
|
|
|
ConfigFollowerGetChangesReply() : mostRecentVersion(0) {}
|
2021-04-17 08:58:00 +08:00
|
|
|
explicit ConfigFollowerGetChangesReply(Version mostRecentVersion,
|
2021-05-12 02:12:19 +08:00
|
|
|
Standalone<VectorRef<VersionedConfigMutationRef>> const& versionedMutations)
|
2021-04-22 12:37:42 +08:00
|
|
|
: mostRecentVersion(mostRecentVersion), versionedMutations(versionedMutations) {}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-04-22 12:37:42 +08:00
|
|
|
serializer(ar, mostRecentVersion, versionedMutations);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigFollowerGetChangesRequest {
|
|
|
|
static constexpr FileIdentifier file_identifier = 178935;
|
|
|
|
Version lastSeenVersion;
|
2021-05-14 15:41:02 +08:00
|
|
|
Optional<ConfigClassSet> configClassSet;
|
2021-04-17 08:58:00 +08:00
|
|
|
ReplyPromise<ConfigFollowerGetChangesReply> reply;
|
|
|
|
|
2021-05-12 02:12:19 +08:00
|
|
|
ConfigFollowerGetChangesRequest() : lastSeenVersion(::invalidVersion) {}
|
2021-05-14 15:41:02 +08:00
|
|
|
explicit ConfigFollowerGetChangesRequest(Version lastSeenVersion, Optional<ConfigClassSet> const& configClassSet)
|
2021-05-12 09:23:33 +08:00
|
|
|
: lastSeenVersion(lastSeenVersion), configClassSet(configClassSet) {}
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-05-12 09:23:33 +08:00
|
|
|
serializer(ar, lastSeenVersion, configClassSet, reply);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-22 03:18:52 +08:00
|
|
|
struct ConfigFollowerCompactRequest {
|
|
|
|
static constexpr FileIdentifier file_identifier = 568910;
|
2021-05-15 03:30:17 +08:00
|
|
|
Version version{ 0 };
|
2021-04-22 03:18:52 +08:00
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
2021-05-15 03:30:17 +08:00
|
|
|
ConfigFollowerCompactRequest() = default;
|
|
|
|
explicit ConfigFollowerCompactRequest(Version version) : version(version) {}
|
|
|
|
|
2021-04-22 03:18:52 +08:00
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-04-24 00:22:47 +08:00
|
|
|
serializer(ar, version, reply);
|
2021-04-22 03:18:52 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-27 11:41:20 +08:00
|
|
|
class ConfigFollowerInterface {
|
|
|
|
UID _id;
|
|
|
|
|
|
|
|
public:
|
2021-04-17 08:58:00 +08:00
|
|
|
static constexpr FileIdentifier file_identifier = 7721102;
|
|
|
|
RequestStream<ConfigFollowerGetVersionRequest> getVersion;
|
2021-05-13 02:56:45 +08:00
|
|
|
RequestStream<ConfigFollowerGetSnapshotRequest> getSnapshot;
|
2021-04-17 08:58:00 +08:00
|
|
|
RequestStream<ConfigFollowerGetChangesRequest> getChanges;
|
2021-04-22 03:18:52 +08:00
|
|
|
RequestStream<ConfigFollowerCompactRequest> compact;
|
2021-04-17 08:58:00 +08:00
|
|
|
|
2021-04-27 09:46:22 +08:00
|
|
|
ConfigFollowerInterface();
|
2021-04-26 08:20:02 +08:00
|
|
|
void setupWellKnownEndpoints();
|
|
|
|
ConfigFollowerInterface(NetworkAddress const& remote);
|
2021-04-27 09:46:22 +08:00
|
|
|
bool operator==(ConfigFollowerInterface const& rhs) const;
|
|
|
|
bool operator!=(ConfigFollowerInterface const& rhs) const;
|
2021-04-27 11:41:20 +08:00
|
|
|
UID id() const { return _id; }
|
2021-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-05-13 02:56:45 +08:00
|
|
|
serializer(ar, _id, getVersion, getSnapshot, getChanges);
|
2021-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
};
|