From 55404d0cd874a18abe47a2a74a22ca682b315bf7 Mon Sep 17 00:00:00 2001 From: "A.J. Beamon" Date: Tue, 28 Jun 2022 16:41:57 -0700 Subject: [PATCH] Add a helper to simulate a commit that can fail with unknown result or take a long time --- .../fdbclient/TenantManagement.actor.h | 21 ++---------- flow/include/flow/genericactors.actor.h | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/fdbclient/include/fdbclient/TenantManagement.actor.h b/fdbclient/include/fdbclient/TenantManagement.actor.h index e480291ffd..b951c1dfb5 100644 --- a/fdbclient/include/fdbclient/TenantManagement.actor.h +++ b/fdbclient/include/fdbclient/TenantManagement.actor.h @@ -160,15 +160,7 @@ Future createTenant(Reference db, TenantName name) { tr->set(tenantLastIdKey, TenantMapEntry::idToPrefix(tenantId)); state std::pair 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 deleteTenant(Reference 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(); diff --git a/flow/include/flow/genericactors.actor.h b/flow/include/flow/genericactors.actor.h index 4955fb6212..c4520dde22 100644 --- a/flow/include/flow/genericactors.actor.h +++ b/flow/include/flow/genericactors.actor.h @@ -1921,6 +1921,39 @@ Future forward(Future from, Promise to) { } } +ACTOR template +Future 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