2021-05-31 02:51:47 +08:00
|
|
|
/*
|
|
|
|
* ClientTransactionProfileCorrectness.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2018-03-15 03:39:50 +08:00
|
|
|
#include "fdbserver/ServerDBInfo.h"
|
2021-02-24 08:17:05 +08:00
|
|
|
#include "fdbclient/GlobalConfig.actor.h"
|
2019-02-18 09:38:13 +08:00
|
|
|
#include "fdbclient/ManagementAPI.actor.h"
|
2018-03-15 03:39:50 +08:00
|
|
|
#include "fdbclient/RunTransaction.actor.h"
|
2021-05-31 02:51:47 +08:00
|
|
|
#include "fdbclient/Tuple.h"
|
2019-02-18 10:46:59 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2018-03-15 03:39:50 +08:00
|
|
|
|
|
|
|
static const Key CLIENT_LATENCY_INFO_PREFIX = LiteralStringRef("client_latency/");
|
|
|
|
static const Key CLIENT_LATENCY_INFO_CTR_PREFIX = LiteralStringRef("client_latency_counter/");
|
|
|
|
|
|
|
|
/*
|
|
|
|
FF - 2 bytes \xff\x02
|
|
|
|
SSSSSSSSSS - 10 bytes Version Stamp
|
|
|
|
RRRRRRRRRRRRRRRR - 16 bytes Transaction id
|
|
|
|
NNNN - 4 Bytes Chunk number (Big Endian)
|
|
|
|
TTTT - 4 Bytes Total number of chunks (Big Endian)
|
2019-02-28 06:24:16 +08:00
|
|
|
XXXX - Variable length user provided transaction identifier
|
2018-03-15 03:39:50 +08:00
|
|
|
*/
|
2021-03-11 02:06:03 +08:00
|
|
|
StringRef sampleTrInfoKey =
|
|
|
|
LiteralStringRef("\xff\x02/fdbClientInfo/client_latency/SSSSSSSSSS/RRRRRRRRRRRRRRRR/NNNNTTTT/XXXX/");
|
2018-03-15 03:39:50 +08:00
|
|
|
static const auto chunkNumStartIndex = sampleTrInfoKey.toString().find('N');
|
|
|
|
static const auto numChunksStartIndex = sampleTrInfoKey.toString().find('T');
|
|
|
|
static const int chunkFormatSize = 4;
|
|
|
|
static const auto trIdStartIndex = sampleTrInfoKey.toString().find('R');
|
|
|
|
static const int trIdFormatSize = 16;
|
|
|
|
|
2019-07-20 08:31:49 +08:00
|
|
|
namespace ClientLogEventsParser {
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventGetVersion(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetVersion gv;
|
|
|
|
reader >> gv;
|
|
|
|
ASSERT(gv.latency < 10000);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventGetVersion_V2(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetVersion_V2 gv;
|
|
|
|
reader >> gv;
|
|
|
|
ASSERT(gv.latency < 10000);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventGetVersion_V3(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetVersion_V3 gv;
|
|
|
|
reader >> gv;
|
|
|
|
ASSERT(gv.latency < 10000);
|
|
|
|
ASSERT(gv.readVersion > 0);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventGet(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGet g;
|
|
|
|
reader >> g;
|
|
|
|
ASSERT(g.latency < 10000 && g.valueSize < CLIENT_KNOBS->VALUE_SIZE_LIMIT &&
|
|
|
|
g.key.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventGetRange(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetRange gr;
|
|
|
|
reader >> gr;
|
|
|
|
ASSERT(gr.latency < 10000 && gr.rangeSize < 1000000000 &&
|
|
|
|
gr.startKey.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT &&
|
|
|
|
gr.endKey.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventCommit(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventCommit c;
|
|
|
|
reader >> c;
|
|
|
|
ASSERT(c.latency < 10000 && c.commitBytes < CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT && c.numMutations < 1000000);
|
|
|
|
}
|
2020-05-04 13:42:06 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventCommit_V2(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventCommit_V2 c;
|
|
|
|
reader >> c;
|
|
|
|
ASSERT(c.latency < 10000 && c.commitBytes < CLIENT_KNOBS->TRANSACTION_SIZE_LIMIT && c.numMutations < 1000000 &&
|
|
|
|
c.commitVersion > 0);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventErrorGet(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetError ge;
|
|
|
|
reader >> ge;
|
|
|
|
ASSERT(ge.errCode < 10000 && ge.key.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void parseEventErrorGetRange(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventGetRangeError gre;
|
|
|
|
reader >> gre;
|
|
|
|
ASSERT(gre.errCode < 10000 && gre.startKey.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT &&
|
|
|
|
gre.endKey.size() < CLIENT_KNOBS->SYSTEM_KEY_SIZE_LIMIT);
|
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
void parseEventErrorCommit(BinaryReader& reader) {
|
|
|
|
FdbClientLogEvents::EventCommitError ce;
|
|
|
|
reader >> ce;
|
|
|
|
ASSERT(ce.errCode < 10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ParserBase {
|
|
|
|
std::function<void(BinaryReader&)> parseGetVersion = parseEventGetVersion;
|
|
|
|
std::function<void(BinaryReader&)> parseGet = parseEventGet;
|
|
|
|
std::function<void(BinaryReader&)> parseGetRange = parseEventGetRange;
|
|
|
|
std::function<void(BinaryReader&)> parseCommit = parseEventCommit;
|
|
|
|
std::function<void(BinaryReader&)> parseErrorGet = parseEventErrorGet;
|
|
|
|
std::function<void(BinaryReader&)> parseErrorGetRange = parseEventErrorGetRange;
|
|
|
|
std::function<void(BinaryReader&)> parseErrorCommit = parseEventErrorCommit;
|
|
|
|
virtual ~ParserBase() = 0;
|
|
|
|
};
|
|
|
|
ParserBase::~ParserBase() {}
|
|
|
|
|
|
|
|
struct Parser_V1 : ParserBase {
|
|
|
|
~Parser_V1() override {}
|
|
|
|
};
|
|
|
|
struct Parser_V2 : ParserBase {
|
|
|
|
Parser_V2() { parseGetVersion = parseEventGetVersion_V2; }
|
|
|
|
~Parser_V2() override {}
|
|
|
|
};
|
|
|
|
struct Parser_V3 : ParserBase {
|
|
|
|
Parser_V3() {
|
|
|
|
parseGetVersion = parseEventGetVersion_V3;
|
|
|
|
parseCommit = parseEventCommit_V2;
|
2019-07-20 08:31:49 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
~Parser_V3() override {}
|
|
|
|
};
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
struct ParserFactory {
|
|
|
|
static std::unique_ptr<ParserBase> getParser(ProtocolVersion version) {
|
|
|
|
if (version.version() >= (uint64_t)0x0FDB00B063010001LL) {
|
|
|
|
return std::unique_ptr<ParserBase>(new Parser_V3());
|
|
|
|
} else if (version.version() >= (uint64_t)0x0FDB00B062000001LL) {
|
|
|
|
return std::unique_ptr<ParserBase>(new Parser_V2());
|
|
|
|
} else {
|
|
|
|
return std::unique_ptr<ParserBase>(new Parser_V1());
|
2019-07-20 08:31:49 +08:00
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
}
|
2019-07-20 08:31:49 +08:00
|
|
|
};
|
2021-03-11 02:06:03 +08:00
|
|
|
}; // namespace ClientLogEventsParser
|
2019-07-20 08:31:49 +08:00
|
|
|
|
2018-03-15 03:39:50 +08:00
|
|
|
// Checks TransactionInfo format
|
2021-03-11 02:06:03 +08:00
|
|
|
bool checkTxInfoEntryFormat(BinaryReader& reader) {
|
2018-03-15 03:39:50 +08:00
|
|
|
// Check protocol version
|
2019-06-19 05:49:04 +08:00
|
|
|
ProtocolVersion protocolVersion;
|
2018-03-15 03:39:50 +08:00
|
|
|
reader >> protocolVersion;
|
|
|
|
reader.setProtocolVersion(protocolVersion);
|
2021-03-11 02:06:03 +08:00
|
|
|
std::unique_ptr<ClientLogEventsParser::ParserBase> parser =
|
|
|
|
ClientLogEventsParser::ParserFactory::getParser(protocolVersion);
|
2018-03-15 03:39:50 +08:00
|
|
|
|
2018-03-16 02:00:47 +08:00
|
|
|
while (!reader.empty()) {
|
2018-03-15 03:39:50 +08:00
|
|
|
// Get EventType and timestamp
|
2020-05-23 00:25:32 +08:00
|
|
|
FdbClientLogEvents::Event event;
|
2018-03-15 03:39:50 +08:00
|
|
|
reader >> event;
|
2021-03-11 02:06:03 +08:00
|
|
|
switch (event.type) {
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::GET_VERSION_LATENCY:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseGetVersion(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::GET_LATENCY:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseGet(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::GET_RANGE_LATENCY:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseGetRange(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::COMMIT_LATENCY:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseCommit(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::ERROR_GET:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseErrorGet(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::ERROR_GET_RANGE:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseErrorGetRange(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
2020-11-15 11:22:19 +08:00
|
|
|
case FdbClientLogEvents::EventType::ERROR_COMMIT:
|
2019-07-20 08:31:49 +08:00
|
|
|
parser->parseErrorCommit(reader);
|
2018-03-15 03:39:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
2020-05-23 00:25:32 +08:00
|
|
|
TraceEvent(SevError, "ClientTransactionProfilingUnknownEvent").detail("EventType", event.type);
|
2018-03-15 03:39:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ClientTransactionProfileCorrectnessWorkload : TestWorkload {
|
|
|
|
double samplingProbability;
|
|
|
|
int64_t trInfoSizeLimit;
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ClientTransactionProfileCorrectnessWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
|
|
|
samplingProbability = getOption(options,
|
|
|
|
LiteralStringRef("samplingProbability"),
|
|
|
|
deterministicRandom()->random01() / 10); // rand range 0 - 0.1
|
|
|
|
trInfoSizeLimit = getOption(options,
|
|
|
|
LiteralStringRef("trInfoSizeLimit"),
|
|
|
|
deterministicRandom()->randomInt(100 * 1024, 10 * 1024 * 1024)); // 100 KB - 10 MB
|
|
|
|
TraceEvent(SevInfo, "ClientTransactionProfilingSetup")
|
|
|
|
.detail("ClientId", clientId)
|
|
|
|
.detail("SamplingProbability", samplingProbability)
|
|
|
|
.detail("TrInfoSizeLimit", trInfoSizeLimit);
|
2018-03-15 03:39:50 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string description() const override { return "ClientTransactionProfileCorrectness"; }
|
2018-03-15 03:39:50 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> setup(Database const& cx) override {
|
2018-03-15 03:39:50 +08:00
|
|
|
if (clientId == 0) {
|
2021-06-10 13:33:00 +08:00
|
|
|
IKnobCollection::getMutableGlobalKnobCollection().setKnob("csi_status_delay",
|
|
|
|
KnobValueRef::create(double{ 2.0 })); // 2 seconds
|
2018-03-15 03:39:50 +08:00
|
|
|
return changeProfilingParameters(cx, trInfoSizeLimit, samplingProbability);
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> start(Database const& cx) override { return Void(); }
|
2018-03-15 03:39:50 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
int getNumChunks(KeyRef key) const {
|
2021-03-11 02:06:03 +08:00
|
|
|
return bigEndian32(
|
|
|
|
BinaryReader::fromStringRef<int>(key.substr(numChunksStartIndex, chunkFormatSize), Unversioned()));
|
2018-03-15 03:39:50 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
int getChunkNum(KeyRef key) const {
|
2021-03-11 02:06:03 +08:00
|
|
|
return bigEndian32(
|
|
|
|
BinaryReader::fromStringRef<int>(key.substr(chunkNumStartIndex, chunkFormatSize), Unversioned()));
|
2018-03-15 03:39:50 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string getTrId(KeyRef key) const { return key.substr(trIdStartIndex, trIdFormatSize).toString(); }
|
2018-03-15 03:39:50 +08:00
|
|
|
|
2021-05-04 04:14:16 +08:00
|
|
|
bool checkTxInfoEntriesFormat(const RangeResult& txInfoEntries) {
|
2018-03-15 03:39:50 +08:00
|
|
|
std::string val;
|
|
|
|
std::map<std::string, std::vector<ValueRef>> trInfoChunks;
|
|
|
|
for (auto kv : txInfoEntries) {
|
|
|
|
int numChunks = getNumChunks(kv.key);
|
|
|
|
int chunkNum = getChunkNum(kv.key);
|
|
|
|
std::string trId = getTrId(kv.key);
|
|
|
|
|
|
|
|
if (numChunks == 1) {
|
|
|
|
ASSERT(chunkNum == 1);
|
|
|
|
BinaryReader reader(kv.value, Unversioned());
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!checkTxInfoEntryFormat(reader))
|
|
|
|
return false;
|
|
|
|
} else {
|
2018-03-15 03:39:50 +08:00
|
|
|
if (chunkNum == 1) { // First chunk
|
2021-03-11 02:06:03 +08:00
|
|
|
// Remove any entry if already present. There are scenarios (eg., commit_unknown_result) where a
|
|
|
|
// transaction info may be logged multiple times
|
2018-03-24 06:51:56 +08:00
|
|
|
trInfoChunks.erase(trId);
|
2021-03-11 02:06:03 +08:00
|
|
|
trInfoChunks.insert(std::pair<std::string, std::vector<ValueRef>>(trId, { kv.value }));
|
|
|
|
} else {
|
2018-03-15 03:39:50 +08:00
|
|
|
if (trInfoChunks.find(trId) == trInfoChunks.end()) {
|
|
|
|
// Some of the earlier chunks for this trId should have been deleted.
|
|
|
|
// Discard this chunk as it is of not much use
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevInfo, "ClientTransactionProfilingSomeChunksMissing").detail("TrId", trId);
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2018-03-24 06:51:56 +08:00
|
|
|
// Check if it is the expected chunk. Otherwise discard the whole transaction entry.
|
|
|
|
// There are scenarios (eg., when deletion is happening) where some chunks get missed.
|
|
|
|
if (chunkNum != trInfoChunks.find(trId)->second.size() + 1) {
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevInfo, "ClientTransactionProfilingChunksMissing").detail("TrId", trId);
|
2018-03-24 06:51:56 +08:00
|
|
|
trInfoChunks.erase(trId);
|
2021-03-11 02:06:03 +08:00
|
|
|
} else {
|
2018-03-24 06:51:56 +08:00
|
|
|
trInfoChunks.find(trId)->second.push_back(kv.value);
|
|
|
|
}
|
2018-03-15 03:39:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chunkNum == numChunks && trInfoChunks.find(trId) != trInfoChunks.end()) {
|
|
|
|
auto iter = trInfoChunks.find(trId);
|
|
|
|
BinaryWriter bw(Unversioned());
|
|
|
|
for (auto val : iter->second)
|
|
|
|
bw.serializeBytes(val.begin(), val.size());
|
|
|
|
BinaryReader reader(bw.getData(), bw.getLength(), Unversioned());
|
|
|
|
if (!checkTxInfoEntryFormat(reader))
|
|
|
|
return false;
|
|
|
|
trInfoChunks.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> changeProfilingParameters(Database cx, int64_t sizeLimit, double sampleProbability) {
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Void> {
|
2021-03-17 08:20:25 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::SPECIAL_KEY_SPACE_ENABLE_WRITES);
|
2021-03-11 02:06:03 +08:00
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
2021-03-17 08:20:25 +08:00
|
|
|
Tuple rate = Tuple().appendDouble(sampleProbability);
|
|
|
|
Tuple size = Tuple().append(sizeLimit);
|
|
|
|
tr->set(GlobalConfig::prefixedKey(fdbClientInfoTxnSampleRate), rate.pack());
|
|
|
|
tr->set(GlobalConfig::prefixedKey(fdbClientInfoTxnSizeLimit), size.pack());
|
2021-03-11 02:06:03 +08:00
|
|
|
return Void();
|
|
|
|
}));
|
2018-03-15 03:39:50 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<bool> _check(Database cx, ClientTransactionProfileCorrectnessWorkload* self) {
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(self->changeProfilingParameters(cx, self->trInfoSizeLimit, 0)); // Disable sampling
|
2018-03-15 03:39:50 +08:00
|
|
|
// FIXME: Better way to ensure that all client profile data has been flushed to the database
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(CLIENT_KNOBS->CSI_STATUS_DELAY));
|
2018-03-15 03:39:50 +08:00
|
|
|
|
|
|
|
state Key clientLatencyAtomicCtr = CLIENT_LATENCY_INFO_CTR_PREFIX.withPrefix(fdbClientInfoPrefixRange.begin);
|
|
|
|
state int64_t counter;
|
2021-05-04 04:14:16 +08:00
|
|
|
state RangeResult txInfoEntries;
|
2021-03-11 02:06:03 +08:00
|
|
|
Optional<Value> ctrValue =
|
|
|
|
wait(runRYWTransaction(cx, [=](Reference<ReadYourWritesTransaction> tr) -> Future<Optional<Value>> {
|
|
|
|
tr->setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr->setOption(FDBTransactionOptions::LOCK_AWARE);
|
|
|
|
return tr->get(clientLatencyAtomicCtr);
|
|
|
|
}));
|
2018-03-15 03:39:50 +08:00
|
|
|
counter = ctrValue.present() ? BinaryReader::fromStringRef<int64_t>(ctrValue.get(), Unversioned()) : 0;
|
|
|
|
state Key clientLatencyName = CLIENT_LATENCY_INFO_PREFIX.withPrefix(fdbClientInfoPrefixRange.begin);
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
state KeySelector begin =
|
|
|
|
firstGreaterOrEqual(CLIENT_LATENCY_INFO_PREFIX.withPrefix(fdbClientInfoPrefixRange.begin));
|
2018-03-15 03:39:50 +08:00
|
|
|
state KeySelector end = firstGreaterOrEqual(strinc(begin.getKey()));
|
2018-06-08 06:27:05 +08:00
|
|
|
state int keysLimit = 10;
|
2018-06-09 02:24:51 +08:00
|
|
|
state Transaction tr(cx);
|
2018-03-15 03:39:50 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
tr.setOption(FDBTransactionOptions::ACCESS_SYSTEM_KEYS);
|
|
|
|
tr.setOption(FDBTransactionOptions::LOCK_AWARE);
|
2021-05-04 04:14:16 +08:00
|
|
|
state RangeResult kvRange = wait(tr.getRange(begin, end, keysLimit));
|
2018-03-15 03:39:50 +08:00
|
|
|
if (kvRange.empty())
|
|
|
|
break;
|
|
|
|
txInfoEntries.arena().dependsOn(kvRange.arena());
|
|
|
|
txInfoEntries.append(txInfoEntries.arena(), kvRange.begin(), kvRange.size());
|
|
|
|
begin = firstGreaterThan(kvRange.back().key);
|
2018-06-09 02:24:51 +08:00
|
|
|
tr.reset();
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-06-08 06:27:05 +08:00
|
|
|
if (e.code() == error_code_transaction_too_old)
|
|
|
|
keysLimit = std::max(1, keysLimit / 2);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2018-03-15 03:39:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the counter value matches the size of contents
|
|
|
|
int64_t contentsSize = 0;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (auto& kv : txInfoEntries) {
|
2018-03-15 03:39:50 +08:00
|
|
|
contentsSize += kv.key.size() + kv.value.size();
|
|
|
|
}
|
|
|
|
// FIXME: Find a way to check that contentsSize is not greater than a certain limit.
|
2021-03-11 02:06:03 +08:00
|
|
|
// if (counter != contentsSize) {
|
|
|
|
// TraceEvent(SevError, "ClientTransactionProfilingIncorrectCtrVal").detail("Counter",
|
|
|
|
// counter).detail("ContentsSize", contentsSize); return false;
|
2018-03-15 03:39:50 +08:00
|
|
|
//}
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevInfo, "ClientTransactionProfilingCtrval").detail("Counter", counter);
|
|
|
|
TraceEvent(SevInfo, "ClientTransactionProfilingContentsSize").detail("ContentsSize", contentsSize);
|
2018-03-15 03:39:50 +08:00
|
|
|
|
|
|
|
// Check if the data format is as expected
|
|
|
|
return self->checkTxInfoEntriesFormat(txInfoEntries);
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(Database const& cx) override {
|
2018-03-15 03:39:50 +08:00
|
|
|
if (clientId != 0)
|
|
|
|
return true;
|
|
|
|
return _check(cx, this);
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {}
|
2018-03-15 03:39:50 +08:00
|
|
|
};
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
WorkloadFactory<ClientTransactionProfileCorrectnessWorkload> ClientTransactionProfileCorrectnessWorkloadFactory(
|
|
|
|
"ClientTransactionProfileCorrectness");
|