2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* FastTriggeredWatches.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fdbrpc/ContinuousSample.h"
|
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"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbclient/ReadYourWrites.h"
|
|
|
|
#include "fdbserver/Knobs.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2021-03-11 02:06:03 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct FastTriggeredWatchesWorkload : TestWorkload {
|
2021-03-23 07:37:54 +08:00
|
|
|
// Tests the time it takes for a watch to be fired after the value has changed in the storage server
|
2017-05-26 04:48:44 +08:00
|
|
|
int nodes, keyBytes;
|
|
|
|
double testDuration;
|
2021-09-17 08:42:34 +08:00
|
|
|
std::vector<Future<Void>> clients;
|
2017-05-26 04:48:44 +08:00
|
|
|
PerfIntCounter operations, retries;
|
|
|
|
Value defaultValue;
|
|
|
|
|
|
|
|
FastTriggeredWatchesWorkload(WorkloadContext const& wcx)
|
2021-03-11 02:06:03 +08:00
|
|
|
: TestWorkload(wcx), operations("Operations"), retries("Retries") {
|
|
|
|
testDuration = getOption(options, LiteralStringRef("testDuration"), 600.0);
|
|
|
|
nodes = getOption(options, LiteralStringRef("nodes"), 100);
|
|
|
|
defaultValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 1000)));
|
|
|
|
keyBytes = std::max(getOption(options, LiteralStringRef("keyBytes"), 16), 16);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string description() const override { return "Watches"; }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> setup(Database const& cx) override {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (clientId == 0)
|
|
|
|
return _setup(cx, this);
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> _setup(Database cx, FastTriggeredWatchesWorkload* self) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state Transaction tr(cx);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
try {
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < self->nodes; i += 2)
|
|
|
|
tr.set(self->keyForIndex(i), self->defaultValue);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.commit());
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
} catch (Error& e) {
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> start(Database const& cx) override {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (clientId == 0)
|
|
|
|
return _start(cx, this);
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Version> setter(Database cx, Key key, Optional<Value> value) {
|
|
|
|
state ReadYourWritesTransaction tr(cx);
|
2021-03-23 07:37:54 +08:00
|
|
|
// set the value of key and return the commit version
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(delay(deterministicRandom()->random01()));
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
try {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (value.present())
|
|
|
|
tr.set(key, value.get());
|
2017-05-26 04:48:44 +08:00
|
|
|
else
|
2021-03-11 02:06:03 +08:00
|
|
|
tr.clear(key);
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWSetBegin").detail("Key", printable(key)).detail("Value", printable(value));
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.commit());
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWSetEnd").detail("Key", printable(key)).detail("Value", printable(value)).detail("Ver", tr.getCommittedVersion());
|
2017-05-26 04:48:44 +08:00
|
|
|
return tr.getCommittedVersion();
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-08-02 05:30:57 +08:00
|
|
|
//TraceEvent("FTWSetError").error(e).detail("Key", printable(key)).detail("Value", printable(value));
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR static Future<Void> _start(Database cx, FastTriggeredWatchesWorkload* self) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state double testStart = now();
|
|
|
|
state Version lastReadVersion = 0;
|
|
|
|
try {
|
|
|
|
loop {
|
|
|
|
state double getDuration = 0;
|
|
|
|
state double watchEnd = 0;
|
|
|
|
state bool first = true;
|
2021-03-11 02:06:03 +08:00
|
|
|
state Key setKey = self->keyForIndex(deterministicRandom()->randomInt(0, self->nodes));
|
2017-05-26 04:48:44 +08:00
|
|
|
state Optional<Value> setValue;
|
2021-03-11 02:06:03 +08:00
|
|
|
if (deterministicRandom()->random01() > 0.5)
|
|
|
|
setValue = StringRef(format("%010d", deterministicRandom()->randomInt(0, 1000)));
|
2021-03-23 07:37:54 +08:00
|
|
|
// Set the value at setKey to something random
|
2021-03-11 02:06:03 +08:00
|
|
|
state Future<Version> setFuture = self->setter(cx, setKey, setValue);
|
|
|
|
wait(delay(deterministicRandom()->random01()));
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
2021-03-11 02:06:03 +08:00
|
|
|
state ReadYourWritesTransaction tr(cx);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
try {
|
2021-03-11 02:06:03 +08:00
|
|
|
Optional<Value> val = wait(tr.get(setKey));
|
|
|
|
if (!first) {
|
2017-05-26 04:48:44 +08:00
|
|
|
getDuration = now() - watchEnd;
|
|
|
|
}
|
|
|
|
lastReadVersion = tr.getReadVersion().get();
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWGet").detail("Key", printable(setKey)).detail("Value", printable(val)).detail("Ver", tr.getReadVersion().get());
|
2021-08-28 08:07:47 +08:00
|
|
|
// if the value is already setValue then there is no point setting a watch so break out of the
|
|
|
|
// loop
|
2021-03-11 02:06:03 +08:00
|
|
|
if (val == setValue)
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(first);
|
2021-03-23 07:37:54 +08:00
|
|
|
// set a watch and wait for it to be triggered (i.e for self->setter to set the value)
|
2021-03-11 02:06:03 +08:00
|
|
|
state Future<Void> watchFuture = tr.watch(setKey);
|
|
|
|
wait(tr.commit());
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWStartWatch").detail("Key", printable(setKey));
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(watchFuture);
|
2017-05-26 04:48:44 +08:00
|
|
|
watchEnd = now();
|
|
|
|
first = false;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2018-08-02 05:30:57 +08:00
|
|
|
//TraceEvent("FTWWatchError").error(e).detail("Key", printable(setKey));
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-11 02:06:03 +08:00
|
|
|
Version ver = wait(setFuture);
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("FTWWatchDone").detail("Key", printable(setKey));
|
2021-03-23 07:37:54 +08:00
|
|
|
// Assert that the time from setting the key to triggering the watch is no greater than 25s
|
|
|
|
// TODO: This assertion can cause flaky behaviour since sometimes a watch can take longer to fire
|
2021-03-11 02:06:03 +08:00
|
|
|
ASSERT(lastReadVersion - ver >= SERVER_KNOBS->MAX_VERSIONS_IN_FLIGHT ||
|
2021-03-23 07:37:54 +08:00
|
|
|
lastReadVersion - ver < SERVER_KNOBS->VERSIONS_PER_SECOND * (25 + getDuration));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
if (now() - testStart > self->testDuration)
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Void();
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
2022-02-25 04:25:52 +08:00
|
|
|
TraceEvent(SevError, "FastWatchError").errorUnsuppressed(e);
|
2017-05-26 04:48:44 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(Database const& cx) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
bool ok = true;
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < clients.size(); i++)
|
|
|
|
if (clients[i].isError())
|
2017-05-26 04:48:44 +08:00
|
|
|
ok = false;
|
|
|
|
clients.clear();
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2021-09-17 08:42:34 +08:00
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
double duration = testDuration;
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Operations/sec", operations.getValue() / duration, Averaged::False);
|
2021-03-11 02:06:03 +08:00
|
|
|
m.push_back(operations.getMetric());
|
|
|
|
m.push_back(retries.getMetric());
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Key keyForIndex(uint64_t index) const {
|
2021-03-11 02:06:03 +08:00
|
|
|
Key result = makeString(keyBytes);
|
|
|
|
uint8_t* data = mutateString(result);
|
2017-05-26 04:48:44 +08:00
|
|
|
memset(data, '.', keyBytes);
|
|
|
|
|
|
|
|
double d = double(index) / nodes;
|
2021-03-11 02:06:03 +08:00
|
|
|
emplaceIndex(data, 0, *(int64_t*)&d);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-02 05:30:57 +08:00
|
|
|
WorkloadFactory<FastTriggeredWatchesWorkload> FastTriggeredWatchesWorkloadFactory("FastTriggeredWatches");
|