2019-06-19 05:49:04 +08:00
|
|
|
/*
|
|
|
|
* ProtocolVersion.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2019 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 <cstdint>
|
|
|
|
|
2019-06-19 08:55:27 +08:00
|
|
|
#define PROTOCOL_VERSION_FEATURE(v, x) \
|
2019-06-19 05:49:04 +08:00
|
|
|
struct x { \
|
|
|
|
static constexpr uint64_t protocolVersion = v; \
|
|
|
|
}; \
|
2020-05-23 07:35:01 +08:00
|
|
|
constexpr bool has##x() const { return this->version() >= x ::protocolVersion; } \
|
2019-06-19 05:49:04 +08:00
|
|
|
static constexpr ProtocolVersion with##x() { return ProtocolVersion(x ::protocolVersion); }
|
|
|
|
|
|
|
|
// ProtocolVersion wraps a uint64_t to make it type safe. It will know about the current versions.
|
|
|
|
// The default constuctor will initialize the version to 0 (which is an invalid
|
|
|
|
// version). ProtocolVersion objects should never be compared to version numbers
|
|
|
|
// directly. Instead one should always use the type-safe version types from which
|
|
|
|
// this class inherits all.
|
|
|
|
class ProtocolVersion {
|
|
|
|
uint64_t _version;
|
|
|
|
|
|
|
|
public: // constants
|
|
|
|
static constexpr uint64_t versionFlagMask = 0x0FFFFFFFFFFFFFFFLL;
|
|
|
|
static constexpr uint64_t objectSerializerFlag = 0x1000000000000000LL;
|
|
|
|
static constexpr uint64_t compatibleProtocolVersionMask = 0xffffffffffff0000LL;
|
|
|
|
static constexpr uint64_t minValidProtocolVersion = 0x0FDB00A200060001LL;
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr explicit ProtocolVersion(uint64_t version) : _version(version) {}
|
|
|
|
constexpr ProtocolVersion() : _version(0) {}
|
|
|
|
|
|
|
|
constexpr bool isCompatible(ProtocolVersion other) const {
|
|
|
|
return (other.version() & compatibleProtocolVersionMask) == (version() & compatibleProtocolVersionMask);
|
|
|
|
}
|
|
|
|
constexpr bool isValid() const { return version() >= minValidProtocolVersion; }
|
|
|
|
|
|
|
|
constexpr uint64_t version() const { return _version & versionFlagMask; }
|
|
|
|
constexpr uint64_t versionWithFlags() const { return _version; }
|
|
|
|
|
|
|
|
constexpr bool hasObjectSerializerFlag() const { return (_version & objectSerializerFlag) > 0; }
|
|
|
|
constexpr void addObjectSerializerFlag() { _version = _version | objectSerializerFlag; }
|
|
|
|
constexpr void removeObjectSerializerFlag() {
|
|
|
|
_version = hasObjectSerializerFlag() ? _version ^ objectSerializerFlag : _version;
|
|
|
|
}
|
|
|
|
constexpr void removeAllFlags() { _version = version(); }
|
|
|
|
|
|
|
|
// comparison operators
|
|
|
|
// Comparison operators ignore the flags - this is because the version flags are stored in the
|
|
|
|
// most significant byte which can make comparison confusing. Also, generally, when one wants to
|
|
|
|
// compare versions, we are usually not interested in the flags.
|
|
|
|
constexpr bool operator==(const ProtocolVersion other) const { return version() == other.version(); }
|
|
|
|
constexpr bool operator!=(const ProtocolVersion other) const { return version() != other.version(); }
|
|
|
|
constexpr bool operator<=(const ProtocolVersion other) const { return version() <= other.version(); }
|
|
|
|
constexpr bool operator>=(const ProtocolVersion other) const { return version() >= other.version(); }
|
|
|
|
constexpr bool operator<(const ProtocolVersion other) const { return version() < other.version(); }
|
|
|
|
constexpr bool operator>(const ProtocolVersion other) const { return version() > other.version(); }
|
|
|
|
|
|
|
|
public: // introduced features
|
2020-06-13 05:48:11 +08:00
|
|
|
// The 5th digit from right is dev version, for example, 2 in 0x0FDB00B061020000LL;
|
|
|
|
// It was used to identify a protocol change (e.g., interface change) between major/minor versions (say 5.1 and 5.2)
|
|
|
|
// We stopped using the dev version consistently in the past.
|
|
|
|
// To ensure binaries work across patch releases (e.g., 6.2.0 to 6.2.22), we require that the protocol version be
|
|
|
|
// the same for each of them.
|
2019-06-19 08:55:27 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A200090000LL, Watches);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A2000D0000LL, MovableCoordinatedState);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A340000000LL, ProcessID);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A400040000LL, OpenDatabase);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A446020000LL, Locality);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A460010000LL, MultiGenerationTLog);
|
2019-10-02 09:52:07 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A460010000LL, SharedMutations);
|
2019-06-19 05:49:04 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A551000000LL, MultiVersionClient);
|
2019-06-19 08:55:27 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00A560010000LL, TagLocality);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B060000000LL, Fearless);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B061020000LL, EndpointAddrList);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B061030000LL, IPv6);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B061030000LL, TLogVersion);
|
2019-06-28 06:15:05 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B061070000LL, PseudoLocalities);
|
2019-06-29 03:33:24 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B061070000LL, ShardedTxsTags);
|
2020-05-23 08:14:21 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, TLogQueueEntryRef);
|
2020-05-23 07:35:01 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, GenerationRegVal);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, MovableCoordinatedStateV2);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, KeyServerValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, LogsValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, ServerTagValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, TagLocalityListValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, DatacenterReplicasValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, ProcessClassValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, WorkerListValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, BackupStartValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, LogRangeEncodeValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, HealthyZoneValue);
|
2020-05-23 08:14:21 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, DRBackupRanges);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, RegionConfiguration);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, ReplicationPolicy);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, BackupMutations);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, ClusterControllerPriorityInfo);
|
2020-05-23 08:16:59 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B062010001LL, ProcessIDFile);
|
2020-05-23 08:14:21 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, DBCoreState);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, TagThrottleValue);
|
2020-05-23 07:35:01 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, ServerListValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, StorageCacheValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, RestoreStatusValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, RestoreRequestValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, RestoreRequestDoneVersionValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, RestoreRequestTriggerValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, RestoreWorkerInterfaceValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, BackupProgressValue);
|
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, KeyServerValueV2);
|
2019-10-02 10:09:47 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063000000LL, UnifiedTLogSpilling);
|
2019-06-01 07:14:58 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, BackupWorker);
|
2020-03-25 07:25:14 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, ReportConflictingKeys);
|
2020-05-02 12:37:19 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, SmallEndpoints);
|
2020-02-06 06:59:55 +08:00
|
|
|
PROTOCOL_VERSION_FEATURE(0x0FDB00B063010000LL, CacheRole);
|
2019-06-19 05:49:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// These impact both communications and the deserialization of certain database and IKeyValueStore keys.
|
|
|
|
//
|
|
|
|
// The convention is that 'x' and 'y' should match the major and minor version of the software, and 'z' should be 0.
|
|
|
|
// To make a change without a corresponding increase to the x.y version, increment the 'dev' digit.
|
|
|
|
//
|
|
|
|
// xyzdev
|
|
|
|
// vvvv
|
2020-05-11 14:51:15 +08:00
|
|
|
constexpr ProtocolVersion currentProtocolVersion(0x0FDB00B070010001LL);
|
2019-06-19 05:49:04 +08:00
|
|
|
// This assert is intended to help prevent incrementing the leftmost digits accidentally. It will probably need to
|
|
|
|
// change when we reach version 10.
|
|
|
|
static_assert(currentProtocolVersion.version() < 0x0FDB00B100000000LL, "Unexpected protocol version");
|