2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* MasterInterface.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 FDBSERVER_MASTERINTERFACE_H
|
|
|
|
#define FDBSERVER_MASTERINTERFACE_H
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-07 04:15:51 +08:00
|
|
|
#include "fdbclient/CommitProxyInterface.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
|
|
|
#include "fdbclient/StorageServerInterface.h"
|
|
|
|
#include "fdbclient/CommitTransaction.h"
|
2018-12-14 05:31:37 +08:00
|
|
|
#include "fdbclient/DatabaseConfiguration.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/TLogInterface.h"
|
2022-01-07 04:15:51 +08:00
|
|
|
#include "fdbclient/Notified.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
typedef uint64_t DBRecoveryCount;
|
|
|
|
|
|
|
|
struct MasterInterface {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 5979145;
|
2017-05-26 04:48:44 +08:00
|
|
|
LocalityData locality;
|
2021-03-11 02:06:03 +08:00
|
|
|
RequestStream<ReplyPromise<Void>> waitFailure;
|
|
|
|
RequestStream<struct GetCommitVersionRequest> getCommitVersion;
|
2020-09-16 13:29:49 +08:00
|
|
|
// Get the centralized live committed version reported by commit proxies.
|
2021-03-11 02:06:03 +08:00
|
|
|
RequestStream<struct GetRawCommittedVersionRequest> getLiveCommittedVersion;
|
2020-06-10 11:47:34 +08:00
|
|
|
// Report a proxy's committed version.
|
2021-03-11 02:06:03 +08:00
|
|
|
RequestStream<struct ReportRawCommittedVersionRequest> reportLiveCommittedVersion;
|
2022-01-07 04:15:51 +08:00
|
|
|
RequestStream<struct UpdateRecoveryDataRequest> updateRecoveryData;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-01-07 04:15:51 +08:00
|
|
|
NetworkAddress address() const { return getCommitVersion.getEndpoint().getPrimaryAddress(); }
|
|
|
|
NetworkAddressList addresses() const { return getCommitVersion.getEndpoint().addresses; }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-01-07 04:15:51 +08:00
|
|
|
UID id() const { return getCommitVersion.getEndpoint().token; }
|
2017-05-26 04:48:44 +08:00
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar) {
|
2019-01-29 11:38:13 +08:00
|
|
|
if constexpr (!is_fb_function<Archive>) {
|
2019-08-15 08:00:20 +08:00
|
|
|
ASSERT(ar.protocolVersion().isValid());
|
|
|
|
}
|
2020-05-23 00:25:32 +08:00
|
|
|
serializer(ar, locality, waitFailure);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (Archive::isDeserializing) {
|
|
|
|
getCommitVersion =
|
2022-01-07 04:15:51 +08:00
|
|
|
RequestStream<struct GetCommitVersionRequest>(waitFailure.getEndpoint().getAdjustedEndpoint(1));
|
2021-03-11 02:06:03 +08:00
|
|
|
getLiveCommittedVersion =
|
2022-01-07 04:15:51 +08:00
|
|
|
RequestStream<struct GetRawCommittedVersionRequest>(waitFailure.getEndpoint().getAdjustedEndpoint(2));
|
2021-03-11 02:06:03 +08:00
|
|
|
reportLiveCommittedVersion = RequestStream<struct ReportRawCommittedVersionRequest>(
|
2022-01-07 04:15:51 +08:00
|
|
|
waitFailure.getEndpoint().getAdjustedEndpoint(3));
|
|
|
|
updateRecoveryData =
|
|
|
|
RequestStream<struct UpdateRecoveryDataRequest>(waitFailure.getEndpoint().getAdjustedEndpoint(4));
|
2020-04-13 07:04:48 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void initEndpoints() {
|
2020-04-13 13:18:51 +08:00
|
|
|
std::vector<std::pair<FlowReceiver*, TaskPriority>> streams;
|
|
|
|
streams.push_back(waitFailure.getReceiver());
|
|
|
|
streams.push_back(getCommitVersion.getReceiver(TaskPriority::GetConsistentReadVersion));
|
2020-06-17 11:37:30 +08:00
|
|
|
streams.push_back(getLiveCommittedVersion.getReceiver(TaskPriority::GetLiveCommittedVersion));
|
|
|
|
streams.push_back(reportLiveCommittedVersion.getReceiver(TaskPriority::ReportLiveCommittedVersion));
|
2022-01-07 04:15:51 +08:00
|
|
|
streams.push_back(updateRecoveryData.getReceiver(TaskPriority::UpdateRecoveryTransactionVersion));
|
2020-05-23 00:25:32 +08:00
|
|
|
FlowTransport::transport().addEndpoints(streams);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChangeCoordinatorsRequest {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 13605416;
|
2017-05-26 04:48:44 +08:00
|
|
|
Standalone<StringRef> newConnectionString;
|
2021-03-11 02:06:03 +08:00
|
|
|
ReplyPromise<Void> reply; // normally throws even on success!
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
ChangeCoordinatorsRequest() {}
|
|
|
|
ChangeCoordinatorsRequest(Standalone<StringRef> newConnectionString) : newConnectionString(newConnectionString) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, newConnectionString, reply);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ResolverMoveRef {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 11945475;
|
2017-05-26 04:48:44 +08:00
|
|
|
KeyRangeRef range;
|
|
|
|
int dest;
|
|
|
|
|
|
|
|
ResolverMoveRef() : dest(0) {}
|
|
|
|
ResolverMoveRef(KeyRangeRef const& range, int dest) : range(range), dest(dest) {}
|
2021-03-11 02:06:03 +08:00
|
|
|
ResolverMoveRef(Arena& a, const ResolverMoveRef& copyFrom) : range(a, copyFrom.range), dest(copyFrom.dest) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
bool operator==(ResolverMoveRef const& rhs) const { return range == rhs.range && dest == rhs.dest; }
|
|
|
|
bool operator!=(ResolverMoveRef const& rhs) const { return range != rhs.range || dest != rhs.dest; }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
size_t expectedSize() const { return range.expectedSize(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
2021-03-11 02:06:03 +08:00
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, range, dest);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GetCommitVersionReply {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 3568822;
|
2017-05-26 04:48:44 +08:00
|
|
|
Standalone<VectorRef<ResolverMoveRef>> resolverChanges;
|
|
|
|
Version resolverChangesVersion;
|
|
|
|
Version version;
|
|
|
|
Version prevVersion;
|
|
|
|
uint64_t requestNum;
|
|
|
|
|
|
|
|
GetCommitVersionReply() : resolverChangesVersion(0), version(0), prevVersion(0), requestNum(0) {}
|
2021-03-11 02:06:03 +08:00
|
|
|
explicit GetCommitVersionReply(Version version, Version prevVersion, uint64_t requestNum)
|
2021-07-23 13:48:27 +08:00
|
|
|
: resolverChangesVersion(0), version(version), prevVersion(prevVersion), requestNum(requestNum) {}
|
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, resolverChanges, resolverChangesVersion, version, prevVersion, requestNum);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GetCommitVersionRequest {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 16683181;
|
2020-07-08 00:06:13 +08:00
|
|
|
SpanID spanContext;
|
2017-05-26 04:48:44 +08:00
|
|
|
uint64_t requestNum;
|
|
|
|
uint64_t mostRecentProcessedRequestNum;
|
|
|
|
UID requestingProxy;
|
|
|
|
ReplyPromise<GetCommitVersionReply> reply;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
GetCommitVersionRequest() {}
|
|
|
|
GetCommitVersionRequest(SpanID spanContext,
|
|
|
|
uint64_t requestNum,
|
|
|
|
uint64_t mostRecentProcessedRequestNum,
|
2020-07-08 00:06:13 +08:00
|
|
|
UID requestingProxy)
|
|
|
|
: spanContext(spanContext), requestNum(requestNum), mostRecentProcessedRequestNum(mostRecentProcessedRequestNum),
|
|
|
|
requestingProxy(requestingProxy) {}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2020-07-08 00:06:13 +08:00
|
|
|
serializer(ar, requestNum, mostRecentProcessedRequestNum, requestingProxy, reply, spanContext);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-07 04:15:51 +08:00
|
|
|
struct UpdateRecoveryDataRequest {
|
|
|
|
constexpr static FileIdentifier file_identifier = 13605417;
|
|
|
|
Version recoveryTransactionVersion;
|
|
|
|
Version lastEpochEnd;
|
|
|
|
std::vector<CommitProxyInterface> commitProxies;
|
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
|
|
|
UpdateRecoveryDataRequest() {}
|
|
|
|
UpdateRecoveryDataRequest(Version recoveryTransactionVersion,
|
|
|
|
Version lastEpochEnd,
|
|
|
|
std::vector<CommitProxyInterface> commitProxies)
|
|
|
|
: recoveryTransactionVersion(recoveryTransactionVersion), lastEpochEnd(lastEpochEnd),
|
|
|
|
commitProxies(commitProxies) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, recoveryTransactionVersion, lastEpochEnd, commitProxies, reply);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-11 06:55:23 +08:00
|
|
|
struct ReportRawCommittedVersionRequest {
|
2020-06-10 02:09:46 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 1853148;
|
|
|
|
Version version;
|
2020-06-11 06:55:23 +08:00
|
|
|
bool locked;
|
|
|
|
Optional<Value> metadataVersion;
|
2020-07-15 15:37:41 +08:00
|
|
|
Version minKnownCommittedVersion;
|
2020-06-11 06:55:23 +08:00
|
|
|
|
2020-06-10 02:09:46 +08:00
|
|
|
ReplyPromise<Void> reply;
|
|
|
|
|
2020-07-15 15:37:41 +08:00
|
|
|
ReportRawCommittedVersionRequest() : version(invalidVersion), locked(false), minKnownCommittedVersion(0) {}
|
2021-03-11 02:06:03 +08:00
|
|
|
ReportRawCommittedVersionRequest(Version version,
|
|
|
|
bool locked,
|
|
|
|
Optional<Value> metadataVersion,
|
|
|
|
Version minKnownCommittedVersion)
|
|
|
|
: version(version), locked(locked), metadataVersion(metadataVersion),
|
|
|
|
minKnownCommittedVersion(minKnownCommittedVersion) {}
|
2020-06-10 02:09:46 +08:00
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2020-07-17 06:56:04 +08:00
|
|
|
serializer(ar, version, locked, metadataVersion, minKnownCommittedVersion, reply);
|
2020-06-10 02:09:46 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
struct LifetimeToken {
|
|
|
|
UID ccID;
|
|
|
|
int64_t count;
|
|
|
|
|
|
|
|
LifetimeToken() : count(0) {}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
bool isStillValid(LifetimeToken const& latestToken, bool isLatestID) const {
|
2017-05-26 04:48:44 +08:00
|
|
|
return ccID == latestToken.ccID && (count >= latestToken.count || isLatestID);
|
|
|
|
}
|
2022-01-07 04:15:51 +08:00
|
|
|
bool isEqual(LifetimeToken const& toCompare) {
|
|
|
|
return ccID.compare(toCompare.ccID) == 0 && count == toCompare.count;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string toString() const { return ccID.shortString() + format("#%lld", count); }
|
|
|
|
void operator++() { ++count; }
|
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, ccID, count);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-07 04:15:51 +08:00
|
|
|
struct CommitProxyVersionReplies {
|
|
|
|
std::map<uint64_t, GetCommitVersionReply> replies;
|
|
|
|
NotifiedVersion latestRequestNum;
|
|
|
|
|
|
|
|
CommitProxyVersionReplies(CommitProxyVersionReplies&& r) noexcept
|
|
|
|
: replies(std::move(r.replies)), latestRequestNum(std::move(r.latestRequestNum)) {}
|
|
|
|
void operator=(CommitProxyVersionReplies&& r) noexcept {
|
|
|
|
replies = std::move(r.replies);
|
|
|
|
latestRequestNum = std::move(r.latestRequestNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
CommitProxyVersionReplies() : latestRequestNum(0) {}
|
|
|
|
};
|
|
|
|
|
2018-10-25 05:59:50 +08:00
|
|
|
#endif
|