2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* RYWDisable.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"
|
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 RYWDisableWorkload : TestWorkload {
|
2022-10-14 10:53:48 +08:00
|
|
|
static constexpr auto NAME = "RYWDisable";
|
|
|
|
|
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
|
|
|
|
|
|
|
RYWDisableWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
|
2022-09-20 02:35:58 +08:00
|
|
|
testDuration = getOption(options, "testDuration"_sr, 600.0);
|
|
|
|
nodes = getOption(options, "nodes"_sr, 100);
|
|
|
|
keyBytes = std::max(getOption(options, "keyBytes"_sr, 16), 16);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> setup(Database const& cx) override { return Void(); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<Void> start(Database const& cx) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
if (clientId == 0)
|
|
|
|
return _start(cx, this);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR static Future<Void> _start(Database cx, RYWDisableWorkload* self) {
|
|
|
|
state double testStart = now();
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
state ReadYourWritesTransaction tr(cx);
|
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
// do some operations
|
2019-05-11 05:01:52 +08:00
|
|
|
state int opType = deterministicRandom()->randomInt(0, 4);
|
2017-05-26 04:48:44 +08:00
|
|
|
state bool shouldError = true;
|
|
|
|
|
|
|
|
if (opType == 0) {
|
|
|
|
//TraceEvent("RYWSetting");
|
2019-05-11 05:01:52 +08:00
|
|
|
tr.set(self->keyForIndex(deterministicRandom()->randomInt(0, self->nodes)), StringRef());
|
2017-05-26 04:48:44 +08:00
|
|
|
} else if (opType == 1) {
|
|
|
|
//TraceEvent("RYWGetNoWait");
|
2019-05-11 05:01:52 +08:00
|
|
|
Future<Optional<Value>> _ =
|
|
|
|
tr.get(self->keyForIndex(deterministicRandom()->randomInt(0, self->nodes)));
|
2017-05-26 04:48:44 +08:00
|
|
|
} else if (opType == 2) {
|
|
|
|
//TraceEvent("RYWGetAndWait");
|
2019-05-11 05:01:52 +08:00
|
|
|
wait(success(tr.get(self->keyForIndex(deterministicRandom()->randomInt(0, self->nodes)))));
|
2017-05-26 04:48:44 +08:00
|
|
|
} else {
|
|
|
|
//TraceEvent("RYWNoOp");
|
|
|
|
shouldError = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set ryw disable, check that it fails
|
|
|
|
try {
|
|
|
|
tr.setOption(FDBTransactionOptions::READ_YOUR_WRITES_DISABLE);
|
|
|
|
if (shouldError)
|
|
|
|
ASSERT(false);
|
|
|
|
} catch (Error& e) {
|
|
|
|
if (!shouldError)
|
|
|
|
ASSERT(false);
|
|
|
|
ASSERT(e.code() == error_code_client_invalid_operation);
|
|
|
|
}
|
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(delay(0.1));
|
2021-03-11 02:06:03 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
if (now() - testStart > self->testDuration)
|
|
|
|
return Void();
|
|
|
|
|
2019-05-11 05:01:52 +08:00
|
|
|
if (deterministicRandom()->random01() < 0.5)
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
tr.reset();
|
|
|
|
} catch (Error& e) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
for (int i = 0; i < clients.size(); i++)
|
|
|
|
if (clients[i].isError())
|
|
|
|
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
|
|
|
|
|
|
|
Key keyForIndex(uint64_t index) {
|
|
|
|
Key result = makeString(keyBytes);
|
|
|
|
uint8_t* data = mutateString(result);
|
|
|
|
memset(data, '.', keyBytes);
|
|
|
|
|
|
|
|
double d = double(index) / nodes;
|
|
|
|
emplaceIndex(data, 0, *(int64_t*)&d);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-14 10:53:48 +08:00
|
|
|
WorkloadFactory<RYWDisableWorkload> RYWDisableWorkloadFactory;
|