Source:
<code>protected boolean afterCommit() { boolean inTransaction = false; try { Map<Long, Integer> delayedRemoveAttemptsMap = new HashMap<>(); while (!stressor.isTerminated()) { try { <START> if (inTransaction || ongoingTx != null) { <END> try { ongoingTx.rollback(); } catch (Exception e) { log.error("Failed to rollback ongoing transaction.", e); } } startTransaction(); inTransaction = true; for (DelayedRemove delayedRemove : delayedRemoves.values()) { try { if (manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts() >= 0) { Integer currentDelayedRemoveAttempts = delayedRemoveAttemptsMap.get(delayedRemove.keyId); if (currentDelayedRemoveAttempts != null && currentDelayedRemoveAttempts > manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts()) { log.errorf("Maximum number of delayed remove attempts on key %s attained, reporting.", keyGenerator.generateKey(delayedRemove.keyId)); manager.getFailureManager().reportDelayedRemoveError(); stressor.requestTerminate(); return false; } } checkedRemoveValue(delayedRemove.keyId, delayedRemove.oldValue); } catch (Exception e) { if (manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts() >= 0) { if (!delayedRemoveAttemptsMap.containsKey(delayedRemove.keyId)) { delayedRemoveAttemptsMap.put(delayedRemove.keyId, 1); } else { delayedRemoveAttemptsMap.put(delayedRemove.keyId, delayedRemoveAttemptsMap.get(delayedRemove.keyId) + 1); } } throw e; } } ongoingTx.commit(); lastSuccessfulTxTimestamp = System.currentTimeMillis(); inTransaction = false; delayedRemoves.clear(); return true; } catch (Exception e) { log.error("Error while executing delayed removes.", e); } } } finally { clearTransaction(); } return true; }</code><technical_language>need inTransaction variable if ongoingTx != null signalizes in tx. is reasonable case inTransaction == false && ongoingTx != null</technical_language>

Target:
protected boolean afterCommit() { try { int delayedRemoveAttempts = 0; while (!stressor.isTerminated()) { boolean delayedRemoveError = false; try { if (ongoingTx != null) { try { ongoingTx.rollback(); } catch (Exception e) { log.error("Failed to rollback ongoing transaction", e); } } startTransaction(); for (DelayedRemove delayedRemove : delayedRemoves.values()) { try { if (manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts() >= 0 && delayedRemoveAttempts > manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts()) { log.errorf("Maximum number of delayed remove attempts on key %s attained, reporting.", keyGenerator.generateKey(delayedRemove.keyId)); manager.getFailureManager().reportDelayedRemoveError(); stressor.requestTerminate(); return false; } checkedRemoveValue(delayedRemove.keyId, delayedRemove.oldValue); } catch (Exception e) { if (manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts() >= 0) { delayedRemoveAttempts++; } delayedRemoveError = true; throw e; } } ongoingTx.commit(); lastSuccessfulTxTimestamp = System.currentTimeMillis(); delayedRemoves.clear(); return true; } catch (Exception e) { if (!delayedRemoveError && manager.getLogLogicConfiguration().getMaxDelayedRemoveAttempts() >= 0) { delayedRemoveAttempts++; } log.error("Error while executing delayed removes.", e); } finally { delayedRemoveError = false; } } } finally { clearTransaction(); } return true; }