2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* SystemData.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 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.
|
|
|
|
*/
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/SystemData.h"
|
2022-07-14 04:53:20 +08:00
|
|
|
#include "fdbclient/BlobGranuleCommon.h"
|
2020-02-25 09:26:20 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbclient/StorageServerInterface.h"
|
2020-04-15 08:07:41 +08:00
|
|
|
#include "flow/Arena.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/TDMetric.actor.h"
|
2020-02-25 09:40:32 +08:00
|
|
|
#include "flow/serialize.h"
|
2021-03-06 03:28:15 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-07-08 11:49:16 +08:00
|
|
|
FDB_DEFINE_BOOLEAN_PARAM(AssignEmptyRange);
|
|
|
|
FDB_DEFINE_BOOLEAN_PARAM(UnassignShard);
|
2023-03-17 09:06:06 +08:00
|
|
|
FDB_DEFINE_BOOLEAN_PARAM(EnablePhysicalShardMove);
|
2022-07-08 11:49:16 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef systemKeysPrefix = "\xff"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRangeRef normalKeys(KeyRef(), systemKeysPrefix);
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef systemKeys(systemKeysPrefix, "\xff\xff"_sr);
|
|
|
|
const KeyRangeRef nonMetadataSystemKeys("\xff\x02"_sr, "\xff\x03"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRangeRef allKeys = KeyRangeRef(normalKeys.begin, systemKeys.end);
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef afterAllKeys = "\xff\xff\x00"_sr;
|
|
|
|
const KeyRangeRef specialKeys = KeyRangeRef("\xff\xff"_sr, "\xff\xff\xff"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// keyServersKeys.contains(k) iff k.startsWith(keyServersPrefix)
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef keyServersKeys("\xff/keyServers/"_sr, "\xff/keyServers0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef keyServersPrefix = keyServersKeys.begin;
|
|
|
|
const KeyRef keyServersEnd = keyServersKeys.end;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef keyServersKeyServersKeys("\xff/keyServers/\xff/keyServers/"_sr,
|
|
|
|
"\xff/keyServers/\xff/keyServers0"_sr);
|
2017-07-27 04:45:11 +08:00
|
|
|
const KeyRef keyServersKeyServersKey = keyServersKeyServersKeys.begin;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-07-08 11:49:16 +08:00
|
|
|
// These constants are selected to be easily recognized during debugging.
|
2023-03-17 09:06:06 +08:00
|
|
|
// Note that the last bit of the follwing constants is 0, indicating that physical shard move is disabled.
|
2022-07-08 11:49:16 +08:00
|
|
|
const UID anonymousShardId = UID(0x666666, 0x88888888);
|
2023-03-17 09:06:06 +08:00
|
|
|
const uint64_t emptyShardId = 0x2222222;
|
2022-07-08 11:49:16 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const Key keyServersKey(const KeyRef& k) {
|
|
|
|
return k.withPrefix(keyServersPrefix);
|
|
|
|
}
|
|
|
|
const KeyRef keyServersKey(const KeyRef& k, Arena& arena) {
|
|
|
|
return k.withPrefix(keyServersPrefix, arena);
|
|
|
|
}
|
2021-05-04 04:14:16 +08:00
|
|
|
const Value keyServersValue(RangeResult result, const std::vector<UID>& src, const std::vector<UID>& dest) {
|
2020-05-19 08:20:15 +08:00
|
|
|
if (!CLIENT_KNOBS->TAG_ENCODE_KEY_SERVERS) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValue()));
|
|
|
|
wr << src << dest;
|
2020-05-14 04:29:13 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2020-04-06 05:30:09 +08:00
|
|
|
std::vector<Tag> srcTag;
|
|
|
|
std::vector<Tag> destTag;
|
|
|
|
|
2020-05-09 07:17:10 +08:00
|
|
|
bool foundOldLocality = false;
|
2021-03-04 01:18:03 +08:00
|
|
|
for (const KeyValueRef& kv : result) {
|
2020-04-06 05:30:09 +08:00
|
|
|
UID uid = decodeServerTagKey(kv.key);
|
|
|
|
if (std::find(src.begin(), src.end(), uid) != src.end()) {
|
|
|
|
srcTag.push_back(decodeServerTagValue(kv.value));
|
2020-05-09 07:17:10 +08:00
|
|
|
if (srcTag.back().locality == tagLocalityUpgraded) {
|
|
|
|
foundOldLocality = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
|
|
|
if (std::find(dest.begin(), dest.end(), uid) != dest.end()) {
|
|
|
|
destTag.push_back(decodeServerTagValue(kv.value));
|
2020-05-09 07:17:10 +08:00
|
|
|
if (destTag.back().locality == tagLocalityUpgraded) {
|
|
|
|
foundOldLocality = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-09 07:17:10 +08:00
|
|
|
if (foundOldLocality || src.size() != srcTag.size() || dest.size() != destTag.size()) {
|
|
|
|
ASSERT_WE_THINK(foundOldLocality);
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValue()));
|
|
|
|
wr << src << dest;
|
2020-05-09 07:17:10 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2020-04-06 05:30:09 +08:00
|
|
|
return keyServersValue(srcTag, destTag);
|
|
|
|
}
|
2022-07-08 11:49:16 +08:00
|
|
|
|
|
|
|
const Value keyServersValue(const std::vector<UID>& src,
|
|
|
|
const std::vector<UID>& dest,
|
|
|
|
const UID& srcID,
|
|
|
|
const UID& destID) {
|
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withShardEncodeLocationMetaData()));
|
|
|
|
if (dest.empty()) {
|
|
|
|
ASSERT(!destID.isValid());
|
|
|
|
wr << src << dest << srcID;
|
|
|
|
} else {
|
|
|
|
wr << src << dest << srcID << destID;
|
|
|
|
}
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2020-04-06 05:30:09 +08:00
|
|
|
const Value keyServersValue(const std::vector<Tag>& srcTag, const std::vector<Tag>& destTag) {
|
2017-05-26 04:48:44 +08:00
|
|
|
// src and dest are expected to be sorted
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValueV2()));
|
|
|
|
wr << srcTag << destTag;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
|
2021-05-04 04:14:16 +08:00
|
|
|
void decodeKeyServersValue(RangeResult result,
|
2020-04-06 05:30:09 +08:00
|
|
|
const ValueRef& value,
|
2020-05-09 08:45:06 +08:00
|
|
|
std::vector<UID>& src,
|
|
|
|
std::vector<UID>& dest,
|
|
|
|
bool missingIsError) {
|
2020-04-06 05:30:09 +08:00
|
|
|
if (value.size() == 0) {
|
2017-05-26 04:48:44 +08:00
|
|
|
src.clear();
|
|
|
|
dest.clear();
|
2020-04-06 05:30:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryReader rd(value, IncludeVersion());
|
2022-07-08 11:49:16 +08:00
|
|
|
if (rd.protocolVersion().hasShardEncodeLocationMetaData()) {
|
|
|
|
UID srcId, destId;
|
|
|
|
decodeKeyServersValue(result, value, src, dest, srcId, destId);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-23 07:35:01 +08:00
|
|
|
if (!rd.protocolVersion().hasKeyServerValueV2()) {
|
2020-04-06 05:30:09 +08:00
|
|
|
rd >> src >> dest;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2020-04-06 05:30:09 +08:00
|
|
|
std::vector<Tag> srcTag, destTag;
|
|
|
|
rd >> srcTag >> destTag;
|
|
|
|
|
|
|
|
src.clear();
|
|
|
|
dest.clear();
|
|
|
|
|
2021-03-04 01:18:03 +08:00
|
|
|
for (const KeyValueRef& kv : result) {
|
2020-04-06 05:30:09 +08:00
|
|
|
Tag tag = decodeServerTagValue(kv.value);
|
|
|
|
if (std::find(srcTag.begin(), srcTag.end(), tag) != srcTag.end()) {
|
|
|
|
src.push_back(decodeServerTagKey(kv.key));
|
|
|
|
}
|
|
|
|
if (std::find(destTag.begin(), destTag.end(), tag) != destTag.end()) {
|
|
|
|
dest.push_back(decodeServerTagKey(kv.key));
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
std::sort(src.begin(), src.end());
|
|
|
|
std::sort(dest.begin(), dest.end());
|
2020-05-09 08:45:06 +08:00
|
|
|
if (missingIsError && (src.size() != srcTag.size() || dest.size() != destTag.size())) {
|
2021-07-27 10:55:10 +08:00
|
|
|
TraceEvent(SevError, "AttemptedToDecodeMissingTag").log();
|
2021-03-04 01:18:03 +08:00
|
|
|
for (const KeyValueRef& kv : result) {
|
2020-05-09 07:17:10 +08:00
|
|
|
Tag tag = decodeServerTagValue(kv.value);
|
|
|
|
UID serverID = decodeServerTagKey(kv.key);
|
|
|
|
TraceEvent("TagUIDMap").detail("Tag", tag.toString()).detail("UID", serverID.toString());
|
|
|
|
}
|
|
|
|
for (auto& it : srcTag) {
|
|
|
|
TraceEvent("SrcTag").detail("Tag", it.toString());
|
|
|
|
}
|
|
|
|
for (auto& it : destTag) {
|
|
|
|
TraceEvent("DestTag").detail("Tag", it.toString());
|
|
|
|
}
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-07-08 11:49:16 +08:00
|
|
|
void decodeKeyServersValue(RangeResult result,
|
|
|
|
const ValueRef& value,
|
|
|
|
std::vector<UID>& src,
|
|
|
|
std::vector<UID>& dest,
|
|
|
|
UID& srcID,
|
|
|
|
UID& destID,
|
|
|
|
bool missingIsError) {
|
|
|
|
src.clear();
|
|
|
|
dest.clear();
|
|
|
|
srcID = UID();
|
|
|
|
destID = UID();
|
|
|
|
|
|
|
|
if (value.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryReader rd(value, IncludeVersion());
|
|
|
|
if (rd.protocolVersion().hasShardEncodeLocationMetaData()) {
|
|
|
|
rd >> src >> dest >> srcID;
|
|
|
|
if (rd.empty()) {
|
|
|
|
ASSERT(dest.empty());
|
|
|
|
} else {
|
|
|
|
rd >> destID;
|
|
|
|
rd.assertEnd();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
decodeKeyServersValue(result, value, src, dest, missingIsError);
|
|
|
|
if (!src.empty()) {
|
|
|
|
srcID = anonymousShardId;
|
|
|
|
}
|
|
|
|
if (!dest.empty()) {
|
|
|
|
destID = anonymousShardId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 07:54:35 +08:00
|
|
|
void decodeKeyServersValue(std::map<Tag, UID> const& tag_uid,
|
|
|
|
const ValueRef& value,
|
|
|
|
std::vector<UID>& src,
|
|
|
|
std::vector<UID>& dest) {
|
|
|
|
static std::vector<Tag> srcTag, destTag;
|
|
|
|
src.clear();
|
|
|
|
dest.clear();
|
|
|
|
if (value.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryReader rd(value, IncludeVersion());
|
|
|
|
rd.checkpoint();
|
|
|
|
int srcLen, destLen;
|
|
|
|
rd >> srcLen;
|
|
|
|
rd.readBytes(srcLen * sizeof(Tag));
|
|
|
|
rd >> destLen;
|
|
|
|
rd.rewind();
|
|
|
|
|
|
|
|
if (value.size() !=
|
|
|
|
sizeof(ProtocolVersion) + sizeof(int) + srcLen * sizeof(Tag) + sizeof(int) + destLen * sizeof(Tag)) {
|
|
|
|
rd >> src >> dest;
|
2022-07-08 11:49:16 +08:00
|
|
|
if (rd.protocolVersion().hasShardEncodeLocationMetaData()) {
|
|
|
|
UID srcId, destId;
|
|
|
|
rd >> srcId;
|
|
|
|
if (rd.empty()) {
|
|
|
|
ASSERT(dest.empty());
|
|
|
|
destId = UID();
|
|
|
|
} else {
|
|
|
|
rd >> destId;
|
|
|
|
}
|
|
|
|
}
|
2020-05-10 07:54:35 +08:00
|
|
|
rd.assertEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcTag.clear();
|
|
|
|
destTag.clear();
|
|
|
|
rd >> srcTag >> destTag;
|
|
|
|
|
|
|
|
for (auto t : srcTag) {
|
|
|
|
auto itr = tag_uid.find(t);
|
|
|
|
if (itr != tag_uid.end()) {
|
|
|
|
src.push_back(itr->second);
|
|
|
|
} else {
|
|
|
|
TraceEvent(SevError, "AttemptedToDecodeMissingSrcTag").detail("Tag", t.toString());
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto t : destTag) {
|
|
|
|
auto itr = tag_uid.find(t);
|
|
|
|
if (itr != tag_uid.end()) {
|
|
|
|
dest.push_back(itr->second);
|
|
|
|
} else {
|
|
|
|
TraceEvent(SevError, "AttemptedToDecodeMissingDestTag").detail("Tag", t.toString());
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(src.begin(), src.end());
|
|
|
|
std::sort(dest.begin(), dest.end());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2023-01-19 07:11:58 +08:00
|
|
|
bool isSystemKey(KeyRef key) {
|
|
|
|
return key.size() && key[0] == systemKeys.begin[0];
|
|
|
|
}
|
|
|
|
|
2020-04-29 01:34:10 +08:00
|
|
|
const KeyRangeRef conflictingKeysRange =
|
2022-09-20 02:35:58 +08:00
|
|
|
KeyRangeRef("\xff\xff/transaction/conflicting_keys/"_sr, "\xff\xff/transaction/conflicting_keys/\xff\xff"_sr);
|
|
|
|
const ValueRef conflictingKeysTrue = "1"_sr;
|
|
|
|
const ValueRef conflictingKeysFalse = "0"_sr;
|
2020-03-25 00:48:03 +08:00
|
|
|
|
2020-04-30 05:43:37 +08:00
|
|
|
const KeyRangeRef readConflictRangeKeysRange =
|
2022-09-20 02:35:58 +08:00
|
|
|
KeyRangeRef("\xff\xff/transaction/read_conflict_range/"_sr, "\xff\xff/transaction/read_conflict_range/\xff\xff"_sr);
|
2020-04-30 05:43:37 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef writeConflictRangeKeysRange = KeyRangeRef("\xff\xff/transaction/write_conflict_range/"_sr,
|
|
|
|
"\xff\xff/transaction/write_conflict_range/\xff\xff"_sr);
|
2020-04-30 05:43:37 +08:00
|
|
|
|
2023-01-16 13:46:14 +08:00
|
|
|
const KeyRangeRef auditKeys = KeyRangeRef("\xff/audits/"_sr, "\xff/audits0"_sr);
|
|
|
|
const KeyRef auditPrefix = auditKeys.begin;
|
|
|
|
const KeyRangeRef auditRanges = KeyRangeRef("\xff/auditRanges/"_sr, "\xff/auditRanges0"_sr);
|
|
|
|
const KeyRef auditRangePrefix = auditRanges.begin;
|
2022-09-20 02:06:43 +08:00
|
|
|
|
2023-01-16 13:46:14 +08:00
|
|
|
const Key auditKey(const AuditType type, const UID& auditId) {
|
2022-09-20 02:06:43 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(auditPrefix);
|
|
|
|
wr << static_cast<uint8_t>(type);
|
|
|
|
wr.serializeBytes("/"_sr);
|
2023-01-16 13:46:14 +08:00
|
|
|
wr << bigEndian64(auditId.first());
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRange auditKeyRange(const AuditType type) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(auditPrefix);
|
|
|
|
wr << static_cast<uint8_t>(type);
|
|
|
|
wr.serializeBytes("/"_sr);
|
|
|
|
return prefixRange(wr.toValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
const Key auditRangeKey(const UID& auditId, const KeyRef& key) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(auditRangePrefix);
|
2022-09-20 02:06:43 +08:00
|
|
|
wr << auditId;
|
|
|
|
wr.serializeBytes("/"_sr);
|
|
|
|
wr.serializeBytes(key);
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2023-01-16 13:46:14 +08:00
|
|
|
const Key auditRangePrefixFor(const UID& auditId) {
|
2022-09-20 02:06:43 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(auditPrefix);
|
|
|
|
wr << auditId;
|
|
|
|
wr.serializeBytes("/"_sr);
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value auditStorageStateValue(const AuditStorageState& auditStorageState) {
|
|
|
|
return ObjectWriter::toValue(auditStorageState, IncludeVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
AuditStorageState decodeAuditStorageState(const ValueRef& value) {
|
|
|
|
AuditStorageState auditState;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(auditState);
|
|
|
|
return auditState;
|
|
|
|
}
|
|
|
|
|
2022-03-16 04:03:23 +08:00
|
|
|
const KeyRef checkpointPrefix = "\xff/checkpoint/"_sr;
|
|
|
|
|
|
|
|
const Key checkpointKeyFor(UID checkpointID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(checkpointPrefix);
|
|
|
|
wr << checkpointID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value checkpointValue(const CheckpointMetaData& checkpoint) {
|
|
|
|
return ObjectWriter::toValue(checkpoint, IncludeVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeCheckpointKey(const KeyRef& key) {
|
|
|
|
UID checkpointID;
|
|
|
|
BinaryReader rd(key.removePrefix(checkpointPrefix), Unversioned());
|
|
|
|
rd >> checkpointID;
|
|
|
|
return checkpointID;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckpointMetaData decodeCheckpointValue(const ValueRef& value) {
|
|
|
|
CheckpointMetaData checkpoint;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(checkpoint);
|
|
|
|
return checkpoint;
|
|
|
|
}
|
|
|
|
|
2022-07-08 11:49:16 +08:00
|
|
|
// "\xff/dataMoves/[[UID]] := [[DataMoveMetaData]]"
|
|
|
|
const KeyRangeRef dataMoveKeys("\xff/dataMoves/"_sr, "\xff/dataMoves0"_sr);
|
|
|
|
const Key dataMoveKeyFor(UID dataMoveId) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(dataMoveKeys.begin);
|
|
|
|
wr << dataMoveId;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value dataMoveValue(const DataMoveMetaData& dataMoveMetaData) {
|
|
|
|
return ObjectWriter::toValue(dataMoveMetaData, IncludeVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeDataMoveKey(const KeyRef& key) {
|
|
|
|
UID id;
|
|
|
|
BinaryReader rd(key.removePrefix(dataMoveKeys.begin), Unversioned());
|
|
|
|
rd >> id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataMoveMetaData decodeDataMoveValue(const ValueRef& value) {
|
|
|
|
DataMoveMetaData dataMove;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(dataMove);
|
|
|
|
return dataMove;
|
|
|
|
}
|
|
|
|
|
2020-02-15 03:42:47 +08:00
|
|
|
// "\xff/cacheServer/[[UID]] := StorageServerInterface"
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef storageCacheServerKeys("\xff/cacheServer/"_sr, "\xff/cacheServer0"_sr);
|
2019-12-07 05:28:44 +08:00
|
|
|
const KeyRef storageCacheServersPrefix = storageCacheServerKeys.begin;
|
|
|
|
const KeyRef storageCacheServersEnd = storageCacheServerKeys.end;
|
|
|
|
|
|
|
|
const Key storageCacheServerKey(UID id) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(storageCacheServersPrefix);
|
|
|
|
wr << id;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value storageCacheServerValue(const StorageServerInterface& ssi) {
|
2022-08-08 23:29:49 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion();
|
2022-01-26 09:52:12 +08:00
|
|
|
protocolVersion.addObjectSerializerFlag();
|
2022-01-27 10:05:54 +08:00
|
|
|
return ObjectWriter::toValue(ssi, IncludeVersion(protocolVersion));
|
2019-12-07 05:28:44 +08:00
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef ddStatsRange =
|
|
|
|
KeyRangeRef("\xff\xff/metrics/data_distribution_stats/"_sr, "\xff\xff/metrics/data_distribution_stats/\xff\xff"_sr);
|
2020-05-19 01:36:34 +08:00
|
|
|
|
2019-11-13 05:01:29 +08:00
|
|
|
// "\xff/storageCache/[[begin]]" := "[[vector<uint16_t>]]"
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef storageCacheKeys("\xff/storageCache/"_sr, "\xff/storageCache0"_sr);
|
2019-11-13 05:01:29 +08:00
|
|
|
const KeyRef storageCachePrefix = storageCacheKeys.begin;
|
|
|
|
|
|
|
|
const Key storageCacheKey(const KeyRef& k) {
|
|
|
|
return k.withPrefix(storageCachePrefix);
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
const Value storageCacheValue(const std::vector<uint16_t>& serverIndices) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr((IncludeVersion(ProtocolVersion::withStorageCacheValue())));
|
2019-11-13 05:01:29 +08:00
|
|
|
wr << serverIndices;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
void decodeStorageCacheValue(const ValueRef& value, std::vector<uint16_t>& serverIndices) {
|
2019-11-13 05:01:29 +08:00
|
|
|
serverIndices.clear();
|
|
|
|
if (value.size()) {
|
|
|
|
BinaryReader rd(value, IncludeVersion());
|
|
|
|
rd >> serverIndices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
const Value logsValue(const std::vector<std::pair<UID, NetworkAddress>>& logs,
|
|
|
|
const std::vector<std::pair<UID, NetworkAddress>>& oldLogs) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withLogsValue()));
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << logs;
|
|
|
|
wr << oldLogs;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-09-17 08:42:34 +08:00
|
|
|
std::pair<std::vector<std::pair<UID, NetworkAddress>>, std::vector<std::pair<UID, NetworkAddress>>> decodeLogsValue(
|
2017-05-26 04:48:44 +08:00
|
|
|
const ValueRef& value) {
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<std::pair<UID, NetworkAddress>> logs;
|
|
|
|
std::vector<std::pair<UID, NetworkAddress>> oldLogs;
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> logs;
|
|
|
|
reader >> oldLogs;
|
|
|
|
return std::make_pair(logs, oldLogs);
|
|
|
|
}
|
|
|
|
|
2022-05-06 14:53:51 +08:00
|
|
|
const KeyRangeRef serverKeysRange = KeyRangeRef("\xff/serverKeys/"_sr, "\xff/serverKeys0"_sr);
|
|
|
|
const KeyRef serverKeysPrefix = serverKeysRange.begin;
|
2021-09-21 02:58:30 +08:00
|
|
|
const ValueRef serverKeysTrue = "1"_sr, // compatible with what was serverKeysTrue
|
2021-09-21 03:01:47 +08:00
|
|
|
serverKeysTrueEmptyRange = "3"_sr, // the server treats the range as empty.
|
2021-09-11 02:10:10 +08:00
|
|
|
serverKeysFalse;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2023-03-17 09:06:06 +08:00
|
|
|
const UID newDataMoveId(const uint64_t physicalShardId,
|
|
|
|
AssignEmptyRange assignEmptyRange,
|
|
|
|
EnablePhysicalShardMove enablePSM,
|
|
|
|
UnassignShard unassignShard) {
|
2022-07-08 11:49:16 +08:00
|
|
|
uint64_t split = 0;
|
|
|
|
if (assignEmptyRange) {
|
|
|
|
split = emptyShardId;
|
|
|
|
} else if (unassignShard) {
|
|
|
|
split = 0;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
split = deterministicRandom()->randomUInt64();
|
2023-03-17 09:06:06 +08:00
|
|
|
if (enablePSM) {
|
|
|
|
split |= 1U;
|
|
|
|
} else {
|
|
|
|
split &= ~1U;
|
|
|
|
}
|
2022-07-08 11:49:16 +08:00
|
|
|
} while (split == anonymousShardId.second() || split == 0 || split == emptyShardId);
|
|
|
|
}
|
|
|
|
return UID(physicalShardId, split);
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const Key serverKeysKey(UID serverID, const KeyRef& key) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverKeysPrefix);
|
|
|
|
wr << serverID;
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes("/"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr.serializeBytes(key);
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
const Key serverKeysPrefixFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverKeysPrefix);
|
|
|
|
wr << serverID;
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes("/"_sr);
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
UID serverKeysDecodeServer(const KeyRef& key) {
|
|
|
|
UID server_id;
|
|
|
|
BinaryReader rd(key.removePrefix(serverKeysPrefix), Unversioned());
|
|
|
|
rd >> server_id;
|
|
|
|
return server_id;
|
|
|
|
}
|
2022-05-06 14:53:51 +08:00
|
|
|
|
|
|
|
std::pair<UID, Key> serverKeysDecodeServerBegin(const KeyRef& key) {
|
|
|
|
UID server_id;
|
|
|
|
BinaryReader rd(key.removePrefix(serverKeysPrefix), Unversioned());
|
|
|
|
rd >> server_id;
|
|
|
|
rd.readBytes(1); // skip "/"
|
2022-05-14 03:55:19 +08:00
|
|
|
const auto remainingBytes = rd.remainingBytes();
|
|
|
|
KeyRef ref = KeyRef(rd.arenaRead(remainingBytes), remainingBytes);
|
2022-05-07 01:39:45 +08:00
|
|
|
// std::cout << ref.size() << " " << ref.toString() << std::endl;
|
|
|
|
return std::make_pair(server_id, Key(ref));
|
2022-05-06 14:53:51 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
bool serverHasKey(ValueRef storedValue) {
|
2023-03-17 09:06:06 +08:00
|
|
|
UID shardId;
|
2022-07-08 11:49:16 +08:00
|
|
|
bool assigned, emptyRange;
|
2023-03-17 09:06:06 +08:00
|
|
|
EnablePhysicalShardMove enablePSM = EnablePhysicalShardMove::False;
|
|
|
|
decodeServerKeysValue(storedValue, assigned, emptyRange, enablePSM, shardId);
|
2022-07-08 11:49:16 +08:00
|
|
|
return assigned;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value serverKeysValue(const UID& id) {
|
|
|
|
if (!id.isValid()) {
|
|
|
|
return serverKeysFalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withShardEncodeLocationMetaData()));
|
|
|
|
wr << id;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2023-03-17 09:06:06 +08:00
|
|
|
void decodeServerKeysValue(const ValueRef& value,
|
|
|
|
bool& assigned,
|
|
|
|
bool& emptyRange,
|
|
|
|
EnablePhysicalShardMove& enablePSM,
|
|
|
|
UID& id) {
|
|
|
|
enablePSM = EnablePhysicalShardMove::False;
|
2022-07-08 11:49:16 +08:00
|
|
|
if (value.size() == 0) {
|
|
|
|
assigned = false;
|
|
|
|
emptyRange = false;
|
2022-07-23 00:30:44 +08:00
|
|
|
id = UID();
|
2022-07-08 11:49:16 +08:00
|
|
|
} else if (value == serverKeysTrue) {
|
|
|
|
assigned = true;
|
|
|
|
emptyRange = false;
|
2022-07-23 00:30:44 +08:00
|
|
|
id = anonymousShardId;
|
2022-07-08 11:49:16 +08:00
|
|
|
} else if (value == serverKeysTrueEmptyRange) {
|
|
|
|
assigned = true;
|
|
|
|
emptyRange = true;
|
2022-07-23 00:30:44 +08:00
|
|
|
id = anonymousShardId;
|
2022-07-08 11:49:16 +08:00
|
|
|
} else if (value == serverKeysFalse) {
|
|
|
|
assigned = false;
|
|
|
|
emptyRange = false;
|
2022-07-23 00:30:44 +08:00
|
|
|
id = UID();
|
2022-07-08 11:49:16 +08:00
|
|
|
} else {
|
|
|
|
BinaryReader rd(value, IncludeVersion());
|
|
|
|
ASSERT(rd.protocolVersion().hasShardEncodeLocationMetaData());
|
|
|
|
rd >> id;
|
|
|
|
assigned = id.second() != 0;
|
|
|
|
emptyRange = id.second() == emptyShardId;
|
2023-03-17 09:06:06 +08:00
|
|
|
if (id.second() & 1U) {
|
|
|
|
enablePSM = EnablePhysicalShardMove::True;
|
|
|
|
}
|
2022-07-08 11:49:16 +08:00
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef cacheKeysPrefix = "\xff\x02/cacheKeys/"_sr;
|
2019-11-13 05:01:29 +08:00
|
|
|
|
|
|
|
const Key cacheKeysKey(uint16_t idx, const KeyRef& key) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(cacheKeysPrefix);
|
|
|
|
wr << idx;
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes("/"_sr);
|
2019-11-13 05:01:29 +08:00
|
|
|
wr.serializeBytes(key);
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
const Key cacheKeysPrefixFor(uint16_t idx) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(cacheKeysPrefix);
|
|
|
|
wr << idx;
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes("/"_sr);
|
2019-11-13 05:01:29 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
uint16_t cacheKeysDecodeIndex(const KeyRef& key) {
|
|
|
|
uint16_t idx;
|
|
|
|
BinaryReader rd(key.removePrefix(cacheKeysPrefix), Unversioned());
|
|
|
|
rd >> idx;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
KeyRef cacheKeysDecodeKey(const KeyRef& key) {
|
|
|
|
return key.substr(cacheKeysPrefix.size() + sizeof(uint16_t) + 1);
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef cacheChangeKey = "\xff\x02/cacheChangeKey"_sr;
|
|
|
|
const KeyRangeRef cacheChangeKeys("\xff\x02/cacheChangeKeys/"_sr, "\xff\x02/cacheChangeKeys0"_sr);
|
2019-11-13 05:01:29 +08:00
|
|
|
const KeyRef cacheChangePrefix = cacheChangeKeys.begin;
|
|
|
|
const Key cacheChangeKeyFor(uint16_t idx) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(cacheChangePrefix);
|
|
|
|
wr << idx;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
uint16_t cacheChangeKeyDecodeIndex(const KeyRef& key) {
|
|
|
|
uint16_t idx;
|
|
|
|
BinaryReader rd(key.removePrefix(cacheChangePrefix), Unversioned());
|
|
|
|
rd >> idx;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tssMappingKeys("\xff/tss/"_sr, "\xff/tss0"_sr);
|
2021-03-06 03:28:15 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tssQuarantineKeys("\xff/tssQ/"_sr, "\xff/tssQ0"_sr);
|
2021-06-08 03:54:24 +08:00
|
|
|
|
|
|
|
const Key tssQuarantineKeyFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(tssQuarantineKeys.begin);
|
|
|
|
wr << serverID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeTssQuarantineKey(KeyRef const& key) {
|
|
|
|
UID serverID;
|
|
|
|
BinaryReader rd(key.removePrefix(tssQuarantineKeys.begin), Unversioned());
|
|
|
|
rd >> serverID;
|
|
|
|
return serverID;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tssMismatchKeys("\xff/tssMismatch/"_sr, "\xff/tssMismatch0"_sr);
|
2021-06-12 05:20:38 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef serverMetadataKeys("\xff/serverMetadata/"_sr, "\xff/serverMetadata0"_sr);
|
2022-02-05 07:04:30 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef serverTagKeys("\xff/serverTag/"_sr, "\xff/serverTag0"_sr);
|
2021-03-06 03:28:15 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef serverTagPrefix = serverTagKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef serverTagConflictKeys("\xff/serverTagConflict/"_sr, "\xff/serverTagConflict0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef serverTagConflictPrefix = serverTagConflictKeys.begin;
|
2019-07-30 10:17:10 +08:00
|
|
|
// serverTagHistoryKeys is the old tag a storage server uses before it is migrated to a different location.
|
|
|
|
// For example, we can copy a SS file to a remote DC and start the SS there;
|
2020-03-28 03:13:30 +08:00
|
|
|
// The new SS will need to consume the last bits of data from the old tag it is responsible for.
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef serverTagHistoryKeys("\xff/serverTagHistory/"_sr, "\xff/serverTagHistory0"_sr);
|
2018-01-29 03:52:54 +08:00
|
|
|
const KeyRef serverTagHistoryPrefix = serverTagHistoryKeys.begin;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const Key serverTagKeyFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverTagKeys.begin);
|
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 03:52:54 +08:00
|
|
|
const Key serverTagHistoryKeyFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return addVersionStampAtEnd(wr.toValue());
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRange serverTagHistoryRangeFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return prefixRange(wr.toValue());
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRange serverTagHistoryRangeBefore(UID serverID, Version version) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
|
|
|
wr << serverID;
|
|
|
|
version = bigEndian64(version);
|
2019-07-10 07:09:51 +08:00
|
|
|
|
2018-01-29 03:52:54 +08:00
|
|
|
Key versionStr = makeString(8);
|
|
|
|
uint8_t* data = mutateString(versionStr);
|
|
|
|
memcpy(data, &version, 8);
|
|
|
|
|
2019-03-29 02:52:50 +08:00
|
|
|
return KeyRangeRef(wr.toValue(), versionStr.withPrefix(wr.toValue()));
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const Value serverTagValue(Tag tag) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withServerTagValue()));
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << tag;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeServerTagKey(KeyRef const& key) {
|
|
|
|
UID serverID;
|
|
|
|
BinaryReader rd(key.removePrefix(serverTagKeys.begin), Unversioned());
|
|
|
|
rd >> serverID;
|
|
|
|
return serverID;
|
|
|
|
}
|
|
|
|
|
2018-01-29 03:52:54 +08:00
|
|
|
Version decodeServerTagHistoryKey(KeyRef const& key) {
|
|
|
|
Version parsedVersion;
|
|
|
|
memcpy(&parsedVersion, key.substr(key.size() - 10).begin(), sizeof(Version));
|
|
|
|
parsedVersion = bigEndian64(parsedVersion);
|
|
|
|
return parsedVersion;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
Tag decodeServerTagValue(ValueRef const& value) {
|
|
|
|
Tag s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2019-06-19 05:49:04 +08:00
|
|
|
if (!reader.protocolVersion().hasTagLocality()) {
|
2018-01-21 02:33:13 +08:00
|
|
|
int16_t id;
|
|
|
|
reader >> id;
|
|
|
|
if (id == invalidTagOld) {
|
|
|
|
s = invalidTag;
|
|
|
|
} else if (id == txsTagOld) {
|
|
|
|
s = txsTag;
|
|
|
|
} else {
|
|
|
|
ASSERT(id >= 0);
|
|
|
|
s.id = id;
|
|
|
|
s.locality = tagLocalityUpgraded;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reader >> s;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Key serverTagConflictKeyFor(Tag tag) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverTagConflictKeys.begin);
|
|
|
|
wr << tag;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tagLocalityListKeys("\xff/tagLocalityList/"_sr, "\xff/tagLocalityList0"_sr);
|
2017-08-04 07:16:36 +08:00
|
|
|
const KeyRef tagLocalityListPrefix = tagLocalityListKeys.begin;
|
|
|
|
|
|
|
|
const Key tagLocalityListKeyFor(Optional<Value> dcID) {
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion()));
|
2017-08-04 07:16:36 +08:00
|
|
|
wr.serializeBytes(tagLocalityListKeys.begin);
|
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-08-04 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Value tagLocalityListValue(int8_t const& tagLocality) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withTagLocalityListValue()));
|
2017-08-04 07:16:36 +08:00
|
|
|
wr << tagLocality;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-08-04 07:16:36 +08:00
|
|
|
}
|
|
|
|
Optional<Value> decodeTagLocalityListKey(KeyRef const& key) {
|
|
|
|
Optional<Value> dcID;
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryReader rd(key.removePrefix(tagLocalityListKeys.begin), AssumeVersion(currentProtocolVersion()));
|
2017-08-04 07:16:36 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
|
|
|
int8_t decodeTagLocalityListValue(ValueRef const& value) {
|
|
|
|
int8_t s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef datacenterReplicasKeys("\xff\x02/datacenterReplicas/"_sr, "\xff\x02/datacenterReplicas0"_sr);
|
2018-04-09 12:24:05 +08:00
|
|
|
const KeyRef datacenterReplicasPrefix = datacenterReplicasKeys.begin;
|
|
|
|
|
|
|
|
const Key datacenterReplicasKeyFor(Optional<Value> dcID) {
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion()));
|
2018-04-09 12:24:05 +08:00
|
|
|
wr.serializeBytes(datacenterReplicasKeys.begin);
|
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2018-04-09 12:24:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Value datacenterReplicasValue(int const& replicas) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withDatacenterReplicasValue()));
|
2018-04-09 12:24:05 +08:00
|
|
|
wr << replicas;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2018-04-09 12:24:05 +08:00
|
|
|
}
|
|
|
|
Optional<Value> decodeDatacenterReplicasKey(KeyRef const& key) {
|
|
|
|
Optional<Value> dcID;
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryReader rd(key.removePrefix(datacenterReplicasKeys.begin), AssumeVersion(currentProtocolVersion()));
|
2018-04-09 12:24:05 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
|
|
|
int decodeDatacenterReplicasValue(ValueRef const& value) {
|
|
|
|
int s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-11-12 04:37:53 +08:00
|
|
|
// "\xff\x02/tLogDatacenters/[[datacenterID]]"
|
|
|
|
extern const KeyRangeRef tLogDatacentersKeys;
|
|
|
|
extern const KeyRef tLogDatacentersPrefix;
|
|
|
|
const Key tLogDatacentersKeyFor(Optional<Value> dcID);
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tLogDatacentersKeys("\xff\x02/tLogDatacenters/"_sr, "\xff\x02/tLogDatacenters0"_sr);
|
2018-11-12 04:37:53 +08:00
|
|
|
const KeyRef tLogDatacentersPrefix = tLogDatacentersKeys.begin;
|
|
|
|
|
|
|
|
const Key tLogDatacentersKeyFor(Optional<Value> dcID) {
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion()));
|
2018-11-12 04:37:53 +08:00
|
|
|
wr.serializeBytes(tLogDatacentersKeys.begin);
|
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2018-11-12 04:37:53 +08:00
|
|
|
}
|
|
|
|
Optional<Value> decodeTLogDatacentersKey(KeyRef const& key) {
|
|
|
|
Optional<Value> dcID;
|
2022-08-08 23:29:49 +08:00
|
|
|
BinaryReader rd(key.removePrefix(tLogDatacentersKeys.begin), AssumeVersion(currentProtocolVersion()));
|
2018-11-12 04:37:53 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef primaryDatacenterKey = "\xff/primaryDatacenter"_sr;
|
2018-06-15 10:36:02 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// serverListKeys.contains(k) iff k.startsWith( serverListKeys.begin ) because '/'+1 == '0'
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef serverListKeys("\xff/serverList/"_sr, "\xff/serverList0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef serverListPrefix = serverListKeys.begin;
|
|
|
|
|
|
|
|
const Key serverListKeyFor(UID serverID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(serverListKeys.begin);
|
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Value serverListValue(StorageServerInterface const& server) {
|
2022-08-08 23:29:49 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion();
|
2022-03-29 14:52:26 +08:00
|
|
|
protocolVersion.addObjectSerializerFlag();
|
|
|
|
return ObjectWriter::toValue(server, IncludeVersion(protocolVersion));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2022-03-25 08:25:07 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
UID decodeServerListKey(KeyRef const& key) {
|
|
|
|
UID serverID;
|
|
|
|
BinaryReader rd(key.removePrefix(serverListKeys.begin), Unversioned());
|
|
|
|
rd >> serverID;
|
|
|
|
return serverID;
|
|
|
|
}
|
2021-03-06 03:28:15 +08:00
|
|
|
|
|
|
|
StorageServerInterface decodeServerListValueFB(ValueRef const& value) {
|
|
|
|
StorageServerInterface s;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2022-03-25 08:25:07 +08:00
|
|
|
StorageServerInterface decodeServerListValue(ValueRef const& value) {
|
|
|
|
StorageServerInterface s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
|
|
|
|
if (!reader.protocolVersion().hasStorageInterfaceReadiness()) {
|
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return decodeServerListValueFB(value);
|
2022-04-02 06:50:38 +08:00
|
|
|
}
|
|
|
|
|
2022-04-13 01:19:38 +08:00
|
|
|
Value swVersionValue(SWVersion const& swversion) {
|
2022-08-08 23:29:49 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion();
|
2022-04-05 09:42:52 +08:00
|
|
|
protocolVersion.addObjectSerializerFlag();
|
|
|
|
return ObjectWriter::toValue(swversion, IncludeVersion(protocolVersion));
|
|
|
|
}
|
|
|
|
|
2022-04-02 06:50:38 +08:00
|
|
|
SWVersion decodeSWVersionValue(ValueRef const& value) {
|
|
|
|
SWVersion s;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(s);
|
|
|
|
return s;
|
2022-03-31 15:09:58 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// processClassKeys.contains(k) iff k.startsWith( processClassKeys.begin ) because '/'+1 == '0'
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef processClassKeys("\xff/processClass/"_sr, "\xff/processClass0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef processClassPrefix = processClassKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef processClassChangeKey = "\xff/processClassChanges"_sr;
|
|
|
|
const KeyRef processClassVersionKey = "\xff/processClassChangesVersion"_sr;
|
|
|
|
const ValueRef processClassVersionValue = "1"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const Key processClassKeyFor(StringRef processID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(processClassKeys.begin);
|
|
|
|
wr << processID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Value processClassValue(ProcessClass const& processClass) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withProcessClassValue()));
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << processClass;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Key decodeProcessClassKey(KeyRef const& key) {
|
|
|
|
StringRef processID;
|
|
|
|
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
|
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeProcessClassKeyOld(KeyRef const& key) {
|
|
|
|
UID processID;
|
|
|
|
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
|
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessClass decodeProcessClassValue(ValueRef const& value) {
|
|
|
|
ProcessClass s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef configKeys("\xff/conf/"_sr, "\xff/conf0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef configKeysPrefix = configKeys.begin;
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef perpetualStorageWiggleKey("\xff/conf/perpetual_storage_wiggle"_sr);
|
|
|
|
const KeyRef perpetualStorageWiggleLocalityKey("\xff/conf/perpetual_storage_wiggle_locality"_sr);
|
2022-12-09 05:46:05 +08:00
|
|
|
// The below two are there for compatible upgrade and downgrade. After 7.3, the perpetual wiggle related keys should use
|
2023-01-03 15:59:46 +08:00
|
|
|
// format "\xff/storageWiggle/[primary | remote]/[fieldName]". See class StorageWiggleData for the data schema.
|
2022-12-09 05:46:05 +08:00
|
|
|
const KeyRef perpetualStorageWiggleIDPrefix("\xff/storageWiggleID/"_sr); // withSuffix /primary/ or /remote/
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef perpetualStorageWiggleStatsPrefix("\xff/storageWiggleStats/"_sr); // withSuffix /primary or /remote
|
2022-12-09 05:46:05 +08:00
|
|
|
const KeyRef perpetualStorageWigglePrefix("\xff/storageWiggle/"_sr);
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef triggerDDTeamInfoPrintKey("\xff/triggerDDTeamInfoPrint"_sr);
|
2021-05-18 04:22:27 +08:00
|
|
|
|
2022-09-17 00:03:06 +08:00
|
|
|
const KeyRef consistencyScanInfoKey = "\xff/consistencyScanInfo"_sr;
|
2020-11-13 08:27:55 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef encryptionAtRestModeConfKey("\xff/conf/encryption_at_rest_mode"_sr);
|
2022-11-23 08:33:59 +08:00
|
|
|
const KeyRef tenantModeConfKey("\xff/conf/tenant_mode"_sr);
|
2022-09-03 05:11:38 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef excludedServersKeys("\xff/conf/excluded/"_sr, "\xff/conf/excluded0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef excludedServersPrefix = excludedServersKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef excludedServersVersionKey = "\xff/conf/excluded"_sr;
|
2021-06-05 06:23:04 +08:00
|
|
|
AddressExclusion decodeExcludedServersKey(KeyRef const& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
ASSERT(key.startsWith(excludedServersPrefix));
|
|
|
|
// Returns an invalid NetworkAddress if given an invalid key (within the prefix)
|
|
|
|
// Excluded servers have IP in x.x.x.x format, port optional, and no SSL suffix
|
|
|
|
// Returns a valid, public NetworkAddress with a port of 0 if the key represents an IP address alone (meaning all
|
|
|
|
// ports) Returns a valid, public NetworkAddress with nonzero port if the key represents an IP:PORT combination
|
|
|
|
|
|
|
|
return AddressExclusion::parse(key.removePrefix(excludedServersPrefix));
|
|
|
|
}
|
|
|
|
std::string encodeExcludedServersKey(AddressExclusion const& addr) {
|
|
|
|
// FIXME: make sure what's persisted here is not affected by innocent changes elsewhere
|
2019-03-01 03:56:37 +08:00
|
|
|
return excludedServersPrefix.toString() + addr.toString();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef excludedLocalityKeys("\xff/conf/excluded_locality/"_sr, "\xff/conf/excluded_locality0"_sr);
|
2021-05-19 14:48:04 +08:00
|
|
|
const KeyRef excludedLocalityPrefix = excludedLocalityKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef excludedLocalityVersionKey = "\xff/conf/excluded_locality"_sr;
|
2021-06-05 06:23:04 +08:00
|
|
|
std::string decodeExcludedLocalityKey(KeyRef const& key) {
|
2021-05-19 14:48:04 +08:00
|
|
|
ASSERT(key.startsWith(excludedLocalityPrefix));
|
|
|
|
return key.removePrefix(excludedLocalityPrefix).toString();
|
|
|
|
}
|
|
|
|
std::string encodeExcludedLocalityKey(std::string const& locality) {
|
|
|
|
return excludedLocalityPrefix.toString() + locality;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef failedServersKeys("\xff/conf/failed/"_sr, "\xff/conf/failed0"_sr);
|
2019-07-31 02:45:32 +08:00
|
|
|
const KeyRef failedServersPrefix = failedServersKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef failedServersVersionKey = "\xff/conf/failed"_sr;
|
2021-06-05 06:23:04 +08:00
|
|
|
AddressExclusion decodeFailedServersKey(KeyRef const& key) {
|
2019-07-31 02:45:32 +08:00
|
|
|
ASSERT(key.startsWith(failedServersPrefix));
|
|
|
|
// Returns an invalid NetworkAddress if given an invalid key (within the prefix)
|
|
|
|
// Excluded servers have IP in x.x.x.x format, port optional, and no SSL suffix
|
|
|
|
// Returns a valid, public NetworkAddress with a port of 0 if the key represents an IP address alone (meaning all
|
|
|
|
// ports) Returns a valid, public NetworkAddress with nonzero port if the key represents an IP:PORT combination
|
|
|
|
|
|
|
|
return AddressExclusion::parse(key.removePrefix(failedServersPrefix));
|
|
|
|
}
|
|
|
|
std::string encodeFailedServersKey(AddressExclusion const& addr) {
|
|
|
|
// FIXME: make sure what's persisted here is not affected by innocent changes elsewhere
|
|
|
|
return failedServersPrefix.toString() + addr.toString();
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef failedLocalityKeys("\xff/conf/failed_locality/"_sr, "\xff/conf/failed_locality0"_sr);
|
2021-05-19 14:48:04 +08:00
|
|
|
const KeyRef failedLocalityPrefix = failedLocalityKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef failedLocalityVersionKey = "\xff/conf/failed_locality"_sr;
|
2021-06-05 06:23:04 +08:00
|
|
|
std::string decodeFailedLocalityKey(KeyRef const& key) {
|
2021-05-19 14:48:04 +08:00
|
|
|
ASSERT(key.startsWith(failedLocalityPrefix));
|
|
|
|
return key.removePrefix(failedLocalityPrefix).toString();
|
|
|
|
}
|
|
|
|
std::string encodeFailedLocalityKey(std::string const& locality) {
|
|
|
|
return failedLocalityPrefix.toString() + locality;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
// const KeyRangeRef globalConfigKeys( "\xff/globalConfig/"_sr, "\xff/globalConfig0"_sr );
|
2021-02-20 16:43:54 +08:00
|
|
|
// const KeyRef globalConfigPrefix = globalConfigKeys.begin;
|
2021-02-13 10:55:01 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef globalConfigDataKeys("\xff/globalConfig/k/"_sr, "\xff/globalConfig/k0"_sr);
|
2021-02-20 16:43:54 +08:00
|
|
|
const KeyRef globalConfigKeysPrefix = globalConfigDataKeys.begin;
|
2021-02-13 10:55:01 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef globalConfigHistoryKeys("\xff/globalConfig/h/"_sr, "\xff/globalConfig/h0"_sr);
|
2021-02-13 10:55:01 +08:00
|
|
|
const KeyRef globalConfigHistoryPrefix = globalConfigHistoryKeys.begin;
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef globalConfigVersionKey = "\xff/globalConfig/v"_sr;
|
2021-02-13 10:55:01 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef workerListKeys("\xff/worker/"_sr, "\xff/worker0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef workerListPrefix = workerListKeys.begin;
|
|
|
|
|
|
|
|
const Key workerListKeyFor(StringRef processID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(workerListKeys.begin);
|
|
|
|
wr << processID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Value workerListValue(ProcessData const& processData) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withWorkerListValue()));
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << processData;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Key decodeWorkerListKey(KeyRef const& key) {
|
|
|
|
StringRef processID;
|
|
|
|
BinaryReader rd(key.removePrefix(workerListKeys.begin), Unversioned());
|
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessData decodeWorkerListValue(ValueRef const& value) {
|
|
|
|
ProcessData s;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef backupProgressKeys("\xff\x02/backupProgress/"_sr, "\xff\x02/backupProgress0"_sr);
|
2019-05-24 07:06:23 +08:00
|
|
|
const KeyRef backupProgressPrefix = backupProgressKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef backupStartedKey = "\xff\x02/backupStarted"_sr;
|
|
|
|
extern const KeyRef backupPausedKey = "\xff\x02/backupPaused"_sr;
|
2019-05-24 07:06:23 +08:00
|
|
|
|
|
|
|
const Key backupProgressKeyFor(UID workerID) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes(backupProgressPrefix);
|
|
|
|
wr << workerID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:37:42 +08:00
|
|
|
const Value backupProgressValue(const WorkerBackupStatus& status) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBackupProgressValue()));
|
2019-07-30 01:37:42 +08:00
|
|
|
wr << status;
|
2019-05-24 07:06:23 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBackupProgressKey(const KeyRef& key) {
|
|
|
|
UID serverID;
|
|
|
|
BinaryReader rd(key.removePrefix(backupProgressPrefix), Unversioned());
|
|
|
|
rd >> serverID;
|
|
|
|
return serverID;
|
|
|
|
}
|
|
|
|
|
2019-07-30 01:37:42 +08:00
|
|
|
WorkerBackupStatus decodeBackupProgressValue(const ValueRef& value) {
|
|
|
|
WorkerBackupStatus status;
|
2019-06-01 00:50:16 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2019-07-30 01:37:42 +08:00
|
|
|
reader >> status;
|
|
|
|
return status;
|
2019-06-01 00:50:16 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 08:57:30 +08:00
|
|
|
Value encodeBackupStartedValue(const std::vector<std::pair<UID, Version>>& ids) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBackupStartValue()));
|
2020-01-22 08:57:30 +08:00
|
|
|
wr << ids;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<UID, Version>> decodeBackupStartedValue(const ValueRef& value) {
|
|
|
|
std::vector<std::pair<UID, Version>> ids;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
if (value.size() > 0)
|
|
|
|
reader >> ids;
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:33:25 +08:00
|
|
|
bool mutationForKey(const MutationRef& m, const KeyRef& key) {
|
|
|
|
return isSingleKeyMutation((MutationRef::Type)m.type) && m.param1 == key;
|
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef previousCoordinatorsKey = "\xff/previousCoordinators"_sr;
|
|
|
|
const KeyRef coordinatorsKey = "\xff/coordinators"_sr;
|
|
|
|
const KeyRef logsKey = "\xff/logs"_sr;
|
|
|
|
const KeyRef minRequiredCommitVersionKey = "\xff/minRequiredCommitVersion"_sr;
|
|
|
|
const KeyRef versionEpochKey = "\xff/versionEpoch"_sr;
|
|
|
|
|
|
|
|
const KeyRef globalKeysPrefix = "\xff/globals"_sr;
|
|
|
|
const KeyRef lastEpochEndKey = "\xff/globals/lastEpochEnd"_sr;
|
|
|
|
const KeyRef lastEpochEndPrivateKey = "\xff\xff/globals/lastEpochEnd"_sr;
|
|
|
|
const KeyRef killStorageKey = "\xff/globals/killStorage"_sr;
|
|
|
|
const KeyRef killStoragePrivateKey = "\xff\xff/globals/killStorage"_sr;
|
|
|
|
const KeyRef rebootWhenDurableKey = "\xff/globals/rebootWhenDurable"_sr;
|
|
|
|
const KeyRef rebootWhenDurablePrivateKey = "\xff\xff/globals/rebootWhenDurable"_sr;
|
|
|
|
const KeyRef primaryLocalityKey = "\xff/globals/primaryLocality"_sr;
|
|
|
|
const KeyRef primaryLocalityPrivateKey = "\xff\xff/globals/primaryLocality"_sr;
|
|
|
|
const KeyRef fastLoggingEnabled = "\xff/globals/fastLoggingEnabled"_sr;
|
|
|
|
const KeyRef fastLoggingEnabledPrivateKey = "\xff\xff/globals/fastLoggingEnabled"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-08-13 01:08:12 +08:00
|
|
|
// Whenever configuration changes or DD related system keyspace is changed(e.g.., serverList),
|
|
|
|
// actor must grab the moveKeysLockOwnerKey and update moveKeysLockWriteKey.
|
|
|
|
// This prevents concurrent write to the same system keyspace.
|
|
|
|
// When the owner of the DD related system keyspace changes, DD will reboot
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef moveKeysLockOwnerKey = "\xff/moveKeysLock/Owner"_sr;
|
|
|
|
const KeyRef moveKeysLockWriteKey = "\xff/moveKeysLock/Write"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef dataDistributionModeKey = "\xff/dataDistributionMode"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
const UID dataDistributionModeLock = UID(6345, 3425);
|
|
|
|
|
2020-04-04 06:24:14 +08:00
|
|
|
// Keys to view and control tag throttling
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef tagThrottleKeys = KeyRangeRef("\xff\x02/throttledTags/tag/"_sr, "\xff\x02/throttledTags/tag0"_sr);
|
2020-04-04 06:24:14 +08:00
|
|
|
const KeyRef tagThrottleKeysPrefix = tagThrottleKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef tagThrottleAutoKeysPrefix = "\xff\x02/throttledTags/tag/\x01"_sr;
|
|
|
|
const KeyRef tagThrottleSignalKey = "\xff\x02/throttledTags/signal"_sr;
|
|
|
|
const KeyRef tagThrottleAutoEnabledKey = "\xff\x02/throttledTags/autoThrottlingEnabled"_sr;
|
|
|
|
const KeyRef tagThrottleLimitKey = "\xff\x02/throttledTags/manualThrottleLimit"_sr;
|
|
|
|
const KeyRef tagThrottleCountKey = "\xff\x02/throttledTags/manualThrottleCount"_sr;
|
2020-04-04 06:24:14 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Client status info prefix
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef fdbClientInfoPrefixRange("\xff\x02/fdbClientInfo/"_sr, "\xff\x02/fdbClientInfo0"_sr);
|
2021-02-24 08:17:05 +08:00
|
|
|
// See remaining fields in GlobalConfig.actor.h
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-06-21 12:38:45 +08:00
|
|
|
// ConsistencyCheck settings
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef fdbShouldConsistencyCheckBeSuspended = "\xff\x02/ConsistencyCheck/Suspend"_sr;
|
2019-06-21 12:38:45 +08:00
|
|
|
|
2019-01-19 08:18:34 +08:00
|
|
|
// Request latency measurement key
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef latencyBandConfigKey = "\xff\x02/latencyBandConfig"_sr;
|
2019-01-19 08:18:34 +08:00
|
|
|
|
2017-09-26 03:40:24 +08:00
|
|
|
// Keyspace to maintain wall clock to version map
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef timeKeeperPrefixRange("\xff\x02/timeKeeper/map/"_sr, "\xff\x02/timeKeeper/map0"_sr);
|
|
|
|
const KeyRef timeKeeperVersionKey = "\xff\x02/timeKeeper/version"_sr;
|
|
|
|
const KeyRef timeKeeperDisableKey = "\xff\x02/timeKeeper/disable"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-10-19 12:18:17 +08:00
|
|
|
// Durable cluster ID key. Added "Key" to the end to differentiate from the key
|
|
|
|
// "\xff/clusterId" which was stored in the txnStateStore in FDB 7.1, whereas
|
|
|
|
// this key is stored in the database in 7.2+.
|
|
|
|
const KeyRef clusterIdKey = "\xff/clusterIdKey"_sr;
|
2022-10-19 08:57:43 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Backup Log Mutation constant variables
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef backupEnabledKey = "\xff/backupEnabled"_sr;
|
|
|
|
const KeyRangeRef backupLogKeys("\xff\x02/blog/"_sr, "\xff\x02/blog0"_sr);
|
|
|
|
const KeyRangeRef applyLogKeys("\xff\x02/alog/"_sr, "\xff\x02/alog0"_sr);
|
2023-02-24 11:33:25 +08:00
|
|
|
bool isBackupLogMutation(const MutationRef& m) {
|
|
|
|
return isSingleKeyMutation((MutationRef::Type)m.type) &&
|
|
|
|
(backupLogKeys.contains(m.param1) || applyLogKeys.contains(m.param1));
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
// static_assert( backupLogKeys.begin.size() == backupLogPrefixBytes, "backupLogPrefixBytes incorrect" );
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef backupVersionKey = "\xff/backupDataFormat"_sr;
|
|
|
|
const ValueRef backupVersionValue = "4"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
const int backupVersion = 4;
|
|
|
|
|
|
|
|
// Log Range constant variables
|
|
|
|
// \xff/logRanges/[16-byte UID][begin key] := serialize( make_pair([end key], [destination key prefix]),
|
|
|
|
// IncludeVersion() )
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef logRangesRange("\xff/logRanges/"_sr, "\xff/logRanges0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Layer status metadata prefix
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef layerStatusMetaPrefixRange("\xff\x02/status/"_sr, "\xff\x02/status0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup agent status root
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef backupStatusPrefixRange("\xff\x02/backupstatus/"_sr, "\xff\x02/backupstatus0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Restore configuration constant variables
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef fileRestorePrefixRange("\xff\x02/restore-agent/"_sr, "\xff\x02/restore-agent0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup Agent configuration constant variables
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef fileBackupPrefixRange("\xff\x02/backup-agent/"_sr, "\xff\x02/backup-agent0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// DR Agent configuration constant variables
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef databaseBackupPrefixRange("\xff\x02/db-backup-agent/"_sr, "\xff\x02/db-backup-agent0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2018-02-21 05:22:31 +08:00
|
|
|
// \xff\x02/sharedLogRangesConfig/destUidLookup/[keyRange]
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef destUidLookupPrefix = "\xff\x02/sharedLogRangesConfig/destUidLookup/"_sr;
|
2018-02-21 05:22:31 +08:00
|
|
|
// \xff\x02/sharedLogRangesConfig/backuplatestVersions/[destUid]/[logUid]
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef backupLatestVersionsPrefix = "\xff\x02/sharedLogRangesConfig/backupLatestVersions/"_sr;
|
2018-02-21 05:22:31 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Returns the encoded key comprised of begin key and log uid
|
|
|
|
Key logRangesEncodeKey(KeyRef keyBegin, UID logUid) {
|
|
|
|
return keyBegin.withPrefix(uidPrefixKey(logRangesRange.begin, logUid));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the start key and optionally the logRange Uid
|
|
|
|
KeyRef logRangesDecodeKey(KeyRef key, UID* logUid) {
|
|
|
|
if (key.size() < logRangesRange.begin.size() + sizeof(UID)) {
|
2019-03-19 06:03:43 +08:00
|
|
|
TraceEvent(SevError, "InvalidDecodeKey").detail("Key", key);
|
2017-05-26 04:48:44 +08:00
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logUid) {
|
|
|
|
*logUid = BinaryReader::fromStringRef<UID>(key.removePrefix(logRangesRange.begin), Unversioned());
|
|
|
|
}
|
|
|
|
|
|
|
|
return key.substr(logRangesRange.begin.size() + sizeof(UID));
|
|
|
|
}
|
|
|
|
|
2018-02-21 05:22:31 +08:00
|
|
|
// Returns the encoded key value comprised of the end key and destination path
|
|
|
|
Key logRangesEncodeValue(KeyRef keyEnd, KeyRef destPath) {
|
2020-05-23 07:35:01 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withLogRangeEncodeValue()));
|
2018-02-21 05:22:31 +08:00
|
|
|
wr << std::make_pair(keyEnd, destPath);
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// \xff/logRanges/[16-byte UID][begin key] := serialize( make_pair([end key], [destination key prefix]),
|
|
|
|
// IncludeVersion() )
|
|
|
|
Key logRangesDecodeValue(KeyRef keyValue, Key* destKeyPrefix) {
|
|
|
|
std::pair<KeyRef, KeyRef> endPrefixCombo;
|
|
|
|
|
|
|
|
BinaryReader rd(keyValue, IncludeVersion());
|
|
|
|
rd >> endPrefixCombo;
|
|
|
|
|
|
|
|
if (destKeyPrefix) {
|
|
|
|
*destKeyPrefix = endPrefixCombo.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return endPrefixCombo.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a key prefixed with the specified key with
|
|
|
|
// the uid encoded at the end
|
|
|
|
Key uidPrefixKey(KeyRef keyPrefix, UID logUid) {
|
|
|
|
BinaryWriter bw(Unversioned());
|
|
|
|
bw.serializeBytes(keyPrefix);
|
|
|
|
bw << logUid;
|
2019-03-29 02:52:50 +08:00
|
|
|
return bw.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply mutations constant variables
|
|
|
|
// \xff/applyMutationsEnd/[16-byte UID] := serialize( endVersion, Unversioned() )
|
2019-06-01 02:09:31 +08:00
|
|
|
// This indicates what is the highest version the mutation log can be applied
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef applyMutationsEndRange("\xff/applyMutationsEnd/"_sr, "\xff/applyMutationsEnd0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsBegin/[16-byte UID] := serialize( beginVersion, Unversioned() )
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef applyMutationsBeginRange("\xff/applyMutationsBegin/"_sr, "\xff/applyMutationsBegin0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsAddPrefix/[16-byte UID] := addPrefix
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef applyMutationsAddPrefixRange("\xff/applyMutationsAddPrefix/"_sr, "\xff/applyMutationsAddPrefix0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsRemovePrefix/[16-byte UID] := removePrefix
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef applyMutationsRemovePrefixRange("\xff/applyMutationsRemovePrefix/"_sr,
|
|
|
|
"\xff/applyMutationsRemovePrefix0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef applyMutationsKeyVersionMapRange("\xff/applyMutationsKeyVersionMap/"_sr,
|
|
|
|
"\xff/applyMutationsKeyVersionMap0"_sr);
|
|
|
|
const KeyRangeRef applyMutationsKeyVersionCountRange("\xff\x02/applyMutationsKeyVersionCount/"_sr,
|
|
|
|
"\xff\x02/applyMutationsKeyVersionCount0"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef systemTuplesPrefix = "\xff/a/"_sr;
|
|
|
|
const KeyRef metricConfChangeKey = "\x01TDMetricConfChanges\x00"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef metricConfKeys("\x01TDMetricConf\x00\x01"_sr, "\x01TDMetricConf\x00\x02"_sr);
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef metricConfPrefix = metricConfKeys.begin;
|
|
|
|
|
|
|
|
/*
|
|
|
|
const Key metricConfKey( KeyRef const& prefix, MetricNameRef const& name, KeyRef const& key ) {
|
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes( prefix );
|
|
|
|
wr.serializeBytes( metricConfPrefix );
|
|
|
|
wr.serializeBytes( name.type );
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes( "\x00\x01"_sr );
|
2017-05-26 04:48:44 +08:00
|
|
|
wr.serializeBytes( name.name );
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes( "\x00\x01"_sr );
|
2017-05-26 04:48:44 +08:00
|
|
|
wr.serializeBytes( name.address );
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes( "\x00\x01"_sr );
|
2017-05-26 04:48:44 +08:00
|
|
|
wr.serializeBytes( name.id );
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes( "\x00\x01"_sr );
|
2017-05-26 04:48:44 +08:00
|
|
|
wr.serializeBytes( key );
|
2022-09-20 02:35:58 +08:00
|
|
|
wr.serializeBytes( "\x00"_sr );
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<MetricNameRef, KeyRef> decodeMetricConfKey( KeyRef const& prefix, KeyRef const& key ) {
|
|
|
|
MetricNameRef result;
|
|
|
|
KeyRef withoutPrefix = key.removePrefix( prefix );
|
|
|
|
withoutPrefix = withoutPrefix.removePrefix( metricConfPrefix );
|
|
|
|
int pos = std::find(withoutPrefix.begin(), withoutPrefix.end(), '\x00') - withoutPrefix.begin();
|
|
|
|
result.type = withoutPrefix.substr(0,pos);
|
|
|
|
withoutPrefix = withoutPrefix.substr(pos+2);
|
|
|
|
pos = std::find(withoutPrefix.begin(), withoutPrefix.end(), '\x00') - withoutPrefix.begin();
|
|
|
|
result.name = withoutPrefix.substr(0,pos);
|
|
|
|
withoutPrefix = withoutPrefix.substr(pos+2);
|
|
|
|
pos = std::find(withoutPrefix.begin(), withoutPrefix.end(), '\x00') - withoutPrefix.begin();
|
|
|
|
result.address = withoutPrefix.substr(0,pos);
|
|
|
|
withoutPrefix = withoutPrefix.substr(pos+2);
|
|
|
|
pos = std::find(withoutPrefix.begin(), withoutPrefix.end(), '\x00') - withoutPrefix.begin();
|
|
|
|
result.id = withoutPrefix.substr(0,pos);
|
|
|
|
return std::make_pair( result, withoutPrefix.substr(pos+2,withoutPrefix.size()-pos-3) );
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef maxUIDKey = "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"_sr;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef databaseLockedKey = "\xff/dbLocked"_sr;
|
|
|
|
const KeyRef databaseLockedKeyEnd = "\xff/dbLocked\x00"_sr;
|
|
|
|
const KeyRef metadataVersionKey = "\xff/metadataVersion"_sr;
|
|
|
|
const KeyRef metadataVersionKeyEnd = "\xff/metadataVersion\x00"_sr;
|
|
|
|
const KeyRef metadataVersionRequiredValue = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"_sr;
|
|
|
|
const KeyRef mustContainSystemMutationsKey = "\xff/mustContainSystemMutations"_sr;
|
2018-10-02 01:43:53 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef monitorConfKeys("\xff\x02/monitorConf/"_sr, "\xff\x02/monitorConf0"_sr);
|
2018-10-10 09:47:28 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef restoreRequestDoneKey = "\xff\x02/restoreRequestDone"_sr;
|
2019-01-31 03:18:11 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef healthyZoneKey = "\xff\x02/healthyZone"_sr;
|
|
|
|
const StringRef ignoreSSFailuresZoneString = "IgnoreSSFailures"_sr;
|
|
|
|
const KeyRef rebalanceDDIgnoreKey = "\xff\x02/rebalanceDDIgnored"_sr;
|
2019-04-02 08:55:13 +08:00
|
|
|
|
|
|
|
const Value healthyZoneValue(StringRef const& zoneId, Version version) {
|
2020-05-23 08:19:46 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withHealthyZoneValue()));
|
2019-04-02 08:55:13 +08:00
|
|
|
wr << zoneId;
|
|
|
|
wr << version;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
std::pair<Key, Version> decodeHealthyZoneValue(ValueRef const& value) {
|
|
|
|
Key zoneId;
|
|
|
|
Version version;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> zoneId;
|
|
|
|
reader >> version;
|
|
|
|
return std::make_pair(zoneId, version);
|
|
|
|
}
|
2019-04-26 07:57:39 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef testOnlyTxnStateStorePrefixRange("\xff/TESTONLYtxnStateStore/"_sr, "\xff/TESTONLYtxnStateStore0"_sr);
|
2020-09-03 02:13:58 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef writeRecoveryKey = "\xff/writeRecovery"_sr;
|
|
|
|
const ValueRef writeRecoveryKeyTrue = "1"_sr;
|
|
|
|
const KeyRef snapshotEndVersionKey = "\xff/snapshotEndVersion"_sr;
|
2021-05-30 02:48:47 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef changeFeedKeys("\xff\x02/feed/"_sr, "\xff\x02/feed0"_sr);
|
2021-08-14 05:27:15 +08:00
|
|
|
const KeyRef changeFeedPrefix = changeFeedKeys.begin;
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef changeFeedPrivatePrefix = "\xff\xff\x02/feed/"_sr;
|
2021-03-05 11:14:54 +08:00
|
|
|
|
2021-10-20 04:56:52 +08:00
|
|
|
const Value changeFeedValue(KeyRangeRef const& range, Version popVersion, ChangeFeedStatus status) {
|
2021-08-14 05:27:15 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withChangeFeed()));
|
2021-03-05 11:14:54 +08:00
|
|
|
wr << range;
|
2021-09-03 12:11:44 +08:00
|
|
|
wr << popVersion;
|
2021-10-20 04:56:52 +08:00
|
|
|
wr << status;
|
2021-03-05 11:14:54 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-09-03 12:11:44 +08:00
|
|
|
|
2021-10-20 04:56:52 +08:00
|
|
|
std::tuple<KeyRange, Version, ChangeFeedStatus> decodeChangeFeedValue(ValueRef const& value) {
|
2021-03-05 11:14:54 +08:00
|
|
|
KeyRange range;
|
2021-09-03 12:11:44 +08:00
|
|
|
Version version;
|
2021-10-20 04:56:52 +08:00
|
|
|
ChangeFeedStatus status;
|
2021-05-01 01:51:35 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-03-05 11:14:54 +08:00
|
|
|
reader >> range;
|
2021-09-03 12:11:44 +08:00
|
|
|
reader >> version;
|
2021-10-20 04:56:52 +08:00
|
|
|
reader >> status;
|
|
|
|
return std::make_tuple(range, version, status);
|
2021-03-05 11:14:54 +08:00
|
|
|
}
|
2021-07-13 10:10:14 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef changeFeedDurableKeys("\xff\xff/cf/"_sr, "\xff\xff/cf0"_sr);
|
2021-08-14 05:27:15 +08:00
|
|
|
const KeyRef changeFeedDurablePrefix = changeFeedDurableKeys.begin;
|
2021-07-31 06:23:42 +08:00
|
|
|
|
2021-10-12 04:53:36 +08:00
|
|
|
const Value changeFeedDurableKey(Key const& feed, Version version) {
|
2021-08-14 05:27:15 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withChangeFeed()));
|
|
|
|
wr.serializeBytes(changeFeedDurablePrefix);
|
2021-07-31 06:23:42 +08:00
|
|
|
wr << feed;
|
2021-08-11 05:37:05 +08:00
|
|
|
wr << bigEndian64(version);
|
2021-07-31 06:23:42 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-08-14 05:27:15 +08:00
|
|
|
std::pair<Key, Version> decodeChangeFeedDurableKey(ValueRef const& key) {
|
2021-07-31 06:23:42 +08:00
|
|
|
Key feed;
|
|
|
|
Version version;
|
2021-08-14 05:27:15 +08:00
|
|
|
BinaryReader reader(key.removePrefix(changeFeedDurablePrefix), AssumeVersion(ProtocolVersion::withChangeFeed()));
|
2021-07-31 06:23:42 +08:00
|
|
|
reader >> feed;
|
|
|
|
reader >> version;
|
2021-08-11 05:37:05 +08:00
|
|
|
return std::make_pair(feed, bigEndian64(version));
|
2021-07-31 06:23:42 +08:00
|
|
|
}
|
2021-10-12 04:53:36 +08:00
|
|
|
const Value changeFeedDurableValue(Standalone<VectorRef<MutationRef>> const& mutations, Version knownCommittedVersion) {
|
2021-08-14 05:27:15 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withChangeFeed()));
|
2021-07-31 06:23:42 +08:00
|
|
|
wr << mutations;
|
2021-10-12 04:53:36 +08:00
|
|
|
wr << knownCommittedVersion;
|
2021-07-31 06:23:42 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-10-12 04:53:36 +08:00
|
|
|
std::pair<Standalone<VectorRef<MutationRef>>, Version> decodeChangeFeedDurableValue(ValueRef const& value) {
|
2021-07-31 06:23:42 +08:00
|
|
|
Standalone<VectorRef<MutationRef>> mutations;
|
2021-10-12 04:53:36 +08:00
|
|
|
Version knownCommittedVersion;
|
2021-07-31 06:23:42 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> mutations;
|
2021-10-12 04:53:36 +08:00
|
|
|
reader >> knownCommittedVersion;
|
|
|
|
return std::make_pair(mutations, knownCommittedVersion);
|
2021-07-31 06:23:42 +08:00
|
|
|
}
|
|
|
|
|
2021-05-30 02:48:47 +08:00
|
|
|
const KeyRef configTransactionDescriptionKey = "\xff\xff/description"_sr;
|
|
|
|
const KeyRange globalConfigKnobKeys = singleKeyRange("\xff\xff/globalKnobs"_sr);
|
|
|
|
const KeyRangeRef configKnobKeys("\xff\xff/knobs/"_sr, "\xff\xff/knobs0"_sr);
|
|
|
|
const KeyRangeRef configClassKeys("\xff\xff/configClasses/"_sr, "\xff\xff/configClasses0"_sr);
|
2021-06-02 06:39:34 +08:00
|
|
|
|
2021-07-07 03:49:36 +08:00
|
|
|
// key to watch for changes in active blob ranges + KeyRangeMap of active blob ranges
|
2021-09-01 01:30:43 +08:00
|
|
|
// Blob Manager + Worker stuff is all \xff\x02 to avoid Transaction State Store
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef blobRangeChangeKey = "\xff\x02/blobRangeChange"_sr;
|
|
|
|
const KeyRangeRef blobRangeKeys("\xff\x02/blobRange/"_sr, "\xff\x02/blobRange0"_sr);
|
|
|
|
const KeyRef blobManagerEpochKey = "\xff\x02/blobManagerEpoch"_sr;
|
2021-07-07 03:49:36 +08:00
|
|
|
|
2021-08-28 05:33:07 +08:00
|
|
|
const Value blobManagerEpochValueFor(int64_t epoch) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
2021-08-28 05:33:07 +08:00
|
|
|
wr << epoch;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-07-23 01:14:30 +08:00
|
|
|
|
2021-08-28 05:33:07 +08:00
|
|
|
int64_t decodeBlobManagerEpochValue(ValueRef const& value) {
|
|
|
|
int64_t epoch;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-08-28 05:33:07 +08:00
|
|
|
reader >> epoch;
|
|
|
|
return epoch;
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
// blob granule data
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRef blobRangeActive = "1"_sr;
|
2022-08-19 13:26:38 +08:00
|
|
|
const KeyRef blobRangeInactive = StringRef();
|
2022-08-08 22:45:52 +08:00
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef blobGranuleFileKeys("\xff\x02/bgf/"_sr, "\xff\x02/bgf0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleMappingKeys("\xff\x02/bgm/"_sr, "\xff\x02/bgm0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleLockKeys("\xff\x02/bgl/"_sr, "\xff\x02/bgl0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleSplitKeys("\xff\x02/bgs/"_sr, "\xff\x02/bgs0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleMergeKeys("\xff\x02/bgmerge/"_sr, "\xff\x02/bgmerge0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleMergeBoundaryKeys("\xff\x02/bgmergebounds/"_sr, "\xff\x02/bgmergebounds0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleHistoryKeys("\xff\x02/bgh/"_sr, "\xff\x02/bgh0"_sr);
|
|
|
|
const KeyRangeRef blobGranulePurgeKeys("\xff\x02/bgp/"_sr, "\xff\x02/bgp0"_sr);
|
|
|
|
const KeyRangeRef blobGranuleForcePurgedKeys("\xff\x02/bgpforce/"_sr, "\xff\x02/bgpforce0"_sr);
|
|
|
|
const KeyRef blobGranulePurgeChangeKey = "\xff\x02/bgpChange"_sr;
|
2021-07-23 01:14:30 +08:00
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const uint8_t BG_FILE_TYPE_DELTA = 'D';
|
|
|
|
const uint8_t BG_FILE_TYPE_SNAPSHOT = 'S';
|
|
|
|
|
2022-03-15 06:38:31 +08:00
|
|
|
const Key blobGranuleFileKeyFor(UID granuleID, Version fileVersion, uint8_t fileType) {
|
2021-10-09 06:35:36 +08:00
|
|
|
ASSERT(fileType == 'D' || fileType == 'S');
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleFileKeys.begin);
|
2021-10-15 03:58:37 +08:00
|
|
|
wr << granuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
wr << bigEndian64(fileVersion);
|
2022-03-15 06:38:31 +08:00
|
|
|
wr << fileType;
|
2021-10-09 06:35:36 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2022-03-15 06:38:31 +08:00
|
|
|
std::tuple<UID, Version, uint8_t> decodeBlobGranuleFileKey(KeyRef const& key) {
|
2021-10-15 03:58:37 +08:00
|
|
|
UID granuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
Version fileVersion;
|
2022-03-15 06:38:31 +08:00
|
|
|
uint8_t fileType;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(key.removePrefix(blobGranuleFileKeys.begin), AssumeVersion(ProtocolVersion::withBlobGranule()));
|
2021-10-15 03:58:37 +08:00
|
|
|
reader >> granuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
reader >> fileVersion;
|
2022-03-15 06:38:31 +08:00
|
|
|
reader >> fileType;
|
2021-10-09 06:35:36 +08:00
|
|
|
ASSERT(fileType == 'D' || fileType == 'S');
|
2022-03-15 06:38:31 +08:00
|
|
|
return std::tuple(granuleID, bigEndian64(fileVersion), fileType);
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2021-10-15 03:58:37 +08:00
|
|
|
const KeyRange blobGranuleFileKeyRangeFor(UID granuleID) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleFileKeys.begin);
|
2021-10-15 03:58:37 +08:00
|
|
|
wr << granuleID;
|
|
|
|
Key startKey = wr.toValue();
|
|
|
|
return KeyRangeRef(startKey, strinc(startKey));
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2022-07-14 04:53:20 +08:00
|
|
|
const Value blobGranuleFileValueFor(StringRef const& filename,
|
|
|
|
int64_t offset,
|
|
|
|
int64_t length,
|
|
|
|
int64_t fullFileLength,
|
2023-03-15 21:27:46 +08:00
|
|
|
int64_t logicalSize,
|
2022-07-14 04:53:20 +08:00
|
|
|
Optional<BlobGranuleCipherKeysMeta> cipherKeysMeta) {
|
2023-03-15 21:27:46 +08:00
|
|
|
auto protocolVersion = CLIENT_KNOBS->ENABLE_BLOB_GRANULE_FILE_LOGICAL_SIZE
|
|
|
|
? ProtocolVersion::withBlobGranuleFileLogicalSize()
|
|
|
|
: ProtocolVersion::withBlobGranule();
|
|
|
|
BinaryWriter wr(IncludeVersion(protocolVersion));
|
2021-10-09 06:35:36 +08:00
|
|
|
wr << filename;
|
|
|
|
wr << offset;
|
|
|
|
wr << length;
|
2022-03-29 03:48:12 +08:00
|
|
|
wr << fullFileLength;
|
2022-07-14 04:53:20 +08:00
|
|
|
wr << cipherKeysMeta;
|
2023-03-15 21:27:46 +08:00
|
|
|
if (CLIENT_KNOBS->ENABLE_BLOB_GRANULE_FILE_LOGICAL_SIZE) {
|
|
|
|
wr << logicalSize;
|
|
|
|
}
|
2021-10-09 06:35:36 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:27:46 +08:00
|
|
|
std::tuple<Standalone<StringRef>, int64_t, int64_t, int64_t, int64_t, Optional<BlobGranuleCipherKeysMeta>>
|
2022-07-14 04:53:20 +08:00
|
|
|
decodeBlobGranuleFileValue(ValueRef const& value) {
|
2021-10-09 06:35:36 +08:00
|
|
|
StringRef filename;
|
|
|
|
int64_t offset;
|
|
|
|
int64_t length;
|
2022-03-29 03:48:12 +08:00
|
|
|
int64_t fullFileLength;
|
2023-03-15 21:27:46 +08:00
|
|
|
int64_t logicalSize;
|
2022-07-14 04:53:20 +08:00
|
|
|
Optional<BlobGranuleCipherKeysMeta> cipherKeysMeta;
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> filename;
|
|
|
|
reader >> offset;
|
|
|
|
reader >> length;
|
2022-03-29 03:48:12 +08:00
|
|
|
reader >> fullFileLength;
|
2022-07-14 04:53:20 +08:00
|
|
|
reader >> cipherKeysMeta;
|
2023-03-15 21:27:46 +08:00
|
|
|
if (reader.protocolVersion().hasBlobGranuleFileLogicalSize()) {
|
|
|
|
reader >> logicalSize;
|
|
|
|
} else {
|
|
|
|
// fall back to estimating logical size as physical size
|
|
|
|
logicalSize = length;
|
|
|
|
}
|
|
|
|
return std::tuple(filename, offset, length, fullFileLength, logicalSize, cipherKeysMeta);
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2022-04-09 05:15:25 +08:00
|
|
|
const Value blobGranulePurgeValueFor(Version version, KeyRange range, bool force) {
|
2021-11-20 09:54:22 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << version;
|
2022-02-23 04:00:09 +08:00
|
|
|
wr << range;
|
2021-11-20 09:54:22 +08:00
|
|
|
wr << force;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2022-04-09 05:15:25 +08:00
|
|
|
std::tuple<Version, KeyRange, bool> decodeBlobGranulePurgeValue(ValueRef const& value) {
|
2021-11-20 09:54:22 +08:00
|
|
|
Version version;
|
2022-02-23 04:00:09 +08:00
|
|
|
KeyRange range;
|
2021-11-20 09:54:22 +08:00
|
|
|
bool force;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> version;
|
2022-02-23 04:00:09 +08:00
|
|
|
reader >> range;
|
2021-11-20 09:54:22 +08:00
|
|
|
reader >> force;
|
2022-02-23 04:00:09 +08:00
|
|
|
return std::tuple(version, range, force);
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2021-07-23 01:14:30 +08:00
|
|
|
const Value blobGranuleMappingValueFor(UID const& workerID) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
2021-07-23 01:14:30 +08:00
|
|
|
wr << workerID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBlobGranuleMappingValue(ValueRef const& value) {
|
|
|
|
UID workerID;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-07-23 01:14:30 +08:00
|
|
|
reader >> workerID;
|
|
|
|
return workerID;
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const Key blobGranuleLockKeyFor(KeyRangeRef const& keyRange) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleLockKeys.begin);
|
|
|
|
wr << keyRange;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2021-09-04 04:13:26 +08:00
|
|
|
const Value blobGranuleLockValueFor(int64_t epoch, int64_t seqno, UID changeFeedId) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
2021-08-31 02:07:25 +08:00
|
|
|
wr << epoch;
|
|
|
|
wr << seqno;
|
2021-09-04 04:13:26 +08:00
|
|
|
wr << changeFeedId;
|
2021-08-28 05:33:07 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2021-09-04 04:13:26 +08:00
|
|
|
std::tuple<int64_t, int64_t, UID> decodeBlobGranuleLockValue(const ValueRef& value) {
|
2021-08-31 02:07:25 +08:00
|
|
|
int64_t epoch, seqno;
|
2021-09-04 04:13:26 +08:00
|
|
|
UID changeFeedId;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-08-31 02:07:25 +08:00
|
|
|
reader >> epoch;
|
|
|
|
reader >> seqno;
|
2021-09-04 04:13:26 +08:00
|
|
|
reader >> changeFeedId;
|
|
|
|
return std::make_tuple(epoch, seqno, changeFeedId);
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const Key blobGranuleSplitKeyFor(UID const& parentGranuleID, UID const& granuleID) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleSplitKeys.begin);
|
2021-10-15 03:58:37 +08:00
|
|
|
wr << parentGranuleID;
|
|
|
|
wr << granuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<UID, UID> decodeBlobGranuleSplitKey(KeyRef const& key) {
|
2021-10-15 03:58:37 +08:00
|
|
|
UID parentGranuleID;
|
|
|
|
UID granuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(key.removePrefix(blobGranuleSplitKeys.begin),
|
|
|
|
AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
|
2021-10-15 03:58:37 +08:00
|
|
|
reader >> parentGranuleID;
|
|
|
|
reader >> granuleID;
|
|
|
|
return std::pair(parentGranuleID, granuleID);
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2021-10-15 03:58:37 +08:00
|
|
|
const KeyRange blobGranuleSplitKeyRangeFor(UID const& parentGranuleID) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleSplitKeys.begin);
|
2021-10-15 03:58:37 +08:00
|
|
|
wr << parentGranuleID;
|
2021-10-09 06:35:36 +08:00
|
|
|
|
2021-10-15 03:58:37 +08:00
|
|
|
Key startKey = wr.toValue();
|
|
|
|
return KeyRangeRef(startKey, strinc(startKey));
|
2021-10-09 06:35:36 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 02:41:00 +08:00
|
|
|
const Key blobGranuleMergeKeyFor(UID const& mergeGranuleID) {
|
|
|
|
// TODO should we bump this assumed version to 7.2 as blob granule merging is not in 7.1? 7.1 won't try to read this
|
|
|
|
// data though since it didn't exist before
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleMergeKeys.begin);
|
|
|
|
wr << mergeGranuleID;
|
|
|
|
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBlobGranuleMergeKey(KeyRef const& key) {
|
|
|
|
UID mergeGranuleID;
|
|
|
|
BinaryReader reader(key.removePrefix(blobGranuleMergeKeys.begin),
|
|
|
|
AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
|
|
|
|
reader >> mergeGranuleID;
|
|
|
|
return mergeGranuleID;
|
|
|
|
}
|
|
|
|
|
2021-09-04 04:13:26 +08:00
|
|
|
const Value blobGranuleSplitValueFor(BlobGranuleSplitState st) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
2021-09-04 04:13:26 +08:00
|
|
|
wr << st;
|
2021-09-23 01:46:20 +08:00
|
|
|
return addVersionStampAtEnd(wr.toValue());
|
2021-09-04 04:13:26 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 01:46:20 +08:00
|
|
|
std::pair<BlobGranuleSplitState, Version> decodeBlobGranuleSplitValue(const ValueRef& value) {
|
2021-09-04 04:13:26 +08:00
|
|
|
BlobGranuleSplitState st;
|
2021-09-23 01:46:20 +08:00
|
|
|
Version v;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-09-04 04:13:26 +08:00
|
|
|
reader >> st;
|
2021-09-23 01:46:20 +08:00
|
|
|
reader >> v;
|
2021-10-30 01:07:16 +08:00
|
|
|
|
|
|
|
return std::pair(st, bigEndian64(v));
|
2021-09-23 01:46:20 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 02:41:00 +08:00
|
|
|
const Value blobGranuleMergeValueFor(KeyRange mergeKeyRange,
|
|
|
|
std::vector<UID> parentGranuleIDs,
|
2022-07-16 05:11:48 +08:00
|
|
|
std::vector<Key> parentGranuleRanges,
|
2022-04-26 02:41:00 +08:00
|
|
|
std::vector<Version> parentGranuleStartVersions) {
|
2022-07-16 05:11:48 +08:00
|
|
|
ASSERT(parentGranuleIDs.size() == parentGranuleRanges.size() - 1);
|
2022-04-26 02:41:00 +08:00
|
|
|
ASSERT(parentGranuleIDs.size() == parentGranuleStartVersions.size());
|
|
|
|
|
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << mergeKeyRange;
|
|
|
|
wr << parentGranuleIDs;
|
|
|
|
wr << parentGranuleRanges;
|
|
|
|
wr << parentGranuleStartVersions;
|
|
|
|
return addVersionStampAtEnd(wr.toValue());
|
|
|
|
}
|
2022-07-16 05:11:48 +08:00
|
|
|
std::tuple<KeyRange, Version, std::vector<UID>, std::vector<Key>, std::vector<Version>> decodeBlobGranuleMergeValue(
|
|
|
|
ValueRef const& value) {
|
2022-04-26 02:41:00 +08:00
|
|
|
KeyRange range;
|
|
|
|
Version v;
|
|
|
|
std::vector<UID> parentGranuleIDs;
|
2022-07-16 05:11:48 +08:00
|
|
|
std::vector<Key> parentGranuleRanges;
|
2022-04-26 02:41:00 +08:00
|
|
|
std::vector<Version> parentGranuleStartVersions;
|
|
|
|
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> range;
|
|
|
|
reader >> parentGranuleIDs;
|
|
|
|
reader >> parentGranuleRanges;
|
|
|
|
reader >> parentGranuleStartVersions;
|
|
|
|
reader >> v;
|
|
|
|
|
2022-07-16 05:11:48 +08:00
|
|
|
ASSERT(parentGranuleIDs.size() == parentGranuleRanges.size() - 1);
|
2022-04-26 02:41:00 +08:00
|
|
|
ASSERT(parentGranuleIDs.size() == parentGranuleStartVersions.size());
|
|
|
|
ASSERT(bigEndian64(v) >= 0);
|
|
|
|
|
|
|
|
return std::tuple(range, bigEndian64(v), parentGranuleIDs, parentGranuleRanges, parentGranuleStartVersions);
|
|
|
|
}
|
|
|
|
|
blob: allow for alignment of granules to tuple boundaries (#7746)
* blob: read TenantMap during recovery
Future functionality in the blob subsystem will rely on the tenant data
being loaded. This fixes this issue by loading the tenant data before
completing recovery such that continued actions on existing blob
granules will have access to the tenant data.
Example scenario with failover, splits are restarted before loading the
tenant data:
BM - BlobManager
epoch 3: epoch 4:
BM record intent to split.
Epoch fails.
BM recovery begins.
BM fails to persist split.
BM recovery finishes.
BM.checkBlobWorkerList()
maybeSplitRange().
BM.monitorClientRanges().
loads tenant data.
bin/fdbserver -r simulation -f tests/slow/BlobGranuleCorrectness.toml \
-s 223570924 -b on --crash --trace_format json
* blob: add tuple key truncation for blob granule alignment
FDB has a backup system available using the blob manager and blob
granule subsystem. If we want to audit the data in the blobs, it's a lot
easier if we can align them to something meaningful.
When a blob granule is being split, we ask the storage metrics system
for split points as it holds approximate data distribution metrics.
These keys are then processed to determine if they are a tuple and
should be truncated according to the new knob,
BG_KEY_TUPLE_TRUNCATE_OFFSET.
Here we keep all aligned keys together in the same granule even if it is
larger than the allowed granule size. The following commit will address
this by adding merge boundaries.
* blob: minor clean ups in merging code
1. Rename mergeNow -> seen. This is more inline with clocksweep naming
and removes the confusion between mergeNow and canMergeNow.
2. Make clearMergeCandidate() reset to MergeCandidateCannotMerge to make
a clear distinction what we're accomplishing.
3. Rename canMergeNow() -> mergeEligble().
* blob: add explicit (hard) boundaries
Blob ranges can be specified either through explicit ranges or at the
tenant level. Right now this is managed implicitly. This commit aims to
make it a little more explicit.
Blobification begins in monitorClientRanges() which parses either the
explicit blob ranges or the tenant map. As we do this and add new
ranges, let's explicitly track what is a hard boundary and what isn't.
When blob merging occurs, we respect this boundary. When a hard boundary
is encountered, we submit the found eligible ranges and start looking
for a new range beginning with this hard boundary.
* blob: create BlobGranuleSplitPoints struct
This is a setup for the following commit. Our goal here is to provide a
structure for split points to be passed around. The need is for us to be
able to carry uncommitted state until it is committed and we can apply
these mutations to the in-memory data structures.
* blob: implement soft boundaries
An earlier commit establishes the need to create data boundaries within
a tenant. The reality is we may encounter a set of keys that degnerate
to the same key prefix. We'll need to be able to split those across
granules, but we want to ensure we merge the split granules together
before merging with other granules.
This adds to the BlobGranuleSplitPoints state of new
BlobGranuleMergeBoundary items. BlobGranuleMergeBoundary contains state
saying if it is a left or right boundary. This information is used to,
like hard boundaries, force merging of like granules first.
We read the BlobGranuleMergeBoundary map into memory at recovery.
2022-08-03 05:06:25 +08:00
|
|
|
const Key blobGranuleMergeBoundaryKeyFor(const KeyRef& key) {
|
|
|
|
return key.withPrefix(blobGranuleMergeBoundaryKeys.begin);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value blobGranuleMergeBoundaryValueFor(BlobGranuleMergeBoundary const& boundary) {
|
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << boundary;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
Standalone<BlobGranuleMergeBoundary> decodeBlobGranuleMergeBoundaryValue(const ValueRef& value) {
|
|
|
|
Standalone<BlobGranuleMergeBoundary> boundaryValue;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> boundaryValue;
|
|
|
|
return boundaryValue;
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const Key blobGranuleHistoryKeyFor(KeyRangeRef const& range, Version version) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobGranuleHistoryKeys.begin);
|
|
|
|
wr << range;
|
|
|
|
wr << bigEndian64(version);
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<KeyRange, Version> decodeBlobGranuleHistoryKey(const KeyRef& key) {
|
|
|
|
KeyRangeRef keyRange;
|
|
|
|
Version version;
|
|
|
|
BinaryReader reader(key.removePrefix(blobGranuleHistoryKeys.begin),
|
|
|
|
AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
reader >> keyRange;
|
|
|
|
reader >> version;
|
|
|
|
return std::make_pair(keyRange, bigEndian64(version));
|
|
|
|
}
|
2021-09-23 01:46:20 +08:00
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const KeyRange blobGranuleHistoryKeyRangeFor(KeyRangeRef const& range) {
|
|
|
|
return KeyRangeRef(blobGranuleHistoryKeyFor(range, 0), blobGranuleHistoryKeyFor(range, MAX_VERSION));
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value blobGranuleHistoryValueFor(Standalone<BlobGranuleHistoryValue> const& historyValue) {
|
2022-07-16 05:11:48 +08:00
|
|
|
ASSERT(historyValue.parentVersions.empty() ||
|
|
|
|
historyValue.parentBoundaries.size() - 1 == historyValue.parentVersions.size());
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << historyValue;
|
2021-09-23 01:46:20 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
Standalone<BlobGranuleHistoryValue> decodeBlobGranuleHistoryValue(const ValueRef& value) {
|
|
|
|
Standalone<BlobGranuleHistoryValue> historyValue;
|
2021-09-24 22:55:37 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2021-10-09 06:35:36 +08:00
|
|
|
reader >> historyValue;
|
2022-07-16 05:11:48 +08:00
|
|
|
ASSERT(historyValue.parentVersions.empty() ||
|
|
|
|
historyValue.parentBoundaries.size() - 1 == historyValue.parentVersions.size());
|
2021-10-09 06:35:36 +08:00
|
|
|
return historyValue;
|
2021-08-28 05:33:07 +08:00
|
|
|
}
|
|
|
|
|
2022-09-20 02:35:58 +08:00
|
|
|
const KeyRangeRef blobWorkerListKeys("\xff\x02/bwList/"_sr, "\xff\x02/bwList0"_sr);
|
2021-07-23 01:14:30 +08:00
|
|
|
|
|
|
|
const Key blobWorkerListKeyFor(UID workerID) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
2021-07-23 01:14:30 +08:00
|
|
|
wr.serializeBytes(blobWorkerListKeys.begin);
|
|
|
|
wr << workerID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBlobWorkerListKey(KeyRef const& key) {
|
|
|
|
UID workerID;
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryReader reader(key.removePrefix(blobWorkerListKeys.begin), AssumeVersion(ProtocolVersion::withBlobGranule()));
|
2021-07-23 01:14:30 +08:00
|
|
|
reader >> workerID;
|
|
|
|
return workerID;
|
|
|
|
}
|
|
|
|
|
2021-10-09 06:35:36 +08:00
|
|
|
const Value blobWorkerListValue(BlobWorkerInterface const& worker) {
|
|
|
|
return ObjectWriter::toValue(worker, IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
}
|
|
|
|
|
2021-07-23 01:14:30 +08:00
|
|
|
BlobWorkerInterface decodeBlobWorkerListValue(ValueRef const& value) {
|
|
|
|
BlobWorkerInterface interf;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(interf);
|
|
|
|
return interf;
|
|
|
|
}
|
2021-07-08 06:04:49 +08:00
|
|
|
|
2023-02-13 02:44:53 +08:00
|
|
|
const KeyRangeRef blobWorkerAffinityKeys("\xff\x02/bwa/"_sr, "\xff\x02/bwa0"_sr);
|
|
|
|
|
|
|
|
const Key blobWorkerAffinityKeyFor(UID workerID) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
2023-02-21 08:47:26 +08:00
|
|
|
wr.serializeBytes(blobWorkerAffinityKeys.begin);
|
2023-02-13 02:44:53 +08:00
|
|
|
wr << workerID;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBlobWorkerAffinityKey(KeyRef const& key) {
|
|
|
|
UID workerID;
|
2023-02-21 08:47:26 +08:00
|
|
|
BinaryReader reader(key.removePrefix(blobWorkerAffinityKeys.begin),
|
|
|
|
AssumeVersion(ProtocolVersion::withBlobGranule()));
|
2023-02-13 02:44:53 +08:00
|
|
|
reader >> workerID;
|
|
|
|
return workerID;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value blobWorkerAffinityValue(UID const& id) {
|
|
|
|
return ObjectWriter::toValue(id, IncludeVersion(ProtocolVersion::withBlobGranuleFile()));
|
|
|
|
}
|
|
|
|
|
|
|
|
UID decodeBlobWorkerAffinityValue(ValueRef const& value) {
|
|
|
|
UID id;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(id);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2022-10-27 00:55:55 +08:00
|
|
|
const KeyRangeRef blobRestoreCommandKeys("\xff\x02/blobRestoreCommand/"_sr, "\xff\x02/blobRestoreCommand0"_sr);
|
|
|
|
|
|
|
|
const Value blobRestoreCommandKeyFor(const KeyRangeRef range) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobRestoreCommandKeys.begin);
|
|
|
|
wr << range;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRange decodeBlobRestoreCommandKeyFor(const KeyRef key) {
|
|
|
|
KeyRange range;
|
|
|
|
BinaryReader reader(key.removePrefix(blobRestoreCommandKeys.begin),
|
|
|
|
AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
reader >> range;
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2023-03-08 23:50:30 +08:00
|
|
|
const Value blobRestoreCommandValueFor(BlobRestoreState restoreState) {
|
2022-10-27 00:55:55 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
2023-03-08 23:50:30 +08:00
|
|
|
wr << restoreState;
|
2022-10-27 00:55:55 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2023-03-08 23:50:30 +08:00
|
|
|
Standalone<BlobRestoreState> decodeBlobRestoreState(ValueRef const& value) {
|
|
|
|
Standalone<BlobRestoreState> restoreState;
|
2022-10-27 00:55:55 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2023-03-08 23:50:30 +08:00
|
|
|
reader >> restoreState;
|
|
|
|
return restoreState;
|
2022-10-27 00:55:55 +08:00
|
|
|
}
|
|
|
|
|
2022-12-04 00:45:23 +08:00
|
|
|
const KeyRangeRef blobRestoreArgKeys("\xff\x02/blobRestoreArgs/"_sr, "\xff\x02/blobRestoreArgs0"_sr);
|
|
|
|
|
|
|
|
const Value blobRestoreArgKeyFor(const KeyRangeRef range) {
|
|
|
|
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr.serializeBytes(blobRestoreArgKeys.begin);
|
|
|
|
wr << range;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRange decodeBlobRestoreArgKeyFor(const KeyRef key) {
|
|
|
|
KeyRange range;
|
|
|
|
BinaryReader reader(key.removePrefix(blobRestoreArgKeys.begin), AssumeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
reader >> range;
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value blobRestoreArgValueFor(BlobRestoreArg args) {
|
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << args;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
Standalone<BlobRestoreArg> decodeBlobRestoreArg(ValueRef const& value) {
|
|
|
|
Standalone<BlobRestoreArg> args;
|
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
reader >> args;
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2023-01-25 08:14:00 +08:00
|
|
|
const Key blobManifestVersionKey = "\xff\x02/blobManifestVersion"_sr;
|
2023-02-02 05:56:07 +08:00
|
|
|
const Key blobGranulesLastFlushKey = "\xff\x02/blobGranulesLastFlushTs"_sr;
|
2023-01-25 08:14:00 +08:00
|
|
|
|
2022-10-04 08:33:40 +08:00
|
|
|
const KeyRangeRef idempotencyIdKeys("\xff\x02/idmp/"_sr, "\xff\x02/idmp0"_sr);
|
2022-10-05 08:07:01 +08:00
|
|
|
const KeyRef idempotencyIdsExpiredVersion("\xff\x02/idmpExpiredVersion"_sr);
|
2022-10-04 08:33:40 +08:00
|
|
|
|
2021-03-06 03:28:15 +08:00
|
|
|
// for tests
|
2022-03-29 14:52:26 +08:00
|
|
|
void testSSISerdes(StorageServerInterface const& ssi) {
|
2022-03-22 01:41:28 +08:00
|
|
|
printf("ssi=\nid=%s\nlocality=%s\nisTss=%s\ntssId=%s\nacceptingRequests=%s\naddress=%s\ngetValue=%s\n\n\n",
|
2021-03-06 03:28:15 +08:00
|
|
|
ssi.id().toString().c_str(),
|
|
|
|
ssi.locality.toString().c_str(),
|
2021-05-13 02:53:20 +08:00
|
|
|
ssi.isTss() ? "true" : "false",
|
|
|
|
ssi.isTss() ? ssi.tssPairID.get().toString().c_str() : "",
|
2022-03-29 14:52:26 +08:00
|
|
|
ssi.isAcceptingRequests() ? "true" : "false",
|
2021-03-06 03:28:15 +08:00
|
|
|
ssi.address().toString().c_str(),
|
|
|
|
ssi.getValue.getEndpoint().token.toString().c_str());
|
|
|
|
|
2022-03-29 14:52:26 +08:00
|
|
|
StorageServerInterface ssi2 = decodeServerListValue(serverListValue(ssi));
|
2021-03-06 03:28:15 +08:00
|
|
|
|
2022-03-22 01:41:28 +08:00
|
|
|
printf("ssi2=\nid=%s\nlocality=%s\nisTss=%s\ntssId=%s\nacceptingRequests=%s\naddress=%s\ngetValue=%s\n\n\n",
|
2021-03-06 03:28:15 +08:00
|
|
|
ssi2.id().toString().c_str(),
|
|
|
|
ssi2.locality.toString().c_str(),
|
2021-05-13 02:53:20 +08:00
|
|
|
ssi2.isTss() ? "true" : "false",
|
|
|
|
ssi2.isTss() ? ssi2.tssPairID.get().toString().c_str() : "",
|
2022-03-29 14:52:26 +08:00
|
|
|
ssi2.isAcceptingRequests() ? "true" : "false",
|
2021-03-06 03:28:15 +08:00
|
|
|
ssi2.address().toString().c_str(),
|
|
|
|
ssi2.getValue.getEndpoint().token.toString().c_str());
|
|
|
|
|
|
|
|
ASSERT(ssi.id() == ssi2.id());
|
|
|
|
ASSERT(ssi.locality == ssi2.locality);
|
2021-05-13 02:53:20 +08:00
|
|
|
ASSERT(ssi.isTss() == ssi2.isTss());
|
2022-03-29 14:52:26 +08:00
|
|
|
ASSERT(ssi.isAcceptingRequests() == ssi2.isAcceptingRequests());
|
2021-05-13 02:53:20 +08:00
|
|
|
if (ssi.isTss()) {
|
|
|
|
ASSERT(ssi2.tssPairID.get() == ssi2.tssPairID.get());
|
2021-03-06 03:28:15 +08:00
|
|
|
}
|
|
|
|
ASSERT(ssi.address() == ssi2.address());
|
|
|
|
ASSERT(ssi.getValue.getEndpoint().token == ssi2.getValue.getEndpoint().token);
|
|
|
|
}
|
|
|
|
|
|
|
|
// unit test for serialization since tss stuff had bugs
|
|
|
|
TEST_CASE("/SystemData/SerDes/SSI") {
|
|
|
|
printf("testing ssi serdes\n");
|
|
|
|
LocalityData localityData(Optional<Standalone<StringRef>>(),
|
|
|
|
Standalone<StringRef>(deterministicRandom()->randomUniqueID().toString()),
|
|
|
|
Standalone<StringRef>(deterministicRandom()->randomUniqueID().toString()),
|
|
|
|
Optional<Standalone<StringRef>>());
|
|
|
|
|
|
|
|
// non-tss
|
|
|
|
StorageServerInterface ssi;
|
|
|
|
ssi.uniqueID = UID(0x1234123412341234, 0x5678567856785678);
|
|
|
|
ssi.locality = localityData;
|
|
|
|
ssi.initEndpoints();
|
|
|
|
|
2022-03-29 14:52:26 +08:00
|
|
|
testSSISerdes(ssi);
|
2021-03-06 03:28:15 +08:00
|
|
|
|
|
|
|
ssi.tssPairID = UID(0x2345234523452345, 0x1238123812381238);
|
|
|
|
|
2022-03-29 14:52:26 +08:00
|
|
|
testSSISerdes(ssi);
|
2021-03-06 03:28:15 +08:00
|
|
|
printf("ssi serdes test complete\n");
|
|
|
|
|
|
|
|
return Void();
|
2021-06-02 06:39:34 +08:00
|
|
|
}
|
2022-07-08 11:49:16 +08:00
|
|
|
|
|
|
|
// Tests compatibility of different keyServersValue() and decodeKeyServersValue().
|
|
|
|
TEST_CASE("noSim/SystemData/compat/KeyServers") {
|
|
|
|
printf("testing keyServers serdes\n");
|
|
|
|
std::vector<UID> src, dest;
|
|
|
|
std::map<Tag, UID> tag_uid;
|
|
|
|
std::map<UID, Tag> uid_tag;
|
|
|
|
std::vector<Tag> srcTag, destTag;
|
|
|
|
const int n = 3;
|
|
|
|
int8_t locality = 1;
|
|
|
|
uint16_t id = 1;
|
|
|
|
UID srcId = deterministicRandom()->randomUniqueID(), destId = deterministicRandom()->randomUniqueID();
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
src.push_back(deterministicRandom()->randomUniqueID());
|
|
|
|
tag_uid.emplace(Tag(locality, id), src.back());
|
|
|
|
uid_tag.emplace(src.back(), Tag(locality, id++));
|
|
|
|
dest.push_back(deterministicRandom()->randomUniqueID());
|
|
|
|
tag_uid.emplace(Tag(locality, id), dest.back());
|
|
|
|
uid_tag.emplace(dest.back(), Tag(locality, id++));
|
|
|
|
}
|
|
|
|
std::sort(src.begin(), src.end());
|
|
|
|
std::sort(dest.begin(), dest.end());
|
|
|
|
RangeResult idTag;
|
|
|
|
for (int i = 0; i < src.size(); ++i) {
|
|
|
|
idTag.push_back_deep(idTag.arena(), KeyValueRef(serverTagKeyFor(src[i]), serverTagValue(uid_tag[src[i]])));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < dest.size(); ++i) {
|
|
|
|
idTag.push_back_deep(idTag.arena(), KeyValueRef(serverTagKeyFor(dest[i]), serverTagValue(uid_tag[dest[i]])));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto decodeAndVerify =
|
|
|
|
[&src, &dest, &tag_uid, &idTag](ValueRef v, const UID expectedSrcId, const UID expectedDestId) {
|
|
|
|
std::vector<UID> resSrc, resDest;
|
|
|
|
UID resSrcId, resDestId;
|
|
|
|
|
|
|
|
decodeKeyServersValue(idTag, v, resSrc, resDest, resSrcId, resDestId);
|
|
|
|
TraceEvent("VerifyKeyServersSerDes")
|
|
|
|
.detail("ExpectedSrc", describe(src))
|
|
|
|
.detail("ActualSrc", describe(resSrc))
|
|
|
|
.detail("ExpectedDest", describe(dest))
|
|
|
|
.detail("ActualDest", describe(resDest))
|
|
|
|
.detail("ExpectedDestID", expectedDestId)
|
|
|
|
.detail("ActualDestID", resDestId)
|
|
|
|
.detail("ExpectedSrcID", expectedSrcId)
|
|
|
|
.detail("ActualSrcID", resSrcId);
|
|
|
|
ASSERT(std::equal(src.begin(), src.end(), resSrc.begin()));
|
|
|
|
ASSERT(std::equal(dest.begin(), dest.end(), resDest.begin()));
|
|
|
|
ASSERT(resSrcId == expectedSrcId);
|
|
|
|
ASSERT(resDestId == expectedDestId);
|
|
|
|
|
|
|
|
resSrc.clear();
|
|
|
|
resDest.clear();
|
|
|
|
decodeKeyServersValue(idTag, v, resSrc, resDest);
|
|
|
|
ASSERT(std::equal(src.begin(), src.end(), resSrc.begin()));
|
|
|
|
ASSERT(std::equal(dest.begin(), dest.end(), resDest.begin()));
|
|
|
|
|
|
|
|
resSrc.clear();
|
|
|
|
resDest.clear();
|
|
|
|
decodeKeyServersValue(tag_uid, v, resSrc, resDest);
|
|
|
|
ASSERT(std::equal(src.begin(), src.end(), resSrc.begin()));
|
|
|
|
ASSERT(std::equal(dest.begin(), dest.end(), resDest.begin()));
|
|
|
|
};
|
|
|
|
|
|
|
|
Value v = keyServersValue(src, dest, srcId, destId);
|
|
|
|
decodeAndVerify(v, srcId, destId);
|
|
|
|
|
|
|
|
printf("ssi serdes test part.1 complete\n");
|
|
|
|
|
|
|
|
v = keyServersValue(idTag, src, dest);
|
|
|
|
decodeAndVerify(v, anonymousShardId, anonymousShardId);
|
|
|
|
|
|
|
|
printf("ssi serdes test part.2 complete\n");
|
|
|
|
|
|
|
|
dest.clear();
|
|
|
|
destId = UID();
|
|
|
|
|
|
|
|
v = keyServersValue(src, dest, srcId, destId);
|
|
|
|
decodeAndVerify(v, srcId, destId);
|
|
|
|
|
|
|
|
printf("ssi serdes test part.3 complete\n");
|
|
|
|
|
|
|
|
v = keyServersValue(idTag, src, dest);
|
|
|
|
decodeAndVerify(v, anonymousShardId, UID());
|
|
|
|
|
|
|
|
printf("ssi serdes test complete\n");
|
|
|
|
|
|
|
|
return Void();
|
2022-10-19 08:57:43 +08:00
|
|
|
}
|