foundationdb/fdbclient/SystemData.cpp

1480 lines
56 KiB
C++
Raw Normal View History

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
*
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
*
2017-05-26 04:48:44 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
*
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.
*/
#include "fdbclient/SystemData.h"
2020-02-25 09:26:20 +08:00
#include "fdbclient/FDBTypes.h"
#include "fdbclient/NativeAPI.actor.h"
#include "fdbclient/StorageServerInterface.h"
#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);
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");
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)
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;
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
const Key keyServersKey(const KeyRef& k) {
return k.withPrefix(keyServersPrefix);
2017-05-26 04:48:44 +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) {
if (!CLIENT_KNOBS->TAG_ENCODE_KEY_SERVERS) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValue()));
wr << src << dest;
return wr.toValue();
}
std::vector<Tag> srcTag;
std::vector<Tag> destTag;
bool foundOldLocality = false;
2021-03-04 01:18:03 +08:00
for (const KeyValueRef& kv : result) {
UID uid = decodeServerTagKey(kv.key);
if (std::find(src.begin(), src.end(), uid) != src.end()) {
srcTag.push_back(decodeServerTagValue(kv.value));
if (srcTag.back().locality == tagLocalityUpgraded) {
foundOldLocality = true;
break;
}
}
if (std::find(dest.begin(), dest.end(), uid) != dest.end()) {
destTag.push_back(decodeServerTagValue(kv.value));
if (destTag.back().locality == tagLocalityUpgraded) {
foundOldLocality = true;
break;
}
}
}
if (foundOldLocality || src.size() != srcTag.size() || dest.size() != destTag.size()) {
ASSERT_WE_THINK(foundOldLocality);
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValue()));
wr << src << dest;
return wr.toValue();
}
return keyServersValue(srcTag, destTag);
}
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
BinaryWriter wr(IncludeVersion(ProtocolVersion::withKeyServerValueV2()));
wr << srcTag << destTag;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
2021-05-04 04:14:16 +08:00
void decodeKeyServersValue(RangeResult result,
const ValueRef& value,
std::vector<UID>& src,
std::vector<UID>& dest,
bool missingIsError) {
if (value.size() == 0) {
2017-05-26 04:48:44 +08:00
src.clear();
dest.clear();
return;
}
BinaryReader rd(value, IncludeVersion());
if (!rd.protocolVersion().hasKeyServerValueV2()) {
rd >> src >> dest;
return;
}
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) {
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
}
std::sort(src.begin(), src.end());
std::sort(dest.begin(), dest.end());
if (missingIsError && (src.size() != srcTag.size() || dest.size() != destTag.size())) {
TraceEvent(SevError, "AttemptedToDecodeMissingTag").log();
2021-03-04 01:18:03 +08:00
for (const KeyValueRef& kv : result) {
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
}
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;
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
}
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"));
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"));
const KeyRef clusterIdKey = LiteralStringRef("\xff/clusterId");
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;
}
// "\xff/cacheServer/[[UID]] := StorageServerInterface"
const KeyRangeRef storageCacheServerKeys(LiteralStringRef("\xff/cacheServer/"), LiteralStringRef("\xff/cacheServer0"));
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) {
auto protocolVersion = currentProtocolVersion;
protocolVersion.addObjectSerializerFlag();
2022-01-27 10:05:54 +08:00
return ObjectWriter::toValue(ssi, IncludeVersion(protocolVersion));
}
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>]]"
const KeyRangeRef storageCacheKeys(LiteralStringRef("\xff/storageCache/"), LiteralStringRef("\xff/storageCache0"));
2019-11-13 05:01:29 +08:00
const KeyRef storageCachePrefix = storageCacheKeys.begin;
const Key storageCacheKey(const KeyRef& k) {
return k.withPrefix(storageCachePrefix);
2019-11-13 05:01:29 +08:00
}
const Value storageCacheValue(const std::vector<uint16_t>& serverIndices) {
BinaryWriter wr((IncludeVersion(ProtocolVersion::withStorageCacheValue())));
2019-11-13 05:01:29 +08:00
wr << serverIndices;
return wr.toValue();
}
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;
}
}
const Value logsValue(const std::vector<std::pair<UID, NetworkAddress>>& logs,
const std::vector<std::pair<UID, NetworkAddress>>& oldLogs) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withLogsValue()));
2017-05-26 04:48:44 +08:00
wr << logs;
wr << oldLogs;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
std::pair<std::vector<std::pair<UID, NetworkAddress>>, std::vector<std::pair<UID, NetworkAddress>>> decodeLogsValue(
const ValueRef& value) {
std::vector<std::pair<UID, NetworkAddress>> logs;
std::vector<std::pair<UID, NetworkAddress>> oldLogs;
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
const Key serverKeysKey(UID serverID, const KeyRef& key) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverKeysPrefix);
2017-05-26 04:48:44 +08:00
wr << serverID;
wr.serializeBytes(LiteralStringRef("/"));
wr.serializeBytes(key);
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const Key serverKeysPrefixFor(UID serverID) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverKeysPrefix);
2017-05-26 04:48:44 +08:00
wr << serverID;
wr.serializeBytes(LiteralStringRef("/"));
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
UID serverKeysDecodeServer(const KeyRef& key) {
2017-05-26 04:48:44 +08:00
UID server_id;
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
}
bool serverHasKey(ValueRef storedValue) {
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/");
const Key cacheKeysKey(uint16_t idx, const KeyRef& key) {
2019-11-13 05:01:29 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(cacheKeysPrefix);
2019-11-13 05:01:29 +08:00
wr << idx;
wr.serializeBytes(LiteralStringRef("/"));
wr.serializeBytes(key);
2019-11-13 05:01:29 +08:00
return wr.toValue();
}
const Key cacheKeysPrefixFor(uint16_t idx) {
2019-11-13 05:01:29 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(cacheKeysPrefix);
2019-11-13 05:01:29 +08:00
wr << idx;
wr.serializeBytes(LiteralStringRef("/"));
2019-11-13 05:01:29 +08:00
return wr.toValue();
}
uint16_t cacheKeysDecodeIndex(const KeyRef& key) {
2019-11-13 05:01:29 +08:00
uint16_t idx;
BinaryReader rd(key.removePrefix(cacheKeysPrefix), Unversioned());
2019-11-13 05:01:29 +08:00
rd >> idx;
return idx;
}
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");
const KeyRangeRef cacheChangeKeys(LiteralStringRef("\xff\x02/cacheChangeKeys/"),
LiteralStringRef("\xff\x02/cacheChangeKeys0"));
2019-11-13 05:01:29 +08:00
const KeyRef cacheChangePrefix = cacheChangeKeys.begin;
const Key cacheChangeKeyFor(uint16_t idx) {
2019-11-13 05:01:29 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(cacheChangePrefix);
2019-11-13 05:01:29 +08:00
wr << idx;
return wr.toValue();
}
uint16_t cacheChangeKeyDecodeIndex(const KeyRef& key) {
2019-11-13 05:01:29 +08:00
uint16_t idx;
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"));
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"));
const KeyRangeRef serverMetadataKeys(LiteralStringRef("\xff/serverMetadata/"),
LiteralStringRef("\xff/serverMetadata0"));
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;
const KeyRangeRef serverTagConflictKeys(LiteralStringRef("\xff/serverTagConflict/"),
LiteralStringRef("\xff/serverTagConflict0"));
2017-05-26 04:48:44 +08:00
const KeyRef serverTagConflictPrefix = serverTagConflictKeys.begin;
// 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.
const KeyRangeRef serverTagHistoryKeys(LiteralStringRef("\xff/serverTagHistory/"),
LiteralStringRef("\xff/serverTagHistory0"));
const KeyRef serverTagHistoryPrefix = serverTagHistoryKeys.begin;
2017-05-26 04:48:44 +08:00
const Key serverTagKeyFor(UID serverID) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverTagKeys.begin);
2017-05-26 04:48:44 +08:00
wr << serverID;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const Key serverTagHistoryKeyFor(UID serverID) {
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverTagHistoryKeys.begin);
wr << serverID;
return addVersionStampAtEnd(wr.toValue());
}
const KeyRange serverTagHistoryRangeFor(UID serverID) {
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverTagHistoryKeys.begin);
wr << serverID;
return prefixRange(wr.toValue());
}
const KeyRange serverTagHistoryRangeBefore(UID serverID, Version version) {
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverTagHistoryKeys.begin);
wr << serverID;
version = bigEndian64(version);
Key versionStr = makeString(8);
uint8_t* data = mutateString(versionStr);
memcpy(data, &version, 8);
return KeyRangeRef(wr.toValue(), versionStr.withPrefix(wr.toValue()));
}
const Value serverTagValue(Tag tag) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withServerTagValue()));
2017-05-26 04:48:44 +08:00
wr << tag;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
UID decodeServerTagKey(KeyRef const& key) {
2017-05-26 04:48:44 +08:00
UID serverID;
BinaryReader rd(key.removePrefix(serverTagKeys.begin), Unversioned());
2017-05-26 04:48:44 +08:00
rd >> serverID;
return serverID;
}
Version decodeServerTagHistoryKey(KeyRef const& key) {
Version parsedVersion;
memcpy(&parsedVersion, key.substr(key.size() - 10).begin(), sizeof(Version));
parsedVersion = bigEndian64(parsedVersion);
return parsedVersion;
}
Tag decodeServerTagValue(ValueRef const& value) {
2017-05-26 04:48:44 +08:00
Tag s;
BinaryReader reader(value, IncludeVersion());
if (!reader.protocolVersion().hasTagLocality()) {
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) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverTagConflictKeys.begin);
2017-05-26 04:48:44 +08:00
wr << tag;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const KeyRangeRef tagLocalityListKeys(LiteralStringRef("\xff/tagLocalityList/"),
LiteralStringRef("\xff/tagLocalityList0"));
const KeyRef tagLocalityListPrefix = tagLocalityListKeys.begin;
const Key tagLocalityListKeyFor(Optional<Value> dcID) {
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
wr.serializeBytes(tagLocalityListKeys.begin);
wr << dcID;
return wr.toValue();
}
const Value tagLocalityListValue(int8_t const& tagLocality) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withTagLocalityListValue()));
wr << tagLocality;
return wr.toValue();
}
Optional<Value> decodeTagLocalityListKey(KeyRef const& key) {
Optional<Value> dcID;
BinaryReader rd(key.removePrefix(tagLocalityListKeys.begin), AssumeVersion(currentProtocolVersion));
rd >> dcID;
return dcID;
}
int8_t decodeTagLocalityListValue(ValueRef const& value) {
int8_t s;
BinaryReader reader(value, IncludeVersion());
reader >> s;
return s;
}
const KeyRangeRef datacenterReplicasKeys(LiteralStringRef("\xff\x02/datacenterReplicas/"),
LiteralStringRef("\xff\x02/datacenterReplicas0"));
const KeyRef datacenterReplicasPrefix = datacenterReplicasKeys.begin;
const Key datacenterReplicasKeyFor(Optional<Value> dcID) {
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
wr.serializeBytes(datacenterReplicasKeys.begin);
wr << dcID;
return wr.toValue();
}
const Value datacenterReplicasValue(int const& replicas) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withDatacenterReplicasValue()));
wr << replicas;
return wr.toValue();
}
Optional<Value> decodeDatacenterReplicasKey(KeyRef const& key) {
Optional<Value> dcID;
BinaryReader rd(key.removePrefix(datacenterReplicasKeys.begin), AssumeVersion(currentProtocolVersion));
rd >> dcID;
return dcID;
}
int decodeDatacenterReplicasValue(ValueRef const& value) {
int s;
BinaryReader reader(value, IncludeVersion());
reader >> s;
return s;
}
// "\xff\x02/tLogDatacenters/[[datacenterID]]"
extern const KeyRangeRef tLogDatacentersKeys;
extern const KeyRef tLogDatacentersPrefix;
const Key tLogDatacentersKeyFor(Optional<Value> dcID);
const KeyRangeRef tLogDatacentersKeys(LiteralStringRef("\xff\x02/tLogDatacenters/"),
LiteralStringRef("\xff\x02/tLogDatacenters0"));
const KeyRef tLogDatacentersPrefix = tLogDatacentersKeys.begin;
const Key tLogDatacentersKeyFor(Optional<Value> dcID) {
BinaryWriter wr(AssumeVersion(currentProtocolVersion));
wr.serializeBytes(tLogDatacentersKeys.begin);
wr << dcID;
return wr.toValue();
}
Optional<Value> decodeTLogDatacentersKey(KeyRef const& key) {
Optional<Value> dcID;
BinaryReader rd(key.removePrefix(tLogDatacentersKeys.begin), AssumeVersion(currentProtocolVersion));
rd >> dcID;
return dcID;
}
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'
const KeyRangeRef serverListKeys(LiteralStringRef("\xff/serverList/"), LiteralStringRef("\xff/serverList0"));
2017-05-26 04:48:44 +08:00
const KeyRef serverListPrefix = serverListKeys.begin;
const Key serverListKeyFor(UID serverID) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(serverListKeys.begin);
2017-05-26 04:48:44 +08:00
wr << serverID;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const Value serverListValue(StorageServerInterface const& server) {
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
UID decodeServerListKey(KeyRef const& key) {
2017-05-26 04:48:44 +08:00
UID serverID;
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
}
Value swVersionValue(SWVersion const& swversion) {
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;
}
2017-05-26 04:48:44 +08:00
// processClassKeys.contains(k) iff k.startsWith( processClassKeys.begin ) because '/'+1 == '0'
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");
const Key processClassKeyFor(StringRef processID) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(processClassKeys.begin);
2017-05-26 04:48:44 +08:00
wr << processID;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const Value processClassValue(ProcessClass const& processClass) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withProcessClassValue()));
2017-05-26 04:48:44 +08:00
wr << processClass;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
Key decodeProcessClassKey(KeyRef const& key) {
2017-05-26 04:48:44 +08:00
StringRef processID;
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
2017-05-26 04:48:44 +08:00
rd >> processID;
return processID;
}
UID decodeProcessClassKeyOld(KeyRef const& key) {
2017-05-26 04:48:44 +08:00
UID processID;
BinaryReader rd(key.removePrefix(processClassKeys.begin), Unversioned());
2017-05-26 04:48:44 +08:00
rd >> processID;
return processID;
}
ProcessClass decodeProcessClassValue(ValueRef const& value) {
2017-05-26 04:48:44 +08:00
ProcessClass s;
BinaryReader reader(value, IncludeVersion());
2017-05-26 04:48:44 +08:00
reader >> s;
return s;
}
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"));
const KeyRef perpetualStorageWiggleLocalityKey(LiteralStringRef("\xff/conf/perpetual_storage_wiggle_locality"));
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
const KeyRef triggerDDTeamInfoPrintKey(LiteralStringRef("\xff/triggerDDTeamInfoPrint"));
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");
AddressExclusion decodeExcludedServersKey(KeyRef const& key) {
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
// 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
return AddressExclusion::parse(key.removePrefix(excludedServersPrefix));
2017-05-26 04:48:44 +08:00
}
std::string encodeExcludedServersKey(AddressExclusion const& addr) {
// FIXME: make sure what's persisted here is not affected by innocent changes elsewhere
return excludedServersPrefix.toString() + addr.toString();
2017-05-26 04:48:44 +08:00
}
const KeyRangeRef excludedLocalityKeys(LiteralStringRef("\xff/conf/excluded_locality/"),
LiteralStringRef("\xff/conf/excluded_locality0"));
const KeyRef excludedLocalityPrefix = excludedLocalityKeys.begin;
const KeyRef excludedLocalityVersionKey = LiteralStringRef("\xff/conf/excluded_locality");
std::string decodeExcludedLocalityKey(KeyRef const& key) {
ASSERT(key.startsWith(excludedLocalityPrefix));
return key.removePrefix(excludedLocalityPrefix).toString();
}
std::string encodeExcludedLocalityKey(std::string const& locality) {
return excludedLocalityPrefix.toString() + locality;
}
const KeyRangeRef failedServersKeys(LiteralStringRef("\xff/conf/failed/"), LiteralStringRef("\xff/conf/failed0"));
const KeyRef failedServersPrefix = failedServersKeys.begin;
const KeyRef failedServersVersionKey = LiteralStringRef("\xff/conf/failed");
AddressExclusion decodeFailedServersKey(KeyRef const& key) {
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();
}
const KeyRangeRef failedLocalityKeys(LiteralStringRef("\xff/conf/failed_locality/"),
LiteralStringRef("\xff/conf/failed_locality0"));
const KeyRef failedLocalityPrefix = failedLocalityKeys.begin;
const KeyRef failedLocalityVersionKey = LiteralStringRef("\xff/conf/failed_locality");
std::string decodeFailedLocalityKey(KeyRef const& key) {
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-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-03-06 03:28:15 +08:00
const KeyRangeRef globalConfigHistoryKeys(LiteralStringRef("\xff/globalConfig/h/"),
LiteralStringRef("\xff/globalConfig/h0"));
const KeyRef globalConfigHistoryPrefix = globalConfigHistoryKeys.begin;
const KeyRef globalConfigVersionKey = LiteralStringRef("\xff/globalConfig/v");
const KeyRangeRef workerListKeys(LiteralStringRef("\xff/worker/"), LiteralStringRef("\xff/worker0"));
2017-05-26 04:48:44 +08:00
const KeyRef workerListPrefix = workerListKeys.begin;
const Key workerListKeyFor(StringRef processID) {
2017-05-26 04:48:44 +08:00
BinaryWriter wr(Unversioned());
wr.serializeBytes(workerListKeys.begin);
2017-05-26 04:48:44 +08:00
wr << processID;
return wr.toValue();
2017-05-26 04:48:44 +08:00
}
const Value workerListValue(ProcessData const& processData) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withWorkerListValue()));
2017-05-26 04:48:44 +08:00
wr << processData;
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());
2017-05-26 04:48:44 +08:00
rd >> processID;
return processID;
}
ProcessData decodeWorkerListValue(ValueRef const& value) {
2017-05-26 04:48:44 +08:00
ProcessData s;
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"));
const KeyRef backupProgressPrefix = backupProgressKeys.begin;
2020-01-17 11:16:23 +08:00
const KeyRef backupStartedKey = LiteralStringRef("\xff\x02/backupStarted");
extern const KeyRef backupPausedKey = LiteralStringRef("\xff\x02/backupPaused");
const Key backupProgressKeyFor(UID workerID) {
BinaryWriter wr(Unversioned());
wr.serializeBytes(backupProgressPrefix);
wr << workerID;
return wr.toValue();
}
const Value backupProgressValue(const WorkerBackupStatus& status) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBackupProgressValue()));
wr << status;
return wr.toValue();
}
UID decodeBackupProgressKey(const KeyRef& key) {
UID serverID;
BinaryReader rd(key.removePrefix(backupProgressPrefix), Unversioned());
rd >> serverID;
return serverID;
}
WorkerBackupStatus decodeBackupProgressValue(const ValueRef& value) {
WorkerBackupStatus status;
BinaryReader reader(value, IncludeVersion());
reader >> status;
return status;
}
Value encodeBackupStartedValue(const std::vector<std::pair<UID, Version>>& ids) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBackupStartValue()));
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;
}
2017-05-26 04:48:44 +08:00
const KeyRef coordinatorsKey = LiteralStringRef("\xff/coordinators");
const KeyRef logsKey = LiteralStringRef("\xff/logs");
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");
const KeyRef killStorageKey = LiteralStringRef("\xff/globals/killStorage");
const KeyRef killStoragePrivateKey = LiteralStringRef("\xff\xff/globals/killStorage");
const KeyRef rebootWhenDurableKey = LiteralStringRef("\xff/globals/rebootWhenDurable");
const KeyRef rebootWhenDurablePrivateKey = LiteralStringRef("\xff\xff/globals/rebootWhenDurable");
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");
// 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");
const UID dataDistributionModeLock = UID(6345, 3425);
2017-05-26 04:48:44 +08:00
// Keys to view and control tag throttling
const KeyRangeRef tagThrottleKeys =
KeyRangeRef(LiteralStringRef("\xff\x02/throttledTags/tag/"), LiteralStringRef("\xff\x02/throttledTags/tag0"));
const KeyRef tagThrottleKeysPrefix = tagThrottleKeys.begin;
const KeyRef tagThrottleAutoKeysPrefix = LiteralStringRef("\xff\x02/throttledTags/tag/\x01");
const KeyRef tagThrottleSignalKey = LiteralStringRef("\xff\x02/throttledTags/signal");
const KeyRef tagThrottleAutoEnabledKey = LiteralStringRef("\xff\x02/throttledTags/autoThrottlingEnabled");
const KeyRef tagThrottleLimitKey = LiteralStringRef("\xff\x02/throttledTags/manualThrottleLimit");
const KeyRef tagThrottleCountKey = LiteralStringRef("\xff\x02/throttledTags/manualThrottleCount");
2017-05-26 04:48:44 +08:00
// Client status info prefix
const KeyRangeRef fdbClientInfoPrefixRange(LiteralStringRef("\xff\x02/fdbClientInfo/"),
LiteralStringRef("\xff\x02/fdbClientInfo0"));
// See remaining fields in GlobalConfig.actor.h
2017-05-26 04:48:44 +08:00
// ConsistencyCheck settings
const KeyRef fdbShouldConsistencyCheckBeSuspended = LiteralStringRef("\xff\x02/ConsistencyCheck/Suspend");
// Request latency measurement key
const KeyRef latencyBandConfigKey = LiteralStringRef("\xff\x02/latencyBandConfig");
// Keyspace to maintain wall clock to version map
const KeyRangeRef timeKeeperPrefixRange(LiteralStringRef("\xff\x02/timeKeeper/map/"),
LiteralStringRef("\xff\x02/timeKeeper/map0"));
const KeyRef timeKeeperVersionKey = LiteralStringRef("\xff\x02/timeKeeper/version");
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"));
// 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
// \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
const KeyRangeRef layerStatusMetaPrefixRange(LiteralStringRef("\xff\x02/status/"),
LiteralStringRef("\xff\x02/status0"));
2017-05-26 04:48:44 +08:00
// Backup agent status root
const KeyRangeRef backupStatusPrefixRange(LiteralStringRef("\xff\x02/backupstatus/"),
LiteralStringRef("\xff\x02/backupstatus0"));
2017-05-26 04:48:44 +08:00
// Restore configuration constant variables
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
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
const KeyRangeRef databaseBackupPrefixRange(LiteralStringRef("\xff\x02/db-backup-agent/"),
LiteralStringRef("\xff\x02/db-backup-agent0"));
2017-05-26 04:48:44 +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)) {
TraceEvent(SevError, "InvalidDecodeKey").detail("Key", key);
2017-05-26 04:48:44 +08:00
ASSERT(false);
}
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));
}
// Returns the encoded key value comprised of the end key and destination path
Key logRangesEncodeValue(KeyRef keyEnd, KeyRef destPath) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withLogRangeEncodeValue()));
wr << std::make_pair(keyEnd, destPath);
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() )
2017-05-26 04:48:44 +08:00
Key logRangesDecodeValue(KeyRef keyValue, Key* destKeyPrefix) {
std::pair<KeyRef, KeyRef> endPrefixCombo;
2017-05-26 04:48:44 +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;
return bw.toValue();
2017-05-26 04:48:44 +08:00
}
// Apply mutations constant variables
// \xff/applyMutationsEnd/[16-byte UID] := serialize( endVersion, Unversioned() )
// This indicates what is the highest version the mutation log can be applied
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() )
const KeyRangeRef applyMutationsBeginRange(LiteralStringRef("\xff/applyMutationsBegin/"),
LiteralStringRef("\xff/applyMutationsBegin0"));
2017-05-26 04:48:44 +08:00
// \xff/applyMutationsAddPrefix/[16-byte UID] := addPrefix
const KeyRangeRef applyMutationsAddPrefixRange(LiteralStringRef("\xff/applyMutationsAddPrefix/"),
LiteralStringRef("\xff/applyMutationsAddPrefix0"));
2017-05-26 04:48:44 +08:00
// \xff/applyMutationsRemovePrefix/[16-byte UID] := removePrefix
const KeyRangeRef applyMutationsRemovePrefixRange(LiteralStringRef("\xff/applyMutationsRemovePrefix/"),
LiteralStringRef("\xff/applyMutationsRemovePrefix0"));
2017-05-26 04:48:44 +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");
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 ) {
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 ) {
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");
const KeyRef databaseLockedKeyEnd = LiteralStringRef("\xff/dbLocked\x00");
const KeyRef metadataVersionKey = LiteralStringRef("\xff/metadataVersion");
const KeyRef metadataVersionKeyEnd = LiteralStringRef("\xff/metadataVersion\x00");
const KeyRef metadataVersionRequiredValue =
LiteralStringRef("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
const KeyRef mustContainSystemMutationsKey = LiteralStringRef("\xff/mustContainSystemMutations");
const KeyRangeRef monitorConfKeys(LiteralStringRef("\xff\x02/monitorConf/"), LiteralStringRef("\xff\x02/monitorConf0"));
const KeyRef restoreRequestDoneKey = LiteralStringRef("\xff\x02/restoreRequestDone");
const KeyRef healthyZoneKey = LiteralStringRef("\xff\x02/healthyZone");
const StringRef ignoreSSFailuresZoneString = LiteralStringRef("IgnoreSSFailures");
const KeyRef rebalanceDDIgnoreKey = LiteralStringRef("\xff\x02/rebalanceDDIgnored");
const Value healthyZoneValue(StringRef const& zoneId, Version version) {
2020-05-23 08:19:46 +08:00
BinaryWriter wr(IncludeVersion(ProtocolVersion::withHealthyZoneValue()));
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);
}
const KeyRangeRef testOnlyTxnStateStorePrefixRange(LiteralStringRef("\xff/TESTONLYtxnStateStore/"),
LiteralStringRef("\xff/TESTONLYtxnStateStore0"));
2020-09-03 02:13:58 +08:00
const KeyRef writeRecoveryKey = LiteralStringRef("\xff/writeRecovery");
const ValueRef writeRecoveryKeyTrue = LiteralStringRef("1");
2020-09-03 02:13:58 +08:00
const KeyRef snapshotEndVersionKey = LiteralStringRef("\xff/snapshotEndVersion");
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) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withChangeFeed()));
2021-03-05 11:14:54 +08:00
wr << range;
wr << popVersion;
2021-10-20 04:56:52 +08:00
wr << status;
2021-03-05 11:14:54 +08:00
return wr.toValue();
}
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;
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;
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
}
const KeyRangeRef changeFeedDurableKeys(LiteralStringRef("\xff\xff/cf/"), LiteralStringRef("\xff\xff/cf0"));
const KeyRef changeFeedDurablePrefix = changeFeedDurableKeys.begin;
const Value changeFeedDurableKey(Key const& feed, Version version) {
BinaryWriter wr(AssumeVersion(ProtocolVersion::withChangeFeed()));
wr.serializeBytes(changeFeedDurablePrefix);
wr << feed;
wr << bigEndian64(version);
return wr.toValue();
}
std::pair<Key, Version> decodeChangeFeedDurableKey(ValueRef const& key) {
Key feed;
Version version;
BinaryReader reader(key.removePrefix(changeFeedDurablePrefix), AssumeVersion(ProtocolVersion::withChangeFeed()));
reader >> feed;
reader >> version;
return std::make_pair(feed, bigEndian64(version));
}
const Value changeFeedDurableValue(Standalone<VectorRef<MutationRef>> const& mutations, Version knownCommittedVersion) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withChangeFeed()));
wr << mutations;
wr << knownCommittedVersion;
return wr.toValue();
}
std::pair<Standalone<VectorRef<MutationRef>>, Version> decodeChangeFeedDurableValue(ValueRef const& value) {
Standalone<VectorRef<MutationRef>> mutations;
Version knownCommittedVersion;
BinaryReader reader(value, IncludeVersion());
reader >> mutations;
reader >> knownCommittedVersion;
return std::make_pair(mutations, knownCommittedVersion);
}
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-07-07 03:49:36 +08:00
// key to watch for changes in active blob ranges + KeyRangeMap of active blob ranges
// 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");
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
const Value blobManagerEpochValueFor(int64_t epoch) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
wr << epoch;
return wr.toValue();
}
int64_t decodeBlobManagerEpochValue(ValueRef const& value) {
int64_t epoch;
BinaryReader reader(value, IncludeVersion());
reader >> epoch;
return epoch;
}
// blob granule data
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"));
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"));
Blob integration (#6808) * Fixing leaked stream with explicit notify failed before destructor * better logic to prevent races in change feed fetching * Found new race that makes assert incorrect * handle server overloaded in initial read from fdb * Handling more blob error types in granule retry * Fixing rollback metadata problem, added better debugging * Fixing version race when fetching change feed metadata * Better racing split request handling * fixing assert * Handle change feed popped check in the blob worker * fix: do not use a RYW transaction for a versionstamp because of randomize API version (#6768) * more merge conflict issues * Change feed destroy fixes * Fixing change feed destroy and move race * Check error condition in BG file req * Using relative endpoints for blob worker interface * Fixing bug in previous fix * More destroy and move race fixes * Don't update empty version on destroy in case it gets rolled back. moved() and removing will take care of ensuring it is not read * Bug fix (#6796) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * Fixing durability issue with moving and destroying change feeds * Adding fix for not fully deleting files for a granule that child granules need to re-snapshot * More destroy and move races * Fixing change feed destroy and pop races * Renaming bg prune to purge, and adding a C api and unit test for it * more cleanup * review comments * Observability for granule purging * better handling for change feed not registered * Fixed purging bugs (#6815) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * fixed a few purging bugs Co-authored-by: Evan Tschannen <evan.tschannen@snowflake.com>
2022-04-09 05:15:25 +08:00
const KeyRangeRef blobGranulePurgeKeys(LiteralStringRef("\xff\x02/bgp/"), LiteralStringRef("\xff\x02/bgp0"));
const KeyRangeRef blobGranuleVersionKeys(LiteralStringRef("\xff\x02/bgv/"), LiteralStringRef("\xff\x02/bgv0"));
Blob integration (#6808) * Fixing leaked stream with explicit notify failed before destructor * better logic to prevent races in change feed fetching * Found new race that makes assert incorrect * handle server overloaded in initial read from fdb * Handling more blob error types in granule retry * Fixing rollback metadata problem, added better debugging * Fixing version race when fetching change feed metadata * Better racing split request handling * fixing assert * Handle change feed popped check in the blob worker * fix: do not use a RYW transaction for a versionstamp because of randomize API version (#6768) * more merge conflict issues * Change feed destroy fixes * Fixing change feed destroy and move race * Check error condition in BG file req * Using relative endpoints for blob worker interface * Fixing bug in previous fix * More destroy and move race fixes * Don't update empty version on destroy in case it gets rolled back. moved() and removing will take care of ensuring it is not read * Bug fix (#6796) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * Fixing durability issue with moving and destroying change feeds * Adding fix for not fully deleting files for a granule that child granules need to re-snapshot * More destroy and move races * Fixing change feed destroy and pop races * Renaming bg prune to purge, and adding a C api and unit test for it * more cleanup * review comments * Observability for granule purging * better handling for change feed not registered * Fixed purging bugs (#6815) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * fixed a few purging bugs Co-authored-by: Evan Tschannen <evan.tschannen@snowflake.com>
2022-04-09 05:15:25 +08:00
const KeyRef blobGranulePurgeChangeKey = LiteralStringRef("\xff\x02/bgpChange");
const uint8_t BG_FILE_TYPE_DELTA = 'D';
const uint8_t BG_FILE_TYPE_SNAPSHOT = 'S';
const Key blobGranuleFileKeyFor(UID granuleID, Version fileVersion, uint8_t fileType) {
ASSERT(fileType == 'D' || fileType == 'S');
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
wr.serializeBytes(blobGranuleFileKeys.begin);
2021-10-15 03:58:37 +08:00
wr << granuleID;
wr << bigEndian64(fileVersion);
wr << fileType;
return wr.toValue();
}
std::tuple<UID, Version, uint8_t> decodeBlobGranuleFileKey(KeyRef const& key) {
2021-10-15 03:58:37 +08:00
UID granuleID;
Version fileVersion;
uint8_t fileType;
BinaryReader reader(key.removePrefix(blobGranuleFileKeys.begin), AssumeVersion(ProtocolVersion::withBlobGranule()));
2021-10-15 03:58:37 +08:00
reader >> granuleID;
reader >> fileVersion;
reader >> fileType;
ASSERT(fileType == 'D' || fileType == 'S');
return std::tuple(granuleID, bigEndian64(fileVersion), fileType);
}
2021-10-15 03:58:37 +08:00
const KeyRange blobGranuleFileKeyRangeFor(UID granuleID) {
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));
}
const Value blobGranuleFileValueFor(StringRef const& filename, int64_t offset, int64_t length, int64_t fullFileLength) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
wr << filename;
wr << offset;
wr << length;
wr << fullFileLength;
return wr.toValue();
}
std::tuple<Standalone<StringRef>, int64_t, int64_t, int64_t> decodeBlobGranuleFileValue(ValueRef const& value) {
StringRef filename;
int64_t offset;
int64_t length;
int64_t fullFileLength;
BinaryReader reader(value, IncludeVersion());
reader >> filename;
reader >> offset;
reader >> length;
reader >> fullFileLength;
return std::tuple(filename, offset, length, fullFileLength);
}
Blob integration (#6808) * Fixing leaked stream with explicit notify failed before destructor * better logic to prevent races in change feed fetching * Found new race that makes assert incorrect * handle server overloaded in initial read from fdb * Handling more blob error types in granule retry * Fixing rollback metadata problem, added better debugging * Fixing version race when fetching change feed metadata * Better racing split request handling * fixing assert * Handle change feed popped check in the blob worker * fix: do not use a RYW transaction for a versionstamp because of randomize API version (#6768) * more merge conflict issues * Change feed destroy fixes * Fixing change feed destroy and move race * Check error condition in BG file req * Using relative endpoints for blob worker interface * Fixing bug in previous fix * More destroy and move race fixes * Don't update empty version on destroy in case it gets rolled back. moved() and removing will take care of ensuring it is not read * Bug fix (#6796) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * Fixing durability issue with moving and destroying change feeds * Adding fix for not fully deleting files for a granule that child granules need to re-snapshot * More destroy and move races * Fixing change feed destroy and pop races * Renaming bg prune to purge, and adding a C api and unit test for it * more cleanup * review comments * Observability for granule purging * better handling for change feed not registered * Fixed purging bugs (#6815) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * fixed a few purging bugs Co-authored-by: Evan Tschannen <evan.tschannen@snowflake.com>
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;
wr << range;
2021-11-20 09:54:22 +08:00
wr << force;
return wr.toValue();
}
Blob integration (#6808) * Fixing leaked stream with explicit notify failed before destructor * better logic to prevent races in change feed fetching * Found new race that makes assert incorrect * handle server overloaded in initial read from fdb * Handling more blob error types in granule retry * Fixing rollback metadata problem, added better debugging * Fixing version race when fetching change feed metadata * Better racing split request handling * fixing assert * Handle change feed popped check in the blob worker * fix: do not use a RYW transaction for a versionstamp because of randomize API version (#6768) * more merge conflict issues * Change feed destroy fixes * Fixing change feed destroy and move race * Check error condition in BG file req * Using relative endpoints for blob worker interface * Fixing bug in previous fix * More destroy and move race fixes * Don't update empty version on destroy in case it gets rolled back. moved() and removing will take care of ensuring it is not read * Bug fix (#6796) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * Fixing durability issue with moving and destroying change feeds * Adding fix for not fully deleting files for a granule that child granules need to re-snapshot * More destroy and move races * Fixing change feed destroy and pop races * Renaming bg prune to purge, and adding a C api and unit test for it * more cleanup * review comments * Observability for granule purging * better handling for change feed not registered * Fixed purging bugs (#6815) * fix: do not use a RYW transaction for a versionstamp because of randomize API version * fix: if the initialSnapshotVersion was pruned, granule history was incorrect * added a way to compress null bytes in printable() * fixed a few purging bugs Co-authored-by: Evan Tschannen <evan.tschannen@snowflake.com>
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;
KeyRange range;
2021-11-20 09:54:22 +08:00
bool force;
BinaryReader reader(value, IncludeVersion());
reader >> version;
reader >> range;
2021-11-20 09:54:22 +08:00
reader >> force;
return std::tuple(version, range, force);
}
const Value blobGranuleMappingValueFor(UID const& workerID) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
wr << workerID;
return wr.toValue();
}
UID decodeBlobGranuleMappingValue(ValueRef const& value) {
UID workerID;
BinaryReader reader(value, IncludeVersion());
reader >> workerID;
return workerID;
}
const Key blobGranuleLockKeyFor(KeyRangeRef const& keyRange) {
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
wr.serializeBytes(blobGranuleLockKeys.begin);
wr << keyRange;
return wr.toValue();
}
const Value blobGranuleLockValueFor(int64_t epoch, int64_t seqno, UID changeFeedId) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
2021-08-31 02:07:25 +08:00
wr << epoch;
wr << seqno;
wr << changeFeedId;
return wr.toValue();
}
std::tuple<int64_t, int64_t, UID> decodeBlobGranuleLockValue(const ValueRef& value) {
2021-08-31 02:07:25 +08:00
int64_t epoch, seqno;
UID changeFeedId;
BinaryReader reader(value, IncludeVersion());
2021-08-31 02:07:25 +08:00
reader >> epoch;
reader >> seqno;
reader >> changeFeedId;
return std::make_tuple(epoch, seqno, changeFeedId);
}
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;
return wr.toValue();
}
std::pair<UID, UID> decodeBlobGranuleSplitKey(KeyRef const& key) {
2021-10-15 03:58:37 +08:00
UID parentGranuleID;
UID granuleID;
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-15 03:58:37 +08:00
const KeyRange blobGranuleSplitKeyRangeFor(UID const& parentGranuleID) {
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
wr.serializeBytes(blobGranuleSplitKeys.begin);
2021-10-15 03:58:37 +08:00
wr << parentGranuleID;
2021-10-15 03:58:37 +08:00
Key startKey = wr.toValue();
return KeyRangeRef(startKey, strinc(startKey));
}
const Value blobGranuleSplitValueFor(BlobGranuleSplitState st) {
BinaryWriter wr(IncludeVersion(ProtocolVersion::withBlobGranule()));
wr << st;
2021-09-23 01:46:20 +08:00
return addVersionStampAtEnd(wr.toValue());
}
2021-09-23 01:46:20 +08:00
std::pair<BlobGranuleSplitState, Version> decodeBlobGranuleSplitValue(const ValueRef& value) {
BlobGranuleSplitState st;
2021-09-23 01:46:20 +08:00
Version v;
BinaryReader reader(value, IncludeVersion());
reader >> st;
2021-09-23 01:46:20 +08:00
reader >> v;
return std::pair(st, bigEndian64(v));
2021-09-23 01:46:20 +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
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();
}
Standalone<BlobGranuleHistoryValue> decodeBlobGranuleHistoryValue(const ValueRef& value) {
Standalone<BlobGranuleHistoryValue> historyValue;
2021-09-24 22:55:37 +08:00
BinaryReader reader(value, IncludeVersion());
reader >> historyValue;
return historyValue;
}
const KeyRangeRef blobWorkerListKeys(LiteralStringRef("\xff\x02/bwList/"), LiteralStringRef("\xff\x02/bwList0"));
const Key blobWorkerListKeyFor(UID workerID) {
BinaryWriter wr(AssumeVersion(ProtocolVersion::withBlobGranule()));
wr.serializeBytes(blobWorkerListKeys.begin);
wr << workerID;
return wr.toValue();
}
UID decodeBlobWorkerListKey(KeyRef const& key) {
UID workerID;
BinaryReader reader(key.removePrefix(blobWorkerListKeys.begin), AssumeVersion(ProtocolVersion::withBlobGranule()));
reader >> workerID;
return workerID;
}
const Value blobWorkerListValue(BlobWorkerInterface const& worker) {
return ObjectWriter::toValue(worker, IncludeVersion(ProtocolVersion::withBlobGranule()));
}
BlobWorkerInterface decodeBlobWorkerListValue(ValueRef const& value) {
BlobWorkerInterface interf;
ObjectReader reader(value.begin(), IncludeVersion());
reader.deserialize(interf);
return interf;
}
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;
const KeyRef tenantLastIdKey = "\xff/tenantLastId/"_sr;
const KeyRef tenantDataPrefixKey = "\xff/tenantDataPrefix"_sr;
2021-03-06 03:28:15 +08:00
// for tests
void testSSISerdes(StorageServerInterface const& ssi) {
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() : "",
ssi.isAcceptingRequests() ? "true" : "false",
2021-03-06 03:28:15 +08:00
ssi.address().toString().c_str(),
ssi.getValue.getEndpoint().token.toString().c_str());
StorageServerInterface ssi2 = decodeServerListValue(serverListValue(ssi));
2021-03-06 03:28:15 +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() : "",
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());
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();
testSSISerdes(ssi);
2021-03-06 03:28:15 +08:00
ssi.tssPairID = UID(0x2345234523452345, 0x1238123812381238);
testSSISerdes(ssi);
2021-03-06 03:28:15 +08:00
printf("ssi serdes test complete\n");
return Void();
}