2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* ClusterInterface.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_ClusterInterface_H
|
|
|
|
#define FDBCLIENT_ClusterInterface_H
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbrpc/FailureMonitor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/Status.h"
|
2020-09-11 08:44:15 +08:00
|
|
|
#include "fdbclient/CommitProxyInterface.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/ClientWorkerInterface.h"
|
2021-11-03 23:30:18 +08:00
|
|
|
#include "fdbclient/ClientVersion.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct ClusterInterface {
|
2021-03-11 02:06:03 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 15888863;
|
|
|
|
RequestStream<struct OpenDatabaseRequest> openDatabase;
|
|
|
|
RequestStream<struct FailureMonitoringRequest> failureMonitoring;
|
|
|
|
RequestStream<struct StatusRequest> databaseStatus;
|
|
|
|
RequestStream<ReplyPromise<Void>> ping;
|
|
|
|
RequestStream<struct GetClientWorkersRequest> getClientWorkers;
|
|
|
|
RequestStream<struct ForceRecoveryRequest> forceRecovery;
|
2021-10-12 01:41:46 +08:00
|
|
|
RequestStream<struct MoveShardRequest> moveShard;
|
|
|
|
RequestStream<struct RepairSystemDataRequest> repairSystemData;
|
2021-11-12 09:45:08 +08:00
|
|
|
RequestStream<struct SplitShardRequest> splitShard;
|
2021-03-11 02:06:03 +08:00
|
|
|
|
|
|
|
bool operator==(ClusterInterface const& r) const { return id() == r.id(); }
|
|
|
|
bool operator!=(ClusterInterface const& r) const { return id() != r.id(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
UID id() const { return openDatabase.getEndpoint().token; }
|
2018-10-31 04:44:37 +08:00
|
|
|
NetworkAddress address() const { return openDatabase.getEndpoint().getPrimaryAddress(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-04-27 06:54:08 +08:00
|
|
|
bool hasMessage() const {
|
2021-03-11 02:06:03 +08:00
|
|
|
return openDatabase.getFuture().isReady() || failureMonitoring.getFuture().isReady() ||
|
|
|
|
databaseStatus.getFuture().isReady() || ping.getFuture().isReady() ||
|
2021-10-12 01:41:46 +08:00
|
|
|
getClientWorkers.getFuture().isReady() || forceRecovery.getFuture().isReady() ||
|
2021-11-12 09:45:08 +08:00
|
|
|
moveShard.getFuture().isReady() || repairSystemData.getFuture().isReady() ||
|
|
|
|
splitShard.getFuture().isReady();
|
2019-05-30 07:57:13 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
void initEndpoints() {
|
2021-03-11 02:06:03 +08:00
|
|
|
openDatabase.getEndpoint(TaskPriority::ClusterController);
|
|
|
|
failureMonitoring.getEndpoint(TaskPriority::FailureMonitor);
|
|
|
|
databaseStatus.getEndpoint(TaskPriority::ClusterController);
|
|
|
|
ping.getEndpoint(TaskPriority::ClusterController);
|
|
|
|
getClientWorkers.getEndpoint(TaskPriority::ClusterController);
|
|
|
|
forceRecovery.getEndpoint(TaskPriority::ClusterController);
|
2021-10-12 01:41:46 +08:00
|
|
|
moveShard.getEndpoint(TaskPriority::ClusterController);
|
|
|
|
repairSystemData.getEndpoint(TaskPriority::ClusterController);
|
2021-11-12 09:45:08 +08:00
|
|
|
splitShard.getEndpoint(TaskPriority::ClusterController);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Ar>
|
2021-03-11 02:06:03 +08:00
|
|
|
void serialize(Ar& ar) {
|
2021-10-12 01:41:46 +08:00
|
|
|
serializer(ar,
|
|
|
|
openDatabase,
|
|
|
|
failureMonitoring,
|
|
|
|
databaseStatus,
|
|
|
|
ping,
|
|
|
|
getClientWorkers,
|
|
|
|
forceRecovery,
|
|
|
|
moveShard,
|
2021-11-12 09:45:08 +08:00
|
|
|
repairSystemData,
|
|
|
|
splitShard);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-30 03:51:37 +08:00
|
|
|
struct ClusterControllerClientInterface {
|
|
|
|
constexpr static FileIdentifier file_identifier = 14997695;
|
|
|
|
ClusterInterface clientInterface;
|
|
|
|
|
|
|
|
bool operator==(ClusterControllerClientInterface const& r) const {
|
|
|
|
return clientInterface.id() == r.clientInterface.id();
|
|
|
|
}
|
|
|
|
bool operator!=(ClusterControllerClientInterface const& r) const {
|
|
|
|
return clientInterface.id() != r.clientInterface.id();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, clientInterface);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-26 08:15:31 +08:00
|
|
|
template <class T>
|
|
|
|
struct ItemWithExamples {
|
|
|
|
T item;
|
|
|
|
int count;
|
2021-03-11 02:06:03 +08:00
|
|
|
std::vector<std::pair<NetworkAddress, Key>> examples;
|
2019-07-26 08:15:31 +08:00
|
|
|
|
2019-07-27 04:23:56 +08:00
|
|
|
ItemWithExamples() : item{}, count(0) {}
|
2021-03-11 02:06:03 +08:00
|
|
|
ItemWithExamples(T const& item, int count, std::vector<std::pair<NetworkAddress, Key>> const& examples)
|
|
|
|
: item(item), count(count), examples(examples) {}
|
2019-07-26 08:15:31 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, item, count, examples);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct OpenDatabaseRequest {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 2799502;
|
2017-05-26 04:48:44 +08:00
|
|
|
// Sent by the native API to the cluster controller to open a database and track client
|
|
|
|
// info changes. Returns immediately if the current client info id is different from
|
|
|
|
// knownClientInfoID; otherwise returns when it next changes (or perhaps after a long interval)
|
2019-07-26 08:15:31 +08:00
|
|
|
|
|
|
|
int clientCount;
|
|
|
|
std::vector<ItemWithExamples<Key>> issues;
|
|
|
|
std::vector<ItemWithExamples<Standalone<ClientVersionRef>>> supportedVersions;
|
|
|
|
std::vector<ItemWithExamples<Key>> maxProtocolSupported;
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
UID knownClientInfoID;
|
2021-03-11 02:06:03 +08:00
|
|
|
ReplyPromise<struct ClientDBInfo> reply;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2019-01-29 11:38:13 +08:00
|
|
|
if constexpr (!is_fb_function<Ar>) {
|
2019-06-19 08:55:27 +08:00
|
|
|
ASSERT(ar.protocolVersion().hasOpenDatabase());
|
2019-01-29 11:38:13 +08:00
|
|
|
}
|
2019-07-26 08:15:31 +08:00
|
|
|
serializer(ar, clientCount, issues, supportedVersions, maxProtocolSupported, knownClientInfoID, reply);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SystemFailureStatus {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 3194108;
|
2019-02-01 10:20:14 +08:00
|
|
|
NetworkAddressList addresses;
|
2017-05-26 04:48:44 +08:00
|
|
|
FailureStatus status;
|
|
|
|
|
2019-02-01 10:20:14 +08:00
|
|
|
SystemFailureStatus() {}
|
2021-03-11 02:06:03 +08:00
|
|
|
SystemFailureStatus(NetworkAddressList const& a, FailureStatus const& s) : addresses(a), status(s) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2019-02-01 10:20:14 +08:00
|
|
|
serializer(ar, addresses, status);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-17 06:00:12 +08:00
|
|
|
struct FailureMonitoringReply {
|
|
|
|
constexpr static FileIdentifier file_identifier = 6820325;
|
2021-03-11 02:06:03 +08:00
|
|
|
VectorRef<SystemFailureStatus> changes;
|
2019-04-17 06:00:12 +08:00
|
|
|
Version failureInformationVersion;
|
2021-03-11 02:06:03 +08:00
|
|
|
bool allOthersFailed; // If true, changes are relative to all servers being failed, otherwise to the version given
|
|
|
|
// in the request
|
|
|
|
int clientRequestIntervalMS, // after this many milliseconds, send another request
|
|
|
|
considerServerFailedTimeoutMS; // after this many additional milliseconds, consider the ClusterController itself
|
|
|
|
// to be failed
|
2019-04-17 06:00:12 +08:00
|
|
|
Arena arena;
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2021-03-11 02:06:03 +08:00
|
|
|
serializer(ar,
|
|
|
|
changes,
|
|
|
|
failureInformationVersion,
|
|
|
|
allOthersFailed,
|
|
|
|
clientRequestIntervalMS,
|
|
|
|
considerServerFailedTimeoutMS,
|
|
|
|
arena);
|
2019-04-17 06:00:12 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct FailureMonitoringRequest {
|
|
|
|
// Sent by all participants to the cluster controller reply.clientRequestIntervalMS
|
|
|
|
// ms after receiving the previous reply.
|
2018-08-31 16:21:24 +08:00
|
|
|
// Provides the controller the self-diagnosed status of the sender, and also
|
2017-05-26 04:48:44 +08:00
|
|
|
// requests the status of other systems. Failure to timely send one of these implies
|
|
|
|
// a failed status.
|
|
|
|
// If !senderStatus.present(), the sender wants to receive the latest failure information
|
|
|
|
// but doesn't want to be monitored.
|
|
|
|
// The failureInformationVersion returned in reply should be passed back to the
|
|
|
|
// next request to facilitate delta compression of the failure information.
|
|
|
|
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 5867851;
|
2017-05-26 04:48:44 +08:00
|
|
|
Optional<FailureStatus> senderStatus;
|
|
|
|
Version failureInformationVersion;
|
2019-02-01 10:20:14 +08:00
|
|
|
NetworkAddressList addresses;
|
2021-03-11 02:06:03 +08:00
|
|
|
ReplyPromise<struct FailureMonitoringReply> reply;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2019-02-01 10:20:14 +08:00
|
|
|
serializer(ar, senderStatus, failureInformationVersion, addresses, reply);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StatusReply {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 9980504;
|
2017-05-26 04:48:44 +08:00
|
|
|
StatusObject statusObj;
|
2018-08-16 10:39:06 +08:00
|
|
|
std::string statusStr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
StatusReply() {}
|
2021-03-11 02:06:03 +08:00
|
|
|
explicit StatusReply(StatusObject obj)
|
|
|
|
: statusObj(obj), statusStr(json_spirit::write_string(json_spirit::mValue(obj))) {}
|
|
|
|
explicit StatusReply(std::string&& text) : statusStr(text) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, statusStr);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (ar.isDeserializing) {
|
2018-08-16 10:39:06 +08:00
|
|
|
json_spirit::mValue mv;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (g_network->isSimulated()) {
|
2018-09-11 02:13:41 +08:00
|
|
|
mv = readJSONStrictly(statusStr);
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2018-09-11 02:13:41 +08:00
|
|
|
// In non-simulation allow errors because some status data is better than no status data
|
2021-03-11 02:06:03 +08:00
|
|
|
json_spirit::read_string(statusStr, mv);
|
2018-09-11 02:13:41 +08:00
|
|
|
}
|
|
|
|
statusObj = std::move(mv.get_obj());
|
2018-08-16 10:39:06 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-17 06:00:12 +08:00
|
|
|
struct StatusRequest {
|
|
|
|
constexpr static FileIdentifier file_identifier = 14419140;
|
2021-03-11 02:06:03 +08:00
|
|
|
ReplyPromise<struct StatusReply> reply;
|
2019-04-17 06:00:12 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, reply);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct GetClientWorkersRequest {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 10771791;
|
2021-09-17 08:42:34 +08:00
|
|
|
ReplyPromise<std::vector<ClientWorkerInterface>> reply;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
GetClientWorkersRequest() {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, reply);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-01 21:39:04 +08:00
|
|
|
struct ForceRecoveryRequest {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 14821350;
|
2019-02-19 06:54:28 +08:00
|
|
|
Key dcId;
|
2018-07-01 21:39:04 +08:00
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
|
|
|
ForceRecoveryRequest() {}
|
2019-02-19 06:54:28 +08:00
|
|
|
explicit ForceRecoveryRequest(Key dcId) : dcId(dcId) {}
|
2018-07-01 21:39:04 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2019-02-19 06:54:28 +08:00
|
|
|
serializer(ar, dcId, reply);
|
2018-07-01 21:39:04 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-13 06:43:18 +08:00
|
|
|
// Request to move a keyrange (shard) to a new team represented as addresses.
|
2021-10-12 01:41:46 +08:00
|
|
|
struct MoveShardRequest {
|
|
|
|
constexpr static FileIdentifier file_identifier = 2799592;
|
|
|
|
|
|
|
|
KeyRange shard;
|
|
|
|
std::vector<NetworkAddress> addresses;
|
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
|
|
|
MoveShardRequest() {}
|
2021-10-13 06:43:18 +08:00
|
|
|
MoveShardRequest(KeyRange shard, std::vector<NetworkAddress> addresses)
|
2021-10-13 07:27:51 +08:00
|
|
|
: shard{ std::move(shard) }, addresses{ std::move(addresses) } {}
|
2021-10-12 01:41:46 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, shard, addresses, reply);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-12 09:45:08 +08:00
|
|
|
// Request to trigger a master recovery, and during the following recovery, the system metadata will be
|
|
|
|
// reconstructed from TLogs, and written to a new SS team.
|
|
|
|
// This is used when metadata on SSes are lost or corrupted.
|
|
|
|
struct RepairSystemDataRequest {
|
|
|
|
constexpr static FileIdentifier file_identifier = 2799593;
|
|
|
|
|
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
|
|
|
RepairSystemDataRequest() {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, reply);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-12 08:49:36 +08:00
|
|
|
// Returns the actual shards generated by the SplitShardRequest.
|
|
|
|
struct SplitShardReply {
|
|
|
|
constexpr static FileIdentifier file_identifier = 1384440;
|
|
|
|
std::vector<KeyRange> shards;
|
|
|
|
|
|
|
|
SplitShardReply() {}
|
|
|
|
explicit SplitShardReply(std::vector<KeyRange> shards) : shards{ std::move(shards) } {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, shards);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Split keyrange [shard.begin, shard.end) into num shards.
|
2022-03-13 21:02:11 +08:00
|
|
|
// Split points are chosen as the arithmetically equal division points of the given range.
|
2021-11-12 08:49:36 +08:00
|
|
|
struct SplitShardRequest {
|
|
|
|
constexpr static FileIdentifier file_identifier = 1384443;
|
|
|
|
KeyRange shard;
|
|
|
|
int num;
|
|
|
|
ReplyPromise<SplitShardReply> reply;
|
|
|
|
|
|
|
|
SplitShardRequest() : num(0) {}
|
|
|
|
SplitShardRequest(KeyRange shard, int num) : shard{ std::move(shard) }, num(num) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, shard, num, reply);
|
|
|
|
}
|
|
|
|
};
|
2018-07-01 21:39:04 +08:00
|
|
|
#endif
|