Skip to content

Commit

Permalink
optimize: branch transaction repeated reporting false (apache#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjinlei authored and xingfudeshi committed Sep 17, 2019
1 parent 520c5ca commit ebcae5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ protected T executeAutoCommitTrue(Object[] args) throws Throwable {
} catch (Exception e) {
// when exception occur in finally,this exception will lost, so just print it here
LOGGER.error("execute executeAutoCommitTrue error:{}", e.getMessage(), e);
connectionProxy.rollback();
if (!LockRetryPolicy.isLockRetryPolicyBranchRollbackOnConflict()) {
connectionProxy.getTargetConnection().rollback();
}
throw e;
} finally {
((ConnectionProxy) connectionProxy).getContext().reset();
Expand Down Expand Up @@ -140,5 +142,9 @@ public <T> T execute(Callable<T> callable) throws Exception {
protected void onException(Exception e) throws Exception {
connection.rollback();
}

public static boolean isLockRetryPolicyBranchRollbackOnConflict() {
return LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ public void testLockRetryPolicyRollbackOnConflict() throws Exception {
boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
branchRollbackFlagField.set(null, true);
Assertions.assertThrows(LockWaitTimeoutException.class, executor::execute);
Mockito.verify(connectionProxy, Mockito.times(1))
.rollback();
Mockito.verify(connectionProxy.getTargetConnection(), Mockito.atLeastOnce())
.rollback();
Mockito.verify(connectionProxy, Mockito.never()).rollback();
branchRollbackFlagField.set(null, oldBranchRollbackFlag);
}

Expand All @@ -95,10 +94,8 @@ public void testLockRetryPolicyNotRollbackOnConflict() throws Throwable {
boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
branchRollbackFlagField.set(null, false);
Assertions.assertThrows(LockConflictException.class, executor::execute);
Mockito.verify(connectionProxy, Mockito.times(1))
.rollback();
Mockito.verify(connectionProxy.getTargetConnection(), Mockito.never())
.rollback();
Mockito.verify(connectionProxy.getTargetConnection(), Mockito.times(1)).rollback();
Mockito.verify(connectionProxy, Mockito.never()).rollback();
branchRollbackFlagField.set(null, oldBranchRollbackFlag);
}
}

0 comments on commit ebcae5f

Please sign in to comment.