format code; refactor tenant management workload setup; use fmt::print
This commit is contained in:
parent
07bd4c311b
commit
72597f7db6
|
@ -1168,7 +1168,7 @@ int64_t extractTenantIdFromSingleKeyMutation(MutationRef m) {
|
|||
ASSERT(!isSystemKey(m.param1));
|
||||
|
||||
// The first 8 bytes of the key of this OP is also an 8-byte number
|
||||
if(m.type == MutationRef::SetVersionstampedKey) {
|
||||
if (m.type == MutationRef::SetVersionstampedKey) {
|
||||
return TenantInfo::INVALID_TENANT;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
int maxClearSize;
|
||||
double initialKeyDensity;
|
||||
bool useSystemKeys;
|
||||
bool writeSystemKeys = false; // whether we really write to a system key in the workload
|
||||
KeyRange conflictRange;
|
||||
unsigned int operationId;
|
||||
int64_t maximumTotalData;
|
||||
|
@ -182,8 +183,9 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
minNode = std::max(minNode, nodes - newNodes);
|
||||
nodes = newNodes;
|
||||
|
||||
if (useSystemKeys) {
|
||||
if (useSystemKeys && deterministicRandom()->coinflip()) {
|
||||
keyPrefixes[-1] = "\xff\x01";
|
||||
writeSystemKeys = true;
|
||||
}
|
||||
|
||||
maxClearSize = 1 << deterministicRandom()->randomInt(0, 20);
|
||||
|
@ -375,7 +377,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
break;
|
||||
} catch (Error& e) {
|
||||
if (e.code() == error_code_illegal_tenant_access) {
|
||||
ASSERT(!self->useSystemKeys);
|
||||
ASSERT(!self->writeSystemKeys);
|
||||
ASSERT_EQ(tenantNum, -1);
|
||||
self->illegalTenantAccess = true;
|
||||
break;
|
||||
|
@ -393,7 +395,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
|
||||
loop {
|
||||
try {
|
||||
wait(self->randomTransaction(self) && delay(self->numOps * .001));
|
||||
wait(self->randomTransaction(self, cx) && delay(self->numOps * .001));
|
||||
} catch (Error& e) {
|
||||
if (e.code() != error_code_not_committed)
|
||||
throw e;
|
||||
|
@ -409,7 +411,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
}
|
||||
}
|
||||
|
||||
ACTOR Future<Void> randomTransaction(FuzzApiCorrectnessWorkload* self) {
|
||||
ACTOR Future<Void> randomTransaction(FuzzApiCorrectnessWorkload* self, Database cx) {
|
||||
state Reference<ITransaction> tr;
|
||||
state bool readYourWritesDisabled = deterministicRandom()->coinflip();
|
||||
state bool readAheadDisabled = deterministicRandom()->coinflip();
|
||||
|
@ -494,6 +496,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
|
|||
throw not_committed();
|
||||
} else if (e.code() == error_code_illegal_tenant_access) {
|
||||
ASSERT_EQ(tenantNum, -1);
|
||||
ASSERT_EQ(cx->getTenantMode(), TenantMode::REQUIRED);
|
||||
return Void();
|
||||
}
|
||||
|
||||
|
|
|
@ -177,61 +177,66 @@ struct TenantManagementWorkload : TestWorkload {
|
|||
});
|
||||
}
|
||||
|
||||
ACTOR static Future<Void> _setup(Database cx, TenantManagementWorkload* self) {
|
||||
Reference<IDatabase> threadSafeHandle =
|
||||
wait(unsafeThreadFutureToFuture(ThreadSafeDatabase::createFromExistingDatabase(cx)));
|
||||
// Set a key outside of all tenants to make sure that our tenants aren't writing to the regular key-space
|
||||
Future<Void> writeNonTenantKey() const {
|
||||
return runRYWTransaction(dataDb, [this](Reference<ReadYourWritesTransaction> tr) {
|
||||
tr->setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
tr->set(keyName, noTenantValue);
|
||||
return Future<Void>(Void());
|
||||
});
|
||||
}
|
||||
|
||||
MultiVersionApi::api->selectApiVersion(cx->apiVersion.version());
|
||||
self->mvDb = MultiVersionDatabase::debugCreateFromExistingDatabase(threadSafeHandle);
|
||||
// load test parameters from meta-cluster
|
||||
ACTOR static Future<Void> loadTestParameters(Database cx, TenantManagementWorkload* self) {
|
||||
state Transaction tr(cx);
|
||||
// Read the parameters chosen and saved by client 0
|
||||
loop {
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
Optional<Value> val = wait(tr.get(self->testParametersKey));
|
||||
if (val.present()) {
|
||||
TestParameters params = TestParameters::decode(val.get());
|
||||
self->useMetacluster = params.useMetacluster;
|
||||
return Void();
|
||||
}
|
||||
wait(delay(1.0));
|
||||
tr.reset();
|
||||
} catch (Error& e) {
|
||||
wait(tr.onError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self->useMetacluster && self->clientId == 0) {
|
||||
std::cout << "Start Meta-cluster and register data cluster..."
|
||||
<< "\n";
|
||||
// Configure the metacluster (this changes the tenant mode)
|
||||
// send test parameters from meta-cluster
|
||||
ACTOR static Future<Void> sendTestParameters(Database cx, TenantManagementWorkload* self) {
|
||||
// Communicates test parameters to all other clients by storing it in a key
|
||||
fmt::print("Sending test parameters ...\n");
|
||||
state Transaction tr(cx);
|
||||
loop {
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
tr.set(self->testParametersKey, TestParameters(self->useMetacluster).encode());
|
||||
wait(tr.commit());
|
||||
break;
|
||||
} catch (Error& e) {
|
||||
wait(tr.onError(e));
|
||||
}
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
// only the first client will do this setup
|
||||
ACTOR static Future<Void> firstClientSetup(Database cx, TenantManagementWorkload* self) {
|
||||
if (self->useMetacluster) {
|
||||
fmt::print("Create meta-cluster and register data cluster ... \n");
|
||||
// Configure the meta-cluster (this changes the tenant mode)
|
||||
wait(success(MetaclusterAPI::createMetacluster(cx.getReference(), "management_cluster"_sr)));
|
||||
|
||||
DataClusterEntry entry;
|
||||
entry.capacity.numTenantGroups = 1e9;
|
||||
wait(MetaclusterAPI::registerCluster(
|
||||
self->mvDb, self->dataClusterName, g_simulator->extraDatabases[0], entry));
|
||||
}
|
||||
|
||||
// set/load test parameters from metacluster
|
||||
std::cout << "Communicate test parameters...\n";
|
||||
state Transaction tr(cx);
|
||||
if (self->clientId == 0) {
|
||||
// Communicates test parameters to all other clients by storing it in a key
|
||||
loop {
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
tr.set(self->testParametersKey, TestParameters(self->useMetacluster).encode());
|
||||
wait(tr.commit());
|
||||
break;
|
||||
} catch (Error& e) {
|
||||
wait(tr.onError(e));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Read the parameters chosen and saved by client 0
|
||||
loop {
|
||||
try {
|
||||
tr.setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
Optional<Value> val = wait(tr.get(self->testParametersKey));
|
||||
if (val.present()) {
|
||||
TestParameters params = TestParameters::decode(val.get());
|
||||
self->useMetacluster = params.useMetacluster;
|
||||
break;
|
||||
}
|
||||
|
||||
wait(delay(1.0));
|
||||
tr.reset();
|
||||
} catch (Error& e) {
|
||||
wait(tr.onError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self->useMetacluster) {
|
||||
ASSERT(g_simulator->extraDatabases.size() == 1);
|
||||
self->dataDb = Database::createSimulatedExtraDatabase(g_simulator->extraDatabases[0], cx->defaultTenant);
|
||||
// wait for tenant mode change on dataDB
|
||||
|
@ -239,19 +244,31 @@ struct TenantManagementWorkload : TestWorkload {
|
|||
} else {
|
||||
self->dataDb = cx;
|
||||
}
|
||||
wait(sendTestParameters(cx, self));
|
||||
|
||||
if (self->clientId == 0 && self->dataDb->getTenantMode() != TenantMode::REQUIRED) {
|
||||
// Set a key outside of all tenants to make sure that our tenants aren't writing to the regular key-space
|
||||
state Transaction dataTr(self->dataDb);
|
||||
loop {
|
||||
try {
|
||||
dataTr.setOption(FDBTransactionOptions::RAW_ACCESS);
|
||||
dataTr.set(self->keyName, self->noTenantValue);
|
||||
wait(dataTr.commit());
|
||||
break;
|
||||
} catch (Error& e) {
|
||||
wait(dataTr.onError(e));
|
||||
}
|
||||
if (self->dataDb->getTenantMode() != TenantMode::REQUIRED) {
|
||||
wait(self->writeNonTenantKey());
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
ACTOR static Future<Void> _setup(Database cx, TenantManagementWorkload* self) {
|
||||
Reference<IDatabase> threadSafeHandle =
|
||||
wait(unsafeThreadFutureToFuture(ThreadSafeDatabase::createFromExistingDatabase(cx)));
|
||||
|
||||
MultiVersionApi::api->selectApiVersion(cx->apiVersion.version());
|
||||
self->mvDb = MultiVersionDatabase::debugCreateFromExistingDatabase(threadSafeHandle);
|
||||
|
||||
if (self->clientId == 0) {
|
||||
wait(firstClientSetup(cx, self));
|
||||
} else {
|
||||
wait(loadTestParameters(cx, self));
|
||||
if (self->useMetacluster) {
|
||||
ASSERT(g_simulator->extraDatabases.size() == 1);
|
||||
self->dataDb =
|
||||
Database::createSimulatedExtraDatabase(g_simulator->extraDatabases[0], cx->defaultTenant);
|
||||
} else {
|
||||
self->dataDb = cx;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue