Skip to content

Commit 137c373

Browse files
committed
Add exponential backoff
1 parent 3cd9ad0 commit 137c373

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/main/java/com/googlecode/objectify/impl/TransactorNo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public <R> R transactNew(final ObjectifyImpl parent, int limitTries, final Work<
110110
if (--limitTries > 0) {
111111
log.warn("Retrying {} failure for {}: {}", ex.getReason(), work, ex);
112112
log.trace("Details of transaction failure", ex);
113+
try {
114+
// Do increasing backoffs with randomness
115+
Thread.sleep(Math.min(10000, (long) (0.5 * Math.random() + 0.5) * 200 * (ORIGINAL_TRIES - limitTries + 2)));
116+
} catch (InterruptedException ignored) {
117+
}
113118
} else {
114119
throw new DatastoreException(ex.getCode(), "Failed retrying datastore " + ORIGINAL_TRIES + " times ", ex.getReason(), ex);
115120
}

0 commit comments

Comments
 (0)