2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* MonitorLeader.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* 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
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
|
|
|
#include "fdbclient/CoordinationInterface.h"
|
2019-01-30 03:51:37 +08:00
|
|
|
#include "fdbclient/ClusterInterface.h"
|
2019-07-24 10:22:44 +08:00
|
|
|
#include "fdbclient/MasterProxyInterface.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
#define CLUSTER_FILE_ENV_VAR_NAME "FDB_CLUSTER_FILE"
|
|
|
|
|
|
|
|
class ClientCoordinators;
|
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
struct ClientStatusInfo {
|
2019-07-26 08:15:31 +08:00
|
|
|
Key traceLogGroup;
|
2019-07-24 10:22:44 +08:00
|
|
|
Standalone<VectorRef<ClientVersionRef>> versions;
|
|
|
|
Standalone<VectorRef<StringRef>> issues;
|
|
|
|
|
|
|
|
ClientStatusInfo() {}
|
2019-07-26 08:15:31 +08:00
|
|
|
ClientStatusInfo(Key const& traceLogGroup, Standalone<VectorRef<ClientVersionRef>> versions, Standalone<VectorRef<StringRef>> issues) : traceLogGroup(traceLogGroup), versions(versions), issues(issues) {}
|
2019-07-24 10:22:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ClientData {
|
|
|
|
std::map<NetworkAddress, ClientStatusInfo> clientStatusInfoMap;
|
2019-09-12 06:19:42 +08:00
|
|
|
Reference<AsyncVar<CachedSerialization<ClientDBInfo>>> clientInfo;
|
2019-07-24 10:22:44 +08:00
|
|
|
|
|
|
|
OpenDatabaseRequest getRequest();
|
2019-07-26 08:15:31 +08:00
|
|
|
|
2019-09-12 06:19:42 +08:00
|
|
|
ClientData() : clientInfo( new AsyncVar<CachedSerialization<ClientDBInfo>>( CachedSerialization<ClientDBInfo>() ) ) {}
|
2019-07-24 10:22:44 +08:00
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
template <class LeaderInterface>
|
2019-07-24 10:22:44 +08:00
|
|
|
Future<Void> monitorLeader( Reference<ClusterConnectionFile> const& connFile, Reference<AsyncVar<Optional<LeaderInterface>>> const& outKnownLeader );
|
2017-05-26 04:48:44 +08:00
|
|
|
// Monitors the given coordination group's leader election process and provides a best current guess
|
|
|
|
// of the current 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.
|
|
|
|
|
2019-07-26 08:15:31 +08:00
|
|
|
Future<Void> monitorLeaderForProxies( Value const& key, vector<NetworkAddress> const& coordinators, ClientData* const& clientData );
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2019-07-27 06:05:02 +08:00
|
|
|
Future<Void> monitorProxies( Reference<AsyncVar<Reference<ClusterConnectionFile>>> const& connFile, Reference<AsyncVar<ClientDBInfo>> const& clientInfo, Standalone<VectorRef<ClientVersionRef>> const& supportedVersions, Key const& traceLogGroup );
|
2019-07-24 10:22:44 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
#pragma region Implementation
|
|
|
|
|
2019-07-24 10:22:44 +08:00
|
|
|
Future<Void> monitorLeaderInternal( Reference<ClusterConnectionFile> const& connFile, Reference<AsyncVar<Value>> const& outSerializedLeaderInfo );
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-01-30 03:51:37 +08:00
|
|
|
template <class LeaderInterface>
|
|
|
|
struct LeaderDeserializer {
|
|
|
|
Future<Void> operator()(const Reference<AsyncVar<Value>>& serializedInfo,
|
2019-04-12 04:24:00 +08:00
|
|
|
const Reference<AsyncVar<Optional<LeaderInterface>>>& outKnownLeader) {
|
2019-08-07 00:25:40 +08:00
|
|
|
return asyncDeserialize(serializedInfo, outKnownLeader, FLOW_KNOBS->USE_OBJECT_SERIALIZER);
|
2019-01-30 03:51:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Future<Void> asyncDeserializeClusterInterface(const Reference<AsyncVar<Value>>& serializedInfo,
|
2019-04-12 04:24:00 +08:00
|
|
|
const Reference<AsyncVar<Optional<ClusterInterface>>>& outKnownLeader);
|
2019-01-30 03:51:37 +08:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct LeaderDeserializer<ClusterInterface> {
|
|
|
|
Future<Void> operator()(const Reference<AsyncVar<Value>>& serializedInfo,
|
2019-04-12 04:24:00 +08:00
|
|
|
const Reference<AsyncVar<Optional<ClusterInterface>>>& outKnownLeader) {
|
2019-01-30 03:51:37 +08:00
|
|
|
return asyncDeserializeClusterInterface(serializedInfo, outKnownLeader);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
template <class LeaderInterface>
|
2019-04-12 04:24:00 +08:00
|
|
|
Future<Void> monitorLeader(Reference<ClusterConnectionFile> const& connFile,
|
2019-07-24 10:22:44 +08:00
|
|
|
Reference<AsyncVar<Optional<LeaderInterface>>> const& outKnownLeader) {
|
2019-01-30 03:51:37 +08:00
|
|
|
LeaderDeserializer<LeaderInterface> deserializer;
|
2017-05-26 04:48:44 +08:00
|
|
|
Reference<AsyncVar<Value>> serializedInfo( new AsyncVar<Value> );
|
2019-07-24 10:22:44 +08:00
|
|
|
Future<Void> m = monitorLeaderInternal( connFile, serializedInfo );
|
2019-01-30 03:51:37 +08:00
|
|
|
return m || deserializer( serializedInfo, outKnownLeader );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2019-01-30 03:51:37 +08:00
|
|
|
#endif
|