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"
|
2020-02-25 09:26:20 +08:00
|
|
|
#include "fdbclient/FDBTypes.h"
|
2020-04-15 08:07:41 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.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
|
|
|
|
|
|
|
const KeyRef systemKeysPrefix = LiteralStringRef("\xff");
|
|
|
|
const KeyRangeRef normalKeys(KeyRef(), systemKeysPrefix);
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef systemKeys(systemKeysPrefix, LiteralStringRef("\xff\xff"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRangeRef nonMetadataSystemKeys(LiteralStringRef("\xff\x02"), LiteralStringRef("\xff\x03"));
|
|
|
|
const KeyRangeRef allKeys = KeyRangeRef(normalKeys.begin, systemKeys.end);
|
|
|
|
const KeyRef afterAllKeys = LiteralStringRef("\xff\xff\x00");
|
2020-04-01 10:06:45 +08:00
|
|
|
const KeyRangeRef specialKeys = KeyRangeRef(LiteralStringRef("\xff\xff"), LiteralStringRef("\xff\xff\xff"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// keyServersKeys.contains(k) iff k.startsWith(keyServersPrefix)
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef keyServersKeys(LiteralStringRef("\xff/keyServers/"), LiteralStringRef("\xff/keyServers0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef keyServersPrefix = keyServersKeys.begin;
|
|
|
|
const KeyRef keyServersEnd = keyServersKeys.end;
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef keyServersKeyServersKeys(LiteralStringRef("\xff/keyServers/\xff/keyServers/"),
|
|
|
|
LiteralStringRef("\xff/keyServers/\xff/keyServers0"));
|
2017-07-27 04:45:11 +08:00
|
|
|
const KeyRef keyServersKeyServersKey = keyServersKeyServersKeys.begin;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key keyServersKey(const KeyRef& k) {
|
|
|
|
return k.withPrefix(keyServersPrefix);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRef keyServersKey(const KeyRef& k, Arena& arena) {
|
|
|
|
return k.withPrefix(keyServersPrefix, arena);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-05-04 04:14:16 +08:00
|
|
|
const Value keyServersValue(RangeResult result, const std::vector<UID>& src, const std::vector<UID>& dest) {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!CLIENT_KNOBS->TAG_ENCODE_KEY_SERVERS) {
|
|
|
|
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()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
srcTag.push_back(decodeServerTagValue(kv.value));
|
|
|
|
if (srcTag.back().locality == tagLocalityUpgraded) {
|
2020-05-09 07:17:10 +08:00
|
|
|
foundOldLocality = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
|
|
|
if (std::find(dest.begin(), dest.end(), uid) != dest.end()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
destTag.push_back(decodeServerTagValue(kv.value));
|
|
|
|
if (destTag.back().locality == tagLocalityUpgraded) {
|
2020-05-09 07:17:10 +08:00
|
|
|
foundOldLocality = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (foundOldLocality || src.size() != srcTag.size() || dest.size() != destTag.size()) {
|
2020-05-09 07:17:10 +08:00
|
|
|
ASSERT_WE_THINK(foundOldLocality);
|
2021-03-11 02:06:03 +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);
|
|
|
|
}
|
2021-03-11 02:06:03 +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
|
2021-03-11 02:06:03 +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,
|
2021-03-11 02:06:03 +08:00
|
|
|
const ValueRef& value,
|
|
|
|
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());
|
2021-03-11 02:06:03 +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()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
src.push_back(decodeServerTagKey(kv.key));
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
|
|
|
if (std::find(destTag.begin(), destTag.end(), tag) != destTag.end()) {
|
2021-03-11 02:06:03 +08:00
|
|
|
dest.push_back(decodeServerTagKey(kv.key));
|
2020-04-06 05:30:09 +08:00
|
|
|
}
|
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());
|
2021-03-11 02:06:03 +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());
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : srcTag) {
|
2020-05-09 07:17:10 +08:00
|
|
|
TraceEvent("SrcTag").detail("Tag", it.toString());
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& it : destTag) {
|
2020-05-09 07:17:10 +08:00
|
|
|
TraceEvent("DestTag").detail("Tag", it.toString());
|
|
|
|
}
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void decodeKeyServersValue(std::map<Tag, UID> const& tag_uid,
|
|
|
|
const ValueRef& value,
|
|
|
|
std::vector<UID>& src,
|
|
|
|
std::vector<UID>& dest) {
|
2020-05-10 07:54:35 +08:00
|
|
|
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();
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (value.size() !=
|
|
|
|
sizeof(ProtocolVersion) + sizeof(int) + srcLen * sizeof(Tag) + sizeof(int) + destLen * sizeof(Tag)) {
|
2020-05-10 07:54:35 +08:00
|
|
|
rd >> src >> dest;
|
|
|
|
rd.assertEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcTag.clear();
|
|
|
|
destTag.clear();
|
|
|
|
rd >> srcTag >> destTag;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto t : srcTag) {
|
2020-05-10 07:54:35 +08:00
|
|
|
auto itr = tag_uid.find(t);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (itr != tag_uid.end()) {
|
2020-05-10 07:54:35 +08:00
|
|
|
src.push_back(itr->second);
|
|
|
|
} else {
|
|
|
|
TraceEvent(SevError, "AttemptedToDecodeMissingSrcTag").detail("Tag", t.toString());
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto t : destTag) {
|
2020-05-10 07:54:35 +08:00
|
|
|
auto itr = tag_uid.find(t);
|
2021-03-11 02:06:03 +08:00
|
|
|
if (itr != tag_uid.end()) {
|
2020-05-10 07:54:35 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-04-29 01:34:10 +08:00
|
|
|
const KeyRangeRef conflictingKeysRange =
|
|
|
|
KeyRangeRef(LiteralStringRef("\xff\xff/transaction/conflicting_keys/"),
|
|
|
|
LiteralStringRef("\xff\xff/transaction/conflicting_keys/\xff\xff"));
|
2020-03-25 00:48:03 +08:00
|
|
|
const ValueRef conflictingKeysTrue = LiteralStringRef("1");
|
|
|
|
const ValueRef conflictingKeysFalse = LiteralStringRef("0");
|
|
|
|
|
2020-04-30 05:43:37 +08:00
|
|
|
const KeyRangeRef readConflictRangeKeysRange =
|
|
|
|
KeyRangeRef(LiteralStringRef("\xff\xff/transaction/read_conflict_range/"),
|
|
|
|
LiteralStringRef("\xff\xff/transaction/read_conflict_range/\xff\xff"));
|
|
|
|
|
|
|
|
const KeyRangeRef writeConflictRangeKeysRange =
|
|
|
|
KeyRangeRef(LiteralStringRef("\xff\xff/transaction/write_conflict_range/"),
|
|
|
|
LiteralStringRef("\xff\xff/transaction/write_conflict_range/\xff\xff"));
|
|
|
|
|
2021-09-22 02:51:20 +08:00
|
|
|
const KeyRef clusterIdKey = LiteralStringRef("\xff/clusterId");
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-02-15 03:42:47 +08:00
|
|
|
// "\xff/cacheServer/[[UID]] := StorageServerInterface"
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef storageCacheServerKeys(LiteralStringRef("\xff/cacheServer/"), LiteralStringRef("\xff/cacheServer0"));
|
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-01-26 09:52:12 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion;
|
|
|
|
protocolVersion.addObjectSerializerFlag();
|
2022-01-27 10:05:54 +08:00
|
|
|
return ObjectWriter::toValue(ssi, IncludeVersion(protocolVersion));
|
2019-12-07 05:28:44 +08:00
|
|
|
}
|
|
|
|
|
2020-05-20 11:51:02 +08:00
|
|
|
const KeyRangeRef ddStatsRange = KeyRangeRef(LiteralStringRef("\xff\xff/metrics/data_distribution_stats/"),
|
|
|
|
LiteralStringRef("\xff\xff/metrics/data_distribution_stats/\xff\xff"));
|
2020-05-19 01:36:34 +08:00
|
|
|
|
2019-11-13 05:01:29 +08:00
|
|
|
// "\xff/storageCache/[[begin]]" := "[[vector<uint16_t>]]"
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef storageCacheKeys(LiteralStringRef("\xff/storageCache/"), LiteralStringRef("\xff/storageCache0"));
|
2019-11-13 05:01:29 +08:00
|
|
|
const KeyRef storageCachePrefix = storageCacheKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key storageCacheKey(const KeyRef& k) {
|
|
|
|
return k.withPrefix(storageCachePrefix);
|
2019-11-13 05:01:29 +08:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
const Value storageCacheValue(const std::vector<uint16_t>& serverIndices) {
|
2021-03-11 02:06:03 +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(
|
2021-03-11 02:06:03 +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;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
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
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverKeysKey(UID serverID, const KeyRef& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverKeysPrefix);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << serverID;
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(LiteralStringRef("/"));
|
|
|
|
wr.serializeBytes(key);
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverKeysPrefixFor(UID serverID) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverKeysPrefix);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << serverID;
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(LiteralStringRef("/"));
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
UID serverKeysDecodeServer(const KeyRef& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
UID server_id;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(serverKeysPrefix), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
bool serverHasKey(ValueRef storedValue) {
|
2021-09-10 05:15:07 +08:00
|
|
|
return storedValue == serverKeysTrue || storedValue == serverKeysTrueEmptyRange;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-11-13 05:01:29 +08:00
|
|
|
const KeyRef cacheKeysPrefix = LiteralStringRef("\xff\x02/cacheKeys/");
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key cacheKeysKey(uint16_t idx, const KeyRef& key) {
|
2019-11-13 05:01:29 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(cacheKeysPrefix);
|
2019-11-13 05:01:29 +08:00
|
|
|
wr << idx;
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(LiteralStringRef("/"));
|
|
|
|
wr.serializeBytes(key);
|
2019-11-13 05:01:29 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key cacheKeysPrefixFor(uint16_t idx) {
|
2019-11-13 05:01:29 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(cacheKeysPrefix);
|
2019-11-13 05:01:29 +08:00
|
|
|
wr << idx;
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(LiteralStringRef("/"));
|
2019-11-13 05:01:29 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
uint16_t cacheKeysDecodeIndex(const KeyRef& key) {
|
2019-11-13 05:01:29 +08:00
|
|
|
uint16_t idx;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(cacheKeysPrefix), Unversioned());
|
2019-11-13 05:01:29 +08:00
|
|
|
rd >> idx;
|
|
|
|
return idx;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
KeyRef cacheKeysDecodeKey(const KeyRef& key) {
|
|
|
|
return key.substr(cacheKeysPrefix.size() + sizeof(uint16_t) + 1);
|
2019-11-13 05:01:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRef cacheChangeKey = LiteralStringRef("\xff\x02/cacheChangeKey");
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef cacheChangeKeys(LiteralStringRef("\xff\x02/cacheChangeKeys/"),
|
|
|
|
LiteralStringRef("\xff\x02/cacheChangeKeys0"));
|
2019-11-13 05:01:29 +08:00
|
|
|
const KeyRef cacheChangePrefix = cacheChangeKeys.begin;
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key cacheChangeKeyFor(uint16_t idx) {
|
2019-11-13 05:01:29 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(cacheChangePrefix);
|
2019-11-13 05:01:29 +08:00
|
|
|
wr << idx;
|
|
|
|
return wr.toValue();
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
uint16_t cacheChangeKeyDecodeIndex(const KeyRef& key) {
|
2019-11-13 05:01:29 +08:00
|
|
|
uint16_t idx;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(cacheChangePrefix), Unversioned());
|
2019-11-13 05:01:29 +08:00
|
|
|
rd >> idx;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
2021-03-06 03:28:15 +08:00
|
|
|
const KeyRangeRef tssMappingKeys(LiteralStringRef("\xff/tss/"), LiteralStringRef("\xff/tss0"));
|
|
|
|
|
2021-06-08 03:54:24 +08:00
|
|
|
const KeyRangeRef tssQuarantineKeys(LiteralStringRef("\xff/tssQ/"), LiteralStringRef("\xff/tssQ0"));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-06-12 05:20:38 +08:00
|
|
|
const KeyRangeRef tssMismatchKeys(LiteralStringRef("\xff/tssMismatch/"), LiteralStringRef("\xff/tssMismatch0"));
|
|
|
|
|
2022-02-05 07:04:30 +08:00
|
|
|
const KeyRangeRef serverMetadataKeys(LiteralStringRef("\xff/serverMetadata/"),
|
|
|
|
LiteralStringRef("\xff/serverMetadata0"));
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef serverTagKeys(LiteralStringRef("\xff/serverTag/"), LiteralStringRef("\xff/serverTag0"));
|
2021-03-06 03:28:15 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef serverTagPrefix = serverTagKeys.begin;
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef serverTagConflictKeys(LiteralStringRef("\xff/serverTagConflict/"),
|
|
|
|
LiteralStringRef("\xff/serverTagConflict0"));
|
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.
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef serverTagHistoryKeys(LiteralStringRef("\xff/serverTagHistory/"),
|
|
|
|
LiteralStringRef("\xff/serverTagHistory0"));
|
2018-01-29 03:52:54 +08:00
|
|
|
const KeyRef serverTagHistoryPrefix = serverTagHistoryKeys.begin;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverTagKeyFor(UID serverID) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverTagKeys.begin);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverTagHistoryKeyFor(UID serverID) {
|
2018-01-29 03:52:54 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
2018-01-29 03:52:54 +08:00
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return addVersionStampAtEnd(wr.toValue());
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRange serverTagHistoryRangeFor(UID serverID) {
|
2018-01-29 03:52:54 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
2018-01-29 03:52:54 +08:00
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return prefixRange(wr.toValue());
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRange serverTagHistoryRangeBefore(UID serverID, Version version) {
|
2018-01-29 03:52:54 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverTagHistoryKeys.begin);
|
2018-01-29 03:52:54 +08:00
|
|
|
wr << serverID;
|
|
|
|
version = bigEndian64(version);
|
2019-07-10 07:09:51 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Key versionStr = makeString(8);
|
|
|
|
uint8_t* data = mutateString(versionStr);
|
2018-01-29 03:52:54 +08:00
|
|
|
memcpy(data, &version, 8);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
return KeyRangeRef(wr.toValue(), versionStr.withPrefix(wr.toValue()));
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +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
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
UID decodeServerTagKey(KeyRef const& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
UID serverID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(serverTagKeys.begin), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
rd >> serverID;
|
|
|
|
return serverID;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Version decodeServerTagHistoryKey(KeyRef const& key) {
|
2018-01-29 03:52:54 +08:00
|
|
|
Version parsedVersion;
|
2021-03-11 02:06:03 +08:00
|
|
|
memcpy(&parsedVersion, key.substr(key.size() - 10).begin(), sizeof(Version));
|
2018-01-29 03:52:54 +08:00
|
|
|
parsedVersion = bigEndian64(parsedVersion);
|
|
|
|
return parsedVersion;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Tag decodeServerTagValue(ValueRef const& value) {
|
2017-05-26 04:48:44 +08:00
|
|
|
Tag s;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
|
|
|
if (!reader.protocolVersion().hasTagLocality()) {
|
2018-01-21 02:33:13 +08:00
|
|
|
int16_t id;
|
|
|
|
reader >> id;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (id == invalidTagOld) {
|
2018-01-21 02:33:13 +08:00
|
|
|
s = invalidTag;
|
2021-03-11 02:06:03 +08:00
|
|
|
} else if (id == txsTagOld) {
|
2018-01-21 02:33:13 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverTagConflictKeyFor(Tag tag) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverTagConflictKeys.begin);
|
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
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef tagLocalityListKeys(LiteralStringRef("\xff/tagLocalityList/"),
|
|
|
|
LiteralStringRef("\xff/tagLocalityList0"));
|
2017-08-04 07:16:36 +08:00
|
|
|
const KeyRef tagLocalityListPrefix = tagLocalityListKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key tagLocalityListKeyFor(Optional<Value> dcID) {
|
2017-08-04 07:16:36 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(tagLocalityListKeys.begin);
|
2017-08-04 07:16:36 +08:00
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-08-04 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +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
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
Optional<Value> decodeTagLocalityListKey(KeyRef const& key) {
|
2017-08-04 07:16:36 +08:00
|
|
|
Optional<Value> dcID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(tagLocalityListKeys.begin), AssumeVersion(currentProtocolVersion));
|
2017-08-04 07:16:36 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
int8_t decodeTagLocalityListValue(ValueRef const& value) {
|
2017-08-04 07:16:36 +08:00
|
|
|
int8_t s;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2017-08-04 07:16:36 +08:00
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef datacenterReplicasKeys(LiteralStringRef("\xff\x02/datacenterReplicas/"),
|
|
|
|
LiteralStringRef("\xff\x02/datacenterReplicas0"));
|
2018-04-09 12:24:05 +08:00
|
|
|
const KeyRef datacenterReplicasPrefix = datacenterReplicasKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key datacenterReplicasKeyFor(Optional<Value> dcID) {
|
2018-04-09 12:24:05 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(datacenterReplicasKeys.begin);
|
2018-04-09 12:24:05 +08:00
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2018-04-09 12:24:05 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +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
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
Optional<Value> decodeDatacenterReplicasKey(KeyRef const& key) {
|
2018-04-09 12:24:05 +08:00
|
|
|
Optional<Value> dcID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(datacenterReplicasKeys.begin), AssumeVersion(currentProtocolVersion));
|
2018-04-09 12:24:05 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
int decodeDatacenterReplicasValue(ValueRef const& value) {
|
2018-04-09 12:24:05 +08:00
|
|
|
int s;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2018-04-09 12:24:05 +08:00
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-11-12 04:37:53 +08:00
|
|
|
// "\xff\x02/tLogDatacenters/[[datacenterID]]"
|
|
|
|
extern const KeyRangeRef tLogDatacentersKeys;
|
|
|
|
extern const KeyRef tLogDatacentersPrefix;
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key tLogDatacentersKeyFor(Optional<Value> dcID);
|
2018-11-12 04:37:53 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef tLogDatacentersKeys(LiteralStringRef("\xff\x02/tLogDatacenters/"),
|
|
|
|
LiteralStringRef("\xff\x02/tLogDatacenters0"));
|
2018-11-12 04:37:53 +08:00
|
|
|
const KeyRef tLogDatacentersPrefix = tLogDatacentersKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key tLogDatacentersKeyFor(Optional<Value> dcID) {
|
2018-11-12 04:37:53 +08:00
|
|
|
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(tLogDatacentersKeys.begin);
|
2018-11-12 04:37:53 +08:00
|
|
|
wr << dcID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2018-11-12 04:37:53 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
Optional<Value> decodeTLogDatacentersKey(KeyRef const& key) {
|
2018-11-12 04:37:53 +08:00
|
|
|
Optional<Value> dcID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(tLogDatacentersKeys.begin), AssumeVersion(currentProtocolVersion));
|
2018-11-12 04:37:53 +08:00
|
|
|
rd >> dcID;
|
|
|
|
return dcID;
|
|
|
|
}
|
|
|
|
|
2018-06-15 10:36:02 +08:00
|
|
|
const KeyRef primaryDatacenterKey = LiteralStringRef("\xff/primaryDatacenter");
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// serverListKeys.contains(k) iff k.startsWith( serverListKeys.begin ) because '/'+1 == '0'
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef serverListKeys(LiteralStringRef("\xff/serverList/"), LiteralStringRef("\xff/serverList0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef serverListPrefix = serverListKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key serverListKeyFor(UID serverID) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(serverListKeys.begin);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << serverID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Value serverListValue(StorageServerInterface const& server) {
|
2022-03-29 14:52:26 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion;
|
|
|
|
protocolVersion.addObjectSerializerFlag();
|
|
|
|
return ObjectWriter::toValue(server, IncludeVersion(protocolVersion));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2022-03-25 08:25:07 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
UID decodeServerListKey(KeyRef const& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
UID serverID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(serverListKeys.begin), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
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-04-05 09:42:52 +08:00
|
|
|
auto protocolVersion = currentProtocolVersion;
|
|
|
|
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'
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef processClassKeys(LiteralStringRef("\xff/processClass/"), LiteralStringRef("\xff/processClass0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef processClassPrefix = processClassKeys.begin;
|
|
|
|
const KeyRef processClassChangeKey = LiteralStringRef("\xff/processClassChanges");
|
|
|
|
const KeyRef processClassVersionKey = LiteralStringRef("\xff/processClassChangesVersion");
|
|
|
|
const ValueRef processClassVersionValue = LiteralStringRef("1");
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key processClassKeyFor(StringRef processID) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(processClassKeys.begin);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << processID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +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
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Key decodeProcessClassKey(KeyRef const& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
StringRef processID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
UID decodeProcessClassKeyOld(KeyRef const& key) {
|
2017-05-26 04:48:44 +08:00
|
|
|
UID processID;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ProcessClass decodeProcessClassValue(ValueRef const& value) {
|
2017-05-26 04:48:44 +08:00
|
|
|
ProcessClass s;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef configKeys(LiteralStringRef("\xff/conf/"), LiteralStringRef("\xff/conf0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef configKeysPrefix = configKeys.begin;
|
|
|
|
|
2021-05-18 04:22:27 +08:00
|
|
|
const KeyRef perpetualStorageWiggleKey(LiteralStringRef("\xff/conf/perpetual_storage_wiggle"));
|
2021-09-11 06:33:17 +08:00
|
|
|
const KeyRef perpetualStorageWiggleLocalityKey(LiteralStringRef("\xff/conf/perpetual_storage_wiggle_locality"));
|
2022-02-05 07:04:30 +08:00
|
|
|
const KeyRef perpetualStorageWiggleIDPrefix(
|
|
|
|
LiteralStringRef("\xff/storageWiggleID/")); // withSuffix /primary or /remote
|
|
|
|
const KeyRef perpetualStorageWiggleStatsPrefix(
|
|
|
|
LiteralStringRef("\xff/storageWiggleStats/")); // withSuffix /primary or /remote
|
2021-05-18 04:22:27 +08:00
|
|
|
|
2020-11-13 08:27:55 +08:00
|
|
|
const KeyRef triggerDDTeamInfoPrintKey(LiteralStringRef("\xff/triggerDDTeamInfoPrint"));
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef excludedServersKeys(LiteralStringRef("\xff/conf/excluded/"), LiteralStringRef("\xff/conf/excluded0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef excludedServersPrefix = excludedServersKeys.begin;
|
|
|
|
const KeyRef excludedServersVersionKey = LiteralStringRef("\xff/conf/excluded");
|
2021-06-05 06:23:04 +08:00
|
|
|
AddressExclusion decodeExcludedServersKey(KeyRef const& key) {
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(key.startsWith(excludedServersPrefix));
|
2017-05-26 04:48:44 +08:00
|
|
|
// 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
|
2021-03-11 02:06:03 +08:00
|
|
|
// 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
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
return AddressExclusion::parse(key.removePrefix(excludedServersPrefix));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-10 08:04:05 +08:00
|
|
|
const KeyRangeRef excludedLocalityKeys(LiteralStringRef("\xff/conf/excluded_locality/"),
|
|
|
|
LiteralStringRef("\xff/conf/excluded_locality0"));
|
2021-05-19 14:48:04 +08:00
|
|
|
const KeyRef excludedLocalityPrefix = excludedLocalityKeys.begin;
|
2021-06-10 08:04:05 +08:00
|
|
|
const KeyRef excludedLocalityVersionKey = LiteralStringRef("\xff/conf/excluded_locality");
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef failedServersKeys(LiteralStringRef("\xff/conf/failed/"), LiteralStringRef("\xff/conf/failed0"));
|
2019-07-31 02:45:32 +08:00
|
|
|
const KeyRef failedServersPrefix = failedServersKeys.begin;
|
|
|
|
const KeyRef failedServersVersionKey = LiteralStringRef("\xff/conf/failed");
|
2021-06-05 06:23:04 +08:00
|
|
|
AddressExclusion decodeFailedServersKey(KeyRef const& key) {
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(key.startsWith(failedServersPrefix));
|
2019-07-31 02:45:32 +08:00
|
|
|
// 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
|
2021-03-11 02:06:03 +08:00
|
|
|
// 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
|
2019-07-31 02:45:32 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
return AddressExclusion::parse(key.removePrefix(failedServersPrefix));
|
2019-07-31 02:45:32 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
std::string encodeFailedServersKey(AddressExclusion const& addr) {
|
|
|
|
// FIXME: make sure what's persisted here is not affected by innocent changes elsewhere
|
2019-07-31 02:45:32 +08:00
|
|
|
return failedServersPrefix.toString() + addr.toString();
|
|
|
|
}
|
|
|
|
|
2021-06-10 08:04:05 +08:00
|
|
|
const KeyRangeRef failedLocalityKeys(LiteralStringRef("\xff/conf/failed_locality/"),
|
|
|
|
LiteralStringRef("\xff/conf/failed_locality0"));
|
2021-05-19 14:48:04 +08:00
|
|
|
const KeyRef failedLocalityPrefix = failedLocalityKeys.begin;
|
2021-06-10 08:04:05 +08:00
|
|
|
const KeyRef failedLocalityVersionKey = LiteralStringRef("\xff/conf/failed_locality");
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-20 16:43:54 +08:00
|
|
|
// const KeyRangeRef globalConfigKeys( LiteralStringRef("\xff/globalConfig/"), LiteralStringRef("\xff/globalConfig0") );
|
|
|
|
// const KeyRef globalConfigPrefix = globalConfigKeys.begin;
|
2021-02-13 10:55:01 +08:00
|
|
|
|
2021-03-06 03:28:15 +08:00
|
|
|
const KeyRangeRef globalConfigDataKeys(LiteralStringRef("\xff/globalConfig/k/"),
|
|
|
|
LiteralStringRef("\xff/globalConfig/k0"));
|
2021-02-20 16:43:54 +08:00
|
|
|
const KeyRef globalConfigKeysPrefix = globalConfigDataKeys.begin;
|
2021-02-13 10:55:01 +08:00
|
|
|
|
2021-03-06 03:28:15 +08:00
|
|
|
const KeyRangeRef globalConfigHistoryKeys(LiteralStringRef("\xff/globalConfig/h/"),
|
|
|
|
LiteralStringRef("\xff/globalConfig/h0"));
|
2021-02-13 10:55:01 +08:00
|
|
|
const KeyRef globalConfigHistoryPrefix = globalConfigHistoryKeys.begin;
|
|
|
|
|
|
|
|
const KeyRef globalConfigVersionKey = LiteralStringRef("\xff/globalConfig/v");
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef workerListKeys(LiteralStringRef("\xff/worker/"), LiteralStringRef("\xff/worker0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef workerListPrefix = workerListKeys.begin;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const Key workerListKeyFor(StringRef processID) {
|
2017-05-26 04:48:44 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
wr.serializeBytes(workerListKeys.begin);
|
2017-05-26 04:48:44 +08:00
|
|
|
wr << processID;
|
2019-03-29 02:52:50 +08:00
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +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;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(key.removePrefix(workerListKeys.begin), Unversioned());
|
2017-05-26 04:48:44 +08:00
|
|
|
rd >> processID;
|
|
|
|
return processID;
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ProcessData decodeWorkerListValue(ValueRef const& value) {
|
2017-05-26 04:48:44 +08:00
|
|
|
ProcessData s;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
reader >> s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-01-17 11:16:23 +08:00
|
|
|
const KeyRangeRef backupProgressKeys(LiteralStringRef("\xff\x02/backupProgress/"),
|
|
|
|
LiteralStringRef("\xff\x02/backupProgress0"));
|
2019-05-24 07:06:23 +08:00
|
|
|
const KeyRef backupProgressPrefix = backupProgressKeys.begin;
|
2020-01-17 11:16:23 +08:00
|
|
|
const KeyRef backupStartedKey = LiteralStringRef("\xff\x02/backupStarted");
|
2020-04-03 06:28:51 +08:00
|
|
|
extern const KeyRef backupPausedKey = LiteralStringRef("\xff\x02/backupPaused");
|
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());
|
2021-03-11 02:06:03 +08:00
|
|
|
if (value.size() > 0)
|
|
|
|
reader >> ids;
|
2020-01-22 08:57:30 +08:00
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef coordinatorsKey = LiteralStringRef("\xff/coordinators");
|
|
|
|
const KeyRef logsKey = LiteralStringRef("\xff/logs");
|
2017-09-08 08:41:20 +08:00
|
|
|
const KeyRef minRequiredCommitVersionKey = LiteralStringRef("\xff/minRequiredCommitVersion");
|
Add fdbcli command to read/write version epoch (#6480)
* Initialize cluster version at wall-clock time
Previously, new clusters would begin at version 0. After this change,
clusters will initialize at a version matching wall-clock time. Instead
of using the Unix epoch (or Windows epoch), FDB clusters will use a new
epoch, defaulting to January 1, 2010, 01:00:00+00:00. In the future,
this base epoch will be modifiable through fdbcli, allowing
administrators to advance the cluster version.
Basing the version off of time allows different FDB clusters to share
data without running into version issues.
* Send version epoch to master
* Cleanup
* Update fdbserver/storageserver.actor.cpp
Co-authored-by: A.J. Beamon <aj.beamon@snowflake.com>
* Jump directly to expected version if possible
* Fix initial version issue on storage servers
* Add random recovery offset to start version in simulation
* Type fixes
* Disable reference time by default
Enable on a cluster using the fdbcli command `versionepoch add 0`.
* Use correct recoveryTransactionVersion when recovering
* Allow version epoch to be adjusted forwards (to decrease the version)
* Set version epoch in simulation
* Add quiet database check to ensure small version offset
* Fix initial version issue on storage servers
* Disable reference time by default
Enable on a cluster using the fdbcli command `versionepoch add 0`.
* Add fdbcli command to read/write version epoch
* Cause recovery when version epoch is set
* Handle optional version epoch key
* Add ability to clear the version epoch
This causes version advancement to revert to the old methodology whereas
versions attempt to advance by about a million versions per second,
instead of trying to match the clock.
* Update transaction access
* Modify version epoch to use microseconds instead of seconds
* Modify fdbcli version target API
Move commands from `versionepoch` to `targetversion` top level command.
* Add fdbcli tests for
* Temporarily disable targetversion cli tests
* Fix version epoch fetch issue
* Fix Arena issue
* Reduce max version jump in simulation to 1,000,000
* Rework fdbcli API
It now requires two commands to fully switch a cluster to using the
version epoch. First, enable the version epoch with `versionepoch
enable` or `versionepoch set <versionepoch>`. At this point, versions
will be given out at a faster or slower rate in an attempt to reach the
expected version. Then, run `versionepoch commit` to perform a one time
jump to the expected version. This is essentially irreversible.
* Temporarily disable old targetversion tests
* Cleanup
* Move version epoch buggify to sequencer
This will cause some issues with the QuietDatabase check for the version
offset - namely, it won't do anything, since the version epoch is not
being written to the txnStateStore in simulation. This will get fixed in
the future.
Co-authored-by: A.J. Beamon <aj.beamon@snowflake.com>
2022-04-09 03:33:19 +08:00
|
|
|
const KeyRef versionEpochKey = LiteralStringRef("\xff/versionEpoch");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const KeyRef globalKeysPrefix = LiteralStringRef("\xff/globals");
|
|
|
|
const KeyRef lastEpochEndKey = LiteralStringRef("\xff/globals/lastEpochEnd");
|
|
|
|
const KeyRef lastEpochEndPrivateKey = LiteralStringRef("\xff\xff/globals/lastEpochEnd");
|
2019-02-19 06:30:51 +08:00
|
|
|
const KeyRef killStorageKey = LiteralStringRef("\xff/globals/killStorage");
|
|
|
|
const KeyRef killStoragePrivateKey = LiteralStringRef("\xff\xff/globals/killStorage");
|
2018-11-09 07:44:03 +08:00
|
|
|
const KeyRef rebootWhenDurableKey = LiteralStringRef("\xff/globals/rebootWhenDurable");
|
|
|
|
const KeyRef rebootWhenDurablePrivateKey = LiteralStringRef("\xff\xff/globals/rebootWhenDurable");
|
2019-02-19 06:40:30 +08:00
|
|
|
const KeyRef primaryLocalityKey = LiteralStringRef("\xff/globals/primaryLocality");
|
|
|
|
const KeyRef primaryLocalityPrivateKey = LiteralStringRef("\xff\xff/globals/primaryLocality");
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef fastLoggingEnabled = LiteralStringRef("\xff/globals/fastLoggingEnabled");
|
|
|
|
const KeyRef fastLoggingEnabledPrivateKey = LiteralStringRef("\xff\xff/globals/fastLoggingEnabled");
|
|
|
|
|
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
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef moveKeysLockOwnerKey = LiteralStringRef("\xff/moveKeysLock/Owner");
|
|
|
|
const KeyRef moveKeysLockWriteKey = LiteralStringRef("\xff/moveKeysLock/Write");
|
|
|
|
|
|
|
|
const KeyRef dataDistributionModeKey = LiteralStringRef("\xff/dataDistributionMode");
|
2021-03-11 02:06:03 +08:00
|
|
|
const UID dataDistributionModeLock = UID(6345, 3425);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-04-04 06:24:14 +08:00
|
|
|
// Keys to view and control tag throttling
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef tagThrottleKeys =
|
|
|
|
KeyRangeRef(LiteralStringRef("\xff\x02/throttledTags/tag/"), LiteralStringRef("\xff\x02/throttledTags/tag0"));
|
2020-04-04 06:24:14 +08:00
|
|
|
const KeyRef tagThrottleKeysPrefix = tagThrottleKeys.begin;
|
2020-04-24 11:50:40 +08:00
|
|
|
const KeyRef tagThrottleAutoKeysPrefix = LiteralStringRef("\xff\x02/throttledTags/tag/\x01");
|
2020-04-04 06:24:14 +08:00
|
|
|
const KeyRef tagThrottleSignalKey = LiteralStringRef("\xff\x02/throttledTags/signal");
|
|
|
|
const KeyRef tagThrottleAutoEnabledKey = LiteralStringRef("\xff\x02/throttledTags/autoThrottlingEnabled");
|
2020-04-18 02:48:02 +08:00
|
|
|
const KeyRef tagThrottleLimitKey = LiteralStringRef("\xff\x02/throttledTags/manualThrottleLimit");
|
|
|
|
const KeyRef tagThrottleCountKey = LiteralStringRef("\xff\x02/throttledTags/manualThrottleCount");
|
2020-04-04 06:24:14 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
// Client status info prefix
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef fdbClientInfoPrefixRange(LiteralStringRef("\xff\x02/fdbClientInfo/"),
|
|
|
|
LiteralStringRef("\xff\x02/fdbClientInfo0"));
|
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
|
|
|
|
const KeyRef fdbShouldConsistencyCheckBeSuspended = LiteralStringRef("\xff\x02/ConsistencyCheck/Suspend");
|
|
|
|
|
2019-01-19 08:18:34 +08:00
|
|
|
// Request latency measurement key
|
|
|
|
const KeyRef latencyBandConfigKey = LiteralStringRef("\xff\x02/latencyBandConfig");
|
|
|
|
|
2017-09-26 03:40:24 +08:00
|
|
|
// Keyspace to maintain wall clock to version map
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef timeKeeperPrefixRange(LiteralStringRef("\xff\x02/timeKeeper/map/"),
|
|
|
|
LiteralStringRef("\xff\x02/timeKeeper/map0"));
|
2017-09-28 07:31:38 +08:00
|
|
|
const KeyRef timeKeeperVersionKey = LiteralStringRef("\xff\x02/timeKeeper/version");
|
2017-09-29 04:13:24 +08:00
|
|
|
const KeyRef timeKeeperDisableKey = LiteralStringRef("\xff\x02/timeKeeper/disable");
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup Log Mutation constant variables
|
|
|
|
const KeyRef backupEnabledKey = LiteralStringRef("\xff/backupEnabled");
|
|
|
|
const KeyRangeRef backupLogKeys(LiteralStringRef("\xff\x02/blog/"), LiteralStringRef("\xff\x02/blog0"));
|
|
|
|
const KeyRangeRef applyLogKeys(LiteralStringRef("\xff\x02/alog/"), LiteralStringRef("\xff\x02/alog0"));
|
2021-03-11 02:06:03 +08:00
|
|
|
// static_assert( backupLogKeys.begin.size() == backupLogPrefixBytes, "backupLogPrefixBytes incorrect" );
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRef backupVersionKey = LiteralStringRef("\xff/backupDataFormat");
|
|
|
|
const ValueRef backupVersionValue = LiteralStringRef("4");
|
|
|
|
const int backupVersion = 4;
|
|
|
|
|
|
|
|
// Log Range constant variables
|
2021-03-11 02:06:03 +08:00
|
|
|
// \xff/logRanges/[16-byte UID][begin key] := serialize( make_pair([end key], [destination key prefix]),
|
|
|
|
// IncludeVersion() )
|
2017-05-26 04:48:44 +08:00
|
|
|
const KeyRangeRef logRangesRange(LiteralStringRef("\xff/logRanges/"), LiteralStringRef("\xff/logRanges0"));
|
|
|
|
|
|
|
|
// Layer status metadata prefix
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef layerStatusMetaPrefixRange(LiteralStringRef("\xff\x02/status/"),
|
|
|
|
LiteralStringRef("\xff\x02/status0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup agent status root
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef backupStatusPrefixRange(LiteralStringRef("\xff\x02/backupstatus/"),
|
|
|
|
LiteralStringRef("\xff\x02/backupstatus0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Restore configuration constant variables
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef fileRestorePrefixRange(LiteralStringRef("\xff\x02/restore-agent/"),
|
|
|
|
LiteralStringRef("\xff\x02/restore-agent0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Backup Agent configuration constant variables
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef fileBackupPrefixRange(LiteralStringRef("\xff\x02/backup-agent/"),
|
|
|
|
LiteralStringRef("\xff\x02/backup-agent0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// DR Agent configuration constant variables
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef databaseBackupPrefixRange(LiteralStringRef("\xff\x02/db-backup-agent/"),
|
|
|
|
LiteralStringRef("\xff\x02/db-backup-agent0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2018-02-21 05:22:31 +08:00
|
|
|
// \xff\x02/sharedLogRangesConfig/destUidLookup/[keyRange]
|
|
|
|
const KeyRef destUidLookupPrefix = LiteralStringRef("\xff\x02/sharedLogRangesConfig/destUidLookup/");
|
|
|
|
// \xff\x02/sharedLogRangesConfig/backuplatestVersions/[destUid]/[logUid]
|
|
|
|
const KeyRef backupLatestVersionsPrefix = LiteralStringRef("\xff\x02/sharedLogRangesConfig/backupLatestVersions/");
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (logUid) {
|
2017-05-26 04:48:44 +08:00
|
|
|
*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
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
// \xff/logRanges/[16-byte UID][begin key] := serialize( make_pair([end key], [destination key prefix]),
|
|
|
|
// IncludeVersion() )
|
2017-05-26 04:48:44 +08:00
|
|
|
Key logRangesDecodeValue(KeyRef keyValue, Key* destKeyPrefix) {
|
2021-03-11 02:06:03 +08:00
|
|
|
std::pair<KeyRef, KeyRef> endPrefixCombo;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader rd(keyValue, IncludeVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
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
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef applyMutationsEndRange(LiteralStringRef("\xff/applyMutationsEnd/"),
|
|
|
|
LiteralStringRef("\xff/applyMutationsEnd0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsBegin/[16-byte UID] := serialize( beginVersion, Unversioned() )
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef applyMutationsBeginRange(LiteralStringRef("\xff/applyMutationsBegin/"),
|
|
|
|
LiteralStringRef("\xff/applyMutationsBegin0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsAddPrefix/[16-byte UID] := addPrefix
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef applyMutationsAddPrefixRange(LiteralStringRef("\xff/applyMutationsAddPrefix/"),
|
|
|
|
LiteralStringRef("\xff/applyMutationsAddPrefix0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// \xff/applyMutationsRemovePrefix/[16-byte UID] := removePrefix
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef applyMutationsRemovePrefixRange(LiteralStringRef("\xff/applyMutationsRemovePrefix/"),
|
|
|
|
LiteralStringRef("\xff/applyMutationsRemovePrefix0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef applyMutationsKeyVersionMapRange(LiteralStringRef("\xff/applyMutationsKeyVersionMap/"),
|
|
|
|
LiteralStringRef("\xff/applyMutationsKeyVersionMap0"));
|
|
|
|
const KeyRangeRef applyMutationsKeyVersionCountRange(LiteralStringRef("\xff\x02/applyMutationsKeyVersionCount/"),
|
|
|
|
LiteralStringRef("\xff\x02/applyMutationsKeyVersionCount0"));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const KeyRef systemTuplesPrefix = LiteralStringRef("\xff/a/");
|
|
|
|
const KeyRef metricConfChangeKey = LiteralStringRef("\x01TDMetricConfChanges\x00");
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef metricConfKeys(LiteralStringRef("\x01TDMetricConf\x00\x01"),
|
|
|
|
LiteralStringRef("\x01TDMetricConf\x00\x02"));
|
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 ) {
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryWriter wr(Unversioned());
|
|
|
|
wr.serializeBytes( prefix );
|
|
|
|
wr.serializeBytes( metricConfPrefix );
|
|
|
|
wr.serializeBytes( name.type );
|
|
|
|
wr.serializeBytes( LiteralStringRef("\x00\x01") );
|
|
|
|
wr.serializeBytes( name.name );
|
|
|
|
wr.serializeBytes( LiteralStringRef("\x00\x01") );
|
|
|
|
wr.serializeBytes( name.address );
|
|
|
|
wr.serializeBytes( LiteralStringRef("\x00\x01") );
|
|
|
|
wr.serializeBytes( name.id );
|
|
|
|
wr.serializeBytes( LiteralStringRef("\x00\x01") );
|
|
|
|
wr.serializeBytes( key );
|
|
|
|
wr.serializeBytes( LiteralStringRef("\x00") );
|
|
|
|
return wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<MetricNameRef, KeyRef> decodeMetricConfKey( KeyRef const& prefix, KeyRef const& key ) {
|
2021-03-11 02:06:03 +08:00
|
|
|
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) );
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const KeyRef maxUIDKey = LiteralStringRef("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff");
|
|
|
|
|
|
|
|
const KeyRef databaseLockedKey = LiteralStringRef("\xff/dbLocked");
|
2020-08-20 10:52:37 +08:00
|
|
|
const KeyRef databaseLockedKeyEnd = LiteralStringRef("\xff/dbLocked\x00");
|
2019-03-01 09:45:00 +08:00
|
|
|
const KeyRef metadataVersionKey = LiteralStringRef("\xff/metadataVersion");
|
2019-05-16 01:13:38 +08:00
|
|
|
const KeyRef metadataVersionKeyEnd = LiteralStringRef("\xff/metadataVersion\x00");
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRef metadataVersionRequiredValue =
|
|
|
|
LiteralStringRef("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
|
2018-08-22 13:15:45 +08:00
|
|
|
const KeyRef mustContainSystemMutationsKey = LiteralStringRef("\xff/mustContainSystemMutations");
|
2018-10-02 01:43:53 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef monitorConfKeys(LiteralStringRef("\xff\x02/monitorConf/"), LiteralStringRef("\xff\x02/monitorConf0"));
|
2018-10-10 09:47:28 +08:00
|
|
|
|
2018-11-30 02:31:47 +08:00
|
|
|
const KeyRef restoreRequestDoneKey = LiteralStringRef("\xff\x02/restoreRequestDone");
|
2019-01-31 03:18:11 +08:00
|
|
|
|
2019-04-02 08:55:13 +08:00
|
|
|
const KeyRef healthyZoneKey = LiteralStringRef("\xff\x02/healthyZone");
|
2019-07-19 04:18:36 +08:00
|
|
|
const StringRef ignoreSSFailuresZoneString = LiteralStringRef("IgnoreSSFailures");
|
2019-07-10 07:09:51 +08:00
|
|
|
const KeyRef rebalanceDDIgnoreKey = LiteralStringRef("\xff\x02/rebalanceDDIgnored");
|
2019-04-02 08:55:13 +08:00
|
|
|
|
2021-03-11 02:06:03 +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();
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
std::pair<Key, Version> decodeHealthyZoneValue(ValueRef const& value) {
|
2019-04-02 08:55:13 +08:00
|
|
|
Key zoneId;
|
|
|
|
Version version;
|
2021-03-11 02:06:03 +08:00
|
|
|
BinaryReader reader(value, IncludeVersion());
|
2019-04-02 08:55:13 +08:00
|
|
|
reader >> zoneId;
|
|
|
|
reader >> version;
|
|
|
|
return std::make_pair(zoneId, version);
|
|
|
|
}
|
2019-04-26 07:57:39 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
const KeyRangeRef testOnlyTxnStateStorePrefixRange(LiteralStringRef("\xff/TESTONLYtxnStateStore/"),
|
|
|
|
LiteralStringRef("\xff/TESTONLYtxnStateStore0"));
|
2020-09-03 02:13:58 +08:00
|
|
|
|
|
|
|
const KeyRef writeRecoveryKey = LiteralStringRef("\xff/writeRecovery");
|
2020-09-03 03:17:54 +08:00
|
|
|
const ValueRef writeRecoveryKeyTrue = LiteralStringRef("1");
|
2020-09-03 02:13:58 +08:00
|
|
|
const KeyRef snapshotEndVersionKey = LiteralStringRef("\xff/snapshotEndVersion");
|
2021-05-30 02:48:47 +08:00
|
|
|
|
2021-08-14 05:27:15 +08:00
|
|
|
const KeyRangeRef changeFeedKeys(LiteralStringRef("\xff\x02/feed/"), LiteralStringRef("\xff\x02/feed0"));
|
|
|
|
const KeyRef changeFeedPrefix = changeFeedKeys.begin;
|
|
|
|
const KeyRef changeFeedPrivatePrefix = LiteralStringRef("\xff\xff\x02/feed/");
|
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
|
|
|
|
2021-09-03 12:11:44 +08:00
|
|
|
const KeyRangeRef changeFeedDurableKeys(LiteralStringRef("\xff\xff/cf/"), LiteralStringRef("\xff\xff/cf0"));
|
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
|
2021-07-07 03:49:36 +08:00
|
|
|
const KeyRef blobRangeChangeKey = LiteralStringRef("\xff\x02/blobRangeChange");
|
2021-09-01 01:30:43 +08:00
|
|
|
const KeyRangeRef blobRangeKeys(LiteralStringRef("\xff\x02/blobRange/"), LiteralStringRef("\xff\x02/blobRange0"));
|
|
|
|
const KeyRef blobManagerEpochKey = LiteralStringRef("\xff\x02/blobManagerEpoch");
|
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
|
2021-09-01 01:30:43 +08:00
|
|
|
const KeyRangeRef blobGranuleFileKeys(LiteralStringRef("\xff\x02/bgf/"), LiteralStringRef("\xff\x02/bgf0"));
|
|
|
|
const KeyRangeRef blobGranuleMappingKeys(LiteralStringRef("\xff\x02/bgm/"), LiteralStringRef("\xff\x02/bgm0"));
|
|
|
|
const KeyRangeRef blobGranuleLockKeys(LiteralStringRef("\xff\x02/bgl/"), LiteralStringRef("\xff\x02/bgl0"));
|
2021-09-04 04:13:26 +08:00
|
|
|
const KeyRangeRef blobGranuleSplitKeys(LiteralStringRef("\xff\x02/bgs/"), LiteralStringRef("\xff\x02/bgs0"));
|
2021-09-23 01:46:20 +08:00
|
|
|
const KeyRangeRef blobGranuleHistoryKeys(LiteralStringRef("\xff\x02/bgh/"), LiteralStringRef("\xff\x02/bgh0"));
|
2022-04-09 05:15:25 +08:00
|
|
|
const KeyRangeRef blobGranulePurgeKeys(LiteralStringRef("\xff\x02/bgp/"), LiteralStringRef("\xff\x02/bgp0"));
|
2022-02-23 04:00:09 +08:00
|
|
|
const KeyRangeRef blobGranuleVersionKeys(LiteralStringRef("\xff\x02/bgv/"), LiteralStringRef("\xff\x02/bgv0"));
|
2022-04-09 05:15:25 +08:00
|
|
|
const KeyRef blobGranulePurgeChangeKey = LiteralStringRef("\xff\x02/bgpChange");
|
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-03-29 03:48:12 +08:00
|
|
|
const Value blobGranuleFileValueFor(StringRef const& filename, int64_t offset, int64_t length, int64_t fullFileLength) {
|
2021-10-09 06:35:36 +08:00
|
|
|
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
|
|
|
|
wr << filename;
|
|
|
|
wr << offset;
|
|
|
|
wr << length;
|
2022-03-29 03:48:12 +08:00
|
|
|
wr << fullFileLength;
|
2021-10-09 06:35:36 +08:00
|
|
|
return wr.toValue();
|
|
|
|
}
|
|
|
|
|
2022-03-29 03:48:12 +08:00
|
|
|
std::tuple<Standalone<StringRef>, int64_t, int64_t, int64_t> 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;
|
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;
|
|
|
|
return std::tuple(filename, offset, length, fullFileLength);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
return historyValue;
|
2021-08-28 05:33:07 +08:00
|
|
|
}
|
|
|
|
|
2021-09-01 01:30:43 +08:00
|
|
|
const KeyRangeRef blobWorkerListKeys(LiteralStringRef("\xff\x02/bwList/"), LiteralStringRef("\xff\x02/bwList0"));
|
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
|
|
|
|
2022-02-19 13:22:31 +08:00
|
|
|
Value encodeTenantEntry(TenantMapEntry const& tenantEntry) {
|
|
|
|
return ObjectWriter::toValue(tenantEntry, IncludeVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
TenantMapEntry decodeTenantEntry(ValueRef const& value) {
|
|
|
|
TenantMapEntry entry;
|
|
|
|
ObjectReader reader(value.begin(), IncludeVersion());
|
|
|
|
reader.deserialize(entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyRangeRef tenantMapKeys("\xff/tenantMap/"_sr, "\xff/tenantMap0"_sr);
|
|
|
|
const KeyRef tenantMapPrefix = tenantMapKeys.begin;
|
|
|
|
const KeyRef tenantMapPrivatePrefix = "\xff\xff/tenantMap/"_sr;
|
2022-02-20 07:09:55 +08:00
|
|
|
const KeyRef tenantLastIdKey = "\xff/tenantLastId/"_sr;
|
|
|
|
const KeyRef tenantDataPrefixKey = "\xff/tenantDataPrefix"_sr;
|
2022-02-19 13:22:31 +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
|
|
|
}
|