Add a helper to simulate a commit that can fail with unknown result or take a long time

This commit is contained in:
A.J. Beamon 2022-06-28 16:41:57 -07:00
parent cc93dfd289
commit 55404d0cd8
2 changed files with 35 additions and 19 deletions
fdbclient/include/fdbclient
flow/include/flow

View File

@ -160,15 +160,7 @@ Future<TenantMapEntry> createTenant(Reference<DB> db, TenantName name) {
tr->set(tenantLastIdKey, TenantMapEntry::idToPrefix(tenantId));
state std::pair<TenantMapEntry, bool> newTenant = wait(createTenantTransaction(tr, name, tenantId));
if (BUGGIFY) {
throw commit_unknown_result();
}
wait(safeThreadFutureToFuture(tr->commit()));
if (BUGGIFY) {
throw commit_unknown_result();
}
wait(buggifiedCommit(tr, BUGGIFY_WITH_PROB(0.1)));
TraceEvent("CreatedTenant")
.detail("Tenant", name)
@ -226,16 +218,7 @@ Future<Void> deleteTenant(Reference<DB> db, TenantName name) {
}
wait(deleteTenantTransaction(tr, name));
if (BUGGIFY) {
throw commit_unknown_result();
}
wait(safeThreadFutureToFuture(tr->commit()));
if (BUGGIFY) {
throw commit_unknown_result();
}
wait(buggifiedCommit(tr, BUGGIFY_WITH_PROB(0.1)));
TraceEvent("DeletedTenant").detail("Tenant", name).detail("Version", tr->getCommittedVersion());
return Void();

View File

@ -1921,6 +1921,39 @@ Future<T> forward(Future<T> from, Promise<T> to) {
}
}
ACTOR template <class Transaction>
Future<Void> buggifiedCommit(Transaction tr, bool buggify, int delayDuration = 60.0) {
state int buggifyPoint = 0;
if (buggify) {
buggifyPoint = deterministicRandom()->randomInt(1, 5);
}
// Simulate an unknown result that didn't commit
if (buggifyPoint == 1) {
throw commit_unknown_result();
}
// Simulate a long delay before commit that could trigger a timeout
if (buggifyPoint == 2) {
wait(delay(delayDuration));
}
wait(safeThreadFutureToFuture(tr->commit()));
// Simulate a long delay that could trigger a timeout where the transaction
// successfully committed
if (buggifyPoint == 3) {
wait(delay(delayDuration));
}
// Simulate an unknown result that did commit
if (buggifyPoint == 4) {
throw commit_unknown_result();
}
return Void();
}
// Monad
ACTOR template <class Fun, class T>