Fixes in the GetEstimatedRangeSize workload

* Run the workload on a trusted client rather than untrusted
  clients. This allows the workload to be substantially simplified
  as well as enables testing for the case where no tenant is
  present.
* Explicitly pass tenant to BulkSetup so that the setup phase
  can be run in parallel for multiple tenants without causing a race.
This commit is contained in:
Ankita Kejriwal 2022-09-29 18:08:40 -07:00
parent 0264262f78
commit c2b6b288b7
2 changed files with 21 additions and 56 deletions

View File

@ -2501,10 +2501,6 @@ void ReadYourWritesTransaction::setOptionImpl(FDBTransactionOptions::Option opti
validateOptionValueNotPresent(value);
options.bypassUnreadable = true;
break;
// TODO(kejriwal): Improve the way this is set
case FDBTransactionOptions::AUTHORIZATION_TOKEN:
tr.setOption(option, value);
break;
default:
break;
}

View File

@ -21,58 +21,24 @@
#include <cstring>
#include "fdbclient/SystemData.h"
#include "flow/Arena.h"
#include "flow/IRandom.h"
#include "flow/Trace.h"
#include "flow/serialize.h"
#include "fdbrpc/simulator.h"
#include "fdbrpc/TokenSign.h"
#include "fdbclient/FDBOptions.g.h"
#include "fdbclient/NativeAPI.actor.h"
#include "fdbclient/SystemData.h"
#include "fdbserver/TesterInterface.actor.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "fdbserver/workloads/BulkSetup.actor.h"
#include "flow/actorcompiler.h" // This must be the last #include.
struct Members {
Arena arena;
TenantName tenant;
authz::jwt::TokenRef token;
StringRef signedToken;
};
struct GetEstimatedRangeSizeWorkload : TestWorkload, Members {
struct GetEstimatedRangeSizeWorkload : TestWorkload {
int nodeCount;
double testDuration;
Key keyPrefix;
bool hasTenant;
TenantName tenant;
GetEstimatedRangeSizeWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
testDuration = getOption(options, "testDuration"_sr, 10.0);
nodeCount = getOption(options, "nodeCount"_sr, 10000.0);
keyPrefix = unprintable(getOption(options, "keyPrefix"_sr, LiteralStringRef("")).toString());
hasTenant = hasOption(options, "tenant"_sr);
if (hasTenant) {
ASSERT(g_network->isSimulated());
auto k = g_simulator.authKeys.begin();
this->tenant = getOption(options, "tenant"_sr, "DefaultTenant"_sr);
// make it comfortably longer than the timeout of the workload
auto currentTime = uint64_t(lround(g_network->timer()));
this->token.algorithm = authz::Algorithm::ES256;
this->token.issuedAtUnixTime = currentTime;
this->token.expiresAtUnixTime =
currentTime + uint64_t(std::lround(getCheckTimeout())) + uint64_t(std::lround(testDuration)) + 100;
this->token.keyId = k->first;
this->token.notBeforeUnixTime = currentTime - 10;
VectorRef<StringRef> tenants;
tenants.push_back_deep(this->arena, this->tenant);
this->token.tenants = tenants;
// we currently don't support this workload to be run outside of simulation
this->signedToken = authz::jwt::signToken(this->arena, this->token, k->second);
}
tenant = getOption(options, "tenant"_sr, "DefaultTenant"_sr);
}
std::string description() const override { return "GetEstimatedRangeSizeWorkload"; }
@ -81,8 +47,21 @@ struct GetEstimatedRangeSizeWorkload : TestWorkload, Members {
if (!hasTenant) {
return Void();
}
cx->defaultTenant = this->tenant;
return bulkSetup(cx, this, nodeCount, Promise<double>());
// Use default values for arguments between (and including) postSetupWarming and endNodeIdx params
return bulkSetup(cx,
this,
nodeCount,
Promise<double>(),
true,
0.0,
1e12,
std::vector<uint64_t>(),
Promise<std::vector<std::pair<uint64_t, double>>>(),
0,
0.1,
0,
0,
tenant);
}
Future<Void> start(Database const& cx) override {
@ -96,14 +75,6 @@ struct GetEstimatedRangeSizeWorkload : TestWorkload, Members {
void getMetrics(std::vector<PerfMetric>& m) override {}
StringRef getAuthToken() const { return this->signedToken; }
void setAuthToken(ReadYourWritesTransaction& tr) {
if (tr.getTenant().present()) {
tr.setOption(FDBTransactionOptions::AUTHORIZATION_TOKEN, this->signedToken);
}
}
Key keyForIndex(int n) { return key(n); }
Key key(int n) { return doubleToTestKey((double)n / nodeCount, keyPrefix); }
Value value(int n) { return doubleToTestKey(n, keyPrefix); }
@ -118,17 +89,15 @@ struct GetEstimatedRangeSizeWorkload : TestWorkload, Members {
ACTOR static Future<int64_t> getSize(GetEstimatedRangeSizeWorkload* self, Database cx) {
state Optional<TenantName> tenant = self->hasTenant ? self->tenant : Optional<TenantName>();
cx->defaultTenant = tenant;
state ReadYourWritesTransaction tr(cx, tenant);
TraceEvent(SevDebug, "AKGetSize1")
.detail("Tenant", cx->defaultTenant.present() ? cx->defaultTenant.get() : "none"_sr);
.detail("Tenant", tr.getTenant().present() ? tr.getTenant().get() : "none"_sr);
loop {
try {
self->setAuthToken(tr);
state int64_t size = wait(tr.getEstimatedRangeSizeBytes(normalKeys));
TraceEvent(SevDebug, "AKGetSize2")
.detail("Tenant", cx->defaultTenant.present() ? cx->defaultTenant.get() : "none"_sr)
.detail("Tenant", tr.getTenant().present() ? tr.getTenant().get() : "none"_sr)
.detail("Size", size);
tr.reset();
return size;
@ -139,4 +108,4 @@ struct GetEstimatedRangeSizeWorkload : TestWorkload, Members {
}
};
WorkloadFactory<GetEstimatedRangeSizeWorkload> GetEstimatedRangeSizeWorkloadFactory("GetEstimatedRangeSize", true);
WorkloadFactory<GetEstimatedRangeSizeWorkload> GetEstimatedRangeSizeWorkloadFactory("GetEstimatedRangeSize", false);