2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* Sideband.actor.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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2019-02-18 11:25:16 +08:00
|
|
|
#include "fdbserver/TesterInterface.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct SidebandMessage {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 11862046;
|
2017-05-26 04:48:44 +08:00
|
|
|
uint64_t key;
|
|
|
|
Version commitVersion;
|
|
|
|
|
|
|
|
SidebandMessage() {}
|
|
|
|
SidebandMessage(uint64_t key, Version commitVersion) : key(key), commitVersion(commitVersion) {}
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, key, commitVersion);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SidebandInterface {
|
2019-01-31 05:53:23 +08:00
|
|
|
constexpr static FileIdentifier file_identifier = 15950544;
|
2017-05-26 04:48:44 +08:00
|
|
|
RequestStream<SidebandMessage> updates;
|
|
|
|
|
|
|
|
UID id() const { return updates.getEndpoint().token; }
|
|
|
|
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
2018-12-29 02:49:26 +08:00
|
|
|
serializer(ar, updates);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SidebandWorkload : TestWorkload {
|
2022-10-14 10:53:48 +08:00
|
|
|
static constexpr auto NAME = "Sideband";
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
double testDuration, operationsPerSecond;
|
|
|
|
SidebandInterface interf;
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<Future<Void>> clients;
|
2017-05-26 04:48:44 +08:00
|
|
|
PerfIntCounter messages, consistencyErrors, keysUnexpectedlyPresent;
|
|
|
|
|
|
|
|
SidebandWorkload(WorkloadContext const& wcx)
|
|
|
|
: TestWorkload(wcx), messages("Messages"), consistencyErrors("Causal Consistency Errors"),
|
|
|
|
keysUnexpectedlyPresent("KeysUnexpectedlyPresent") {
|
2022-09-20 02:35:58 +08:00
|
|
|
testDuration = getOption(options, "testDuration"_sr, 10.0);
|
|
|
|
operationsPerSecond = getOption(options, "operationsPerSecond"_sr, 50.0);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> setup(Database const& cx) override { return persistInterface(this, cx->clone()); }
|
|
|
|
Future<Void> start(Database const& cx) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
clients.push_back(mutator(this, cx->clone()));
|
|
|
|
clients.push_back(checker(this, cx->clone()));
|
|
|
|
return delay(testDuration);
|
|
|
|
}
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(Database const& cx) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
int errors = 0;
|
|
|
|
for (int c = 0; c < clients.size(); c++)
|
|
|
|
errors += clients[c].isError();
|
|
|
|
if (errors)
|
|
|
|
TraceEvent(SevError, "TestFailure").detail("Reason", "There were client errors.");
|
|
|
|
clients.clear();
|
|
|
|
if (consistencyErrors.getValue())
|
|
|
|
TraceEvent(SevError, "TestFailure").detail("Reason", "There were causal consistency errors.");
|
|
|
|
return !errors && !consistencyErrors.getValue();
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
m.push_back(messages.getMetric());
|
|
|
|
m.push_back(consistencyErrors.getMetric());
|
|
|
|
m.push_back(keysUnexpectedlyPresent.getMetric());
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> persistInterface(SidebandWorkload* self, Database cx) {
|
|
|
|
state Transaction tr(cx);
|
|
|
|
BinaryWriter wr(IncludeVersion());
|
|
|
|
wr << self->interf;
|
2019-03-29 02:52:50 +08:00
|
|
|
state Standalone<StringRef> serializedInterface = wr.toValue();
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
Optional<Value> val = wait(tr.get(StringRef(format("Sideband/Client/%d", self->clientId))));
|
|
|
|
if (val.present()) {
|
|
|
|
if (val.get() != serializedInterface)
|
|
|
|
throw operation_failed();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tr.set(format("Sideband/Client/%d", self->clientId), serializedInterface);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.commit());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TraceEvent("SidebandPersisted", self->interf.id()).detail("ClientIdx", self->clientId);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<SidebandInterface> fetchSideband(SidebandWorkload* self, Database cx) {
|
|
|
|
state Transaction tr(cx);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
Optional<Value> val =
|
|
|
|
wait(tr.get(StringRef(format("Sideband/Client/%d", (self->clientId + 1) % self->clientCount))));
|
|
|
|
if (!val.present()) {
|
|
|
|
throw operation_failed();
|
|
|
|
}
|
|
|
|
SidebandInterface sideband;
|
|
|
|
BinaryReader br(val.get(), IncludeVersion());
|
|
|
|
br >> sideband;
|
|
|
|
TraceEvent("SidebandFetched", sideband.id()).detail("ClientIdx", self->clientId);
|
|
|
|
return sideband;
|
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> mutator(SidebandWorkload* self, Database cx) {
|
2020-05-11 05:26:40 +08:00
|
|
|
state SidebandInterface checker = wait(self->fetchSideband(self, cx->clone()));
|
|
|
|
state double lastTime = now();
|
|
|
|
state Version commitVersion;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-05-11 05:26:40 +08:00
|
|
|
loop {
|
|
|
|
wait(poisson(&lastTime, 1.0 / self->operationsPerSecond));
|
|
|
|
state Transaction tr(cx);
|
|
|
|
state uint64_t key = deterministicRandom()->randomUniqueID().hash();
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2020-05-11 05:26:40 +08:00
|
|
|
state Standalone<StringRef> messageKey(format("Sideband/Message/%llx", key));
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
2020-05-11 05:26:40 +08:00
|
|
|
try {
|
|
|
|
Optional<Value> val = wait(tr.get(messageKey));
|
|
|
|
if (val.present()) {
|
|
|
|
commitVersion = tr.getReadVersion().get();
|
|
|
|
++self->keysUnexpectedlyPresent;
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-09-20 02:35:58 +08:00
|
|
|
tr.set(messageKey, "deadbeef"_sr);
|
2020-05-11 05:26:40 +08:00
|
|
|
wait(tr.commit());
|
|
|
|
commitVersion = tr.getCommittedVersion();
|
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
2020-05-11 05:26:40 +08:00
|
|
|
++self->messages;
|
|
|
|
checker.updates.send(SidebandMessage(key, commitVersion));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> checker(SidebandWorkload* self, Database cx) {
|
2020-05-11 05:26:40 +08:00
|
|
|
loop {
|
|
|
|
state SidebandMessage message = waitNext(self->interf.updates.getFuture());
|
|
|
|
state Standalone<StringRef> messageKey(format("Sideband/Message/%llx", message.key));
|
|
|
|
state Transaction tr(cx);
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
2020-05-11 05:26:40 +08:00
|
|
|
try {
|
|
|
|
Optional<Value> val = wait(tr.get(messageKey));
|
|
|
|
if (!val.present()) {
|
|
|
|
TraceEvent(SevError, "CausalConsistencyError", self->interf.id())
|
|
|
|
.detail("MessageKey", messageKey.toString().c_str())
|
|
|
|
.detail("RemoteCommitVersion", message.commitVersion)
|
|
|
|
.detail("LocalReadVersion",
|
|
|
|
tr.getReadVersion().get()); // will assert that ReadVersion is set
|
|
|
|
++self->consistencyErrors;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
2020-05-11 05:26:40 +08:00
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-14 10:53:48 +08:00
|
|
|
WorkloadFactory<SidebandWorkload> SidebandWorkloadFactory;
|