/* * MonitorLeader.h * * This source file is part of the FoundationDB open source project * * Copyright 2013-2022 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. */ #ifndef FDBCLIENT_MONITORLEADER_H #define FDBCLIENT_MONITORLEADER_H #pragma once #include "fdbclient/FDBTypes.h" #include "fdbclient/CoordinationInterface.h" #include "fdbclient/ClusterInterface.h" #include "fdbclient/CommitProxyInterface.h" #define CLUSTER_FILE_ENV_VAR_NAME "FDB_CLUSTER_FILE" class ClientCoordinators; struct ClientStatusInfo { Key traceLogGroup; Standalone> versions; Standalone> issues; ClientStatusInfo() {} ClientStatusInfo(Key const& traceLogGroup, Standalone> versions, Standalone> issues) : traceLogGroup(traceLogGroup), versions(versions), issues(issues) {} }; struct ClientData { std::map clientStatusInfoMap; Reference>> clientInfo; OpenDatabaseRequest getRequest(); ClientData() : clientInfo(makeReference>>()) {} }; struct MonitorLeaderInfo { bool hasConnected; Reference intermediateConnRecord; MonitorLeaderInfo() : hasConnected(false) {} explicit MonitorLeaderInfo(Reference intermediateConnRecord) : hasConnected(false), intermediateConnRecord(intermediateConnRecord) {} }; Optional> getLeader(const std::vector>& nominees); // This is one place where the leader election algorithm is run. The coodinator contacts all coodinators to collect // nominees, the nominee with the most nomination is the leader. This function also monitors the change of the leader. // If a leader is elected for long enough and communication with a quorum of coordinators is possible, eventually // outKnownLeader will be that leader's interface. template Future monitorLeader(Reference const& connFile, Reference>> const& outKnownLeader); // This is one place where the leader election algorithm is run. The coodinator contacts all coodinators to collect // nominees, the nominee with the most nomination is the leader, and collects client data from the leader. This function // also monitors the change of the leader. Future monitorLeaderAndGetClientInfo(Key const& clusterKey, std::vector const& coordinators, ClientData* const& clientData, Reference>> const& leaderInfo, Reference> const& coordinatorsChanged); Future monitorProxies( Reference>> const& connRecord, Reference> const& clientInfo, Reference>> const& coordinator, Reference>>> const& supportedVersions, Key const& traceLogGroup); void shrinkProxyList(ClientDBInfo& ni, std::vector& lastCommitProxyUIDs, std::vector& lastCommitProxies, std::vector& lastGrvProxyUIDs, std::vector& lastGrvProxies); #ifndef __INTEL_COMPILER #pragma region Implementation #endif Future monitorLeaderInternal(Reference const& connRecord, Reference> const& outSerializedLeaderInfo); template struct LeaderDeserializer { Future operator()(const Reference>& serializedInfo, const Reference>>& outKnownLeader) { return asyncDeserialize(serializedInfo, outKnownLeader); } }; Future asyncDeserializeClusterInterface(const Reference>& serializedInfo, const Reference>>& outKnownLeader); template <> struct LeaderDeserializer { Future operator()(const Reference>& serializedInfo, const Reference>>& outKnownLeader) { return asyncDeserializeClusterInterface(serializedInfo, outKnownLeader); } }; template Future monitorLeader(Reference const& connRecord, Reference>> const& outKnownLeader) { LeaderDeserializer deserializer; auto serializedInfo = makeReference>(); Future m = monitorLeaderInternal(connRecord, serializedInfo); return m || deserializer(serializedInfo, outKnownLeader); } #ifndef __INTEL_COMPILER #pragma endregion #endif #endif