-
Notifications
You must be signed in to change notification settings - Fork 19
Description
// pub.dtm.client.barrier.BranchBarrier#insertBarrier
private boolean insertBarrier(Connection connection) throws SQLException {
log.info("insert barrier {}", this);
if (Objects.isNull(connection)) {
return false;
}
PreparedStatement preparedStatement = null;
try {
String sql = "insert ignore into barrier(trans_type, gid, branch_id, op, barrier_id, reason) values(?,?,?,?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, this.getTransTypeEnum().getValue());
preparedStatement.setString(2, this.getGid());
preparedStatement.setString(3, branchId);
preparedStatement.setString(4, op);
preparedStatement.setString(5, String.format("%02d", barrierId));
preparedStatement.setString(6, op);
if (preparedStatement.executeUpdate() == 0) {
return false;
}
if (ParamFieldConstants.CANCEL.equals(op)) {
int opIndex = 4;
preparedStatement.setString(opIndex, ParamFieldConstants.TRY);
if (preparedStatement.executeUpdate() > 0) {
return false;
}
}
} finally {
if (Objects.nonNull(preparedStatement)) {
preparedStatement.close();
}
}
return true;
}
这个地方,只判断了ParamFieldConstants.CANCEL.equals(op),而Saga模式的补偿op是compensate,不是cancel