foundationdb/fdbserver/ConfigFollowerInterface.h

183 lines
5.5 KiB
C
Raw Normal View History

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