- public void rollback() {
- final intinitCount = session.getTargetCount();
- lock.lock();
- try {
- reset(initCount);
- } finally {
- lock.unlock();
- }
- if (session.closed()) {
- decrementCountToZero();
- return;
- }
- // 执行
- intstarted = 0;
- for(final RouteResultsetNode node : session.getTargetKeys()) {
- if(node ==null) {
- LOGGER.error("null is contained in RoutResultsetNodes, source = "
- + session.getSource());
- continue;
- }
- finalBackendConnection conn = session.getTarget(node);
- if(conn !=null) {
- booleanisClosed=conn.isClosedOrQuit();
- if(isClosed)
- {
- session.getSource().writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR,
- "receive rollback,but find backend con is closed or quit");
- LOGGER.error( conn+"receive rollback,but fond backend con is closed or quit");
- }
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("rollback job run for " + conn);
- }
- if (clearIfSessionClosed(session)) {
- return;
- }
- conn.setResponseHandler(RollbackNodeHandler.this);
- //support the XA rollback
- if(session.getXaTXID()!=null&& conninstanceof MySQLConnection) {
- MySQLConnection mysqlCon = (MySQLConnection) conn;
- String xaTxId = session.getXaTXID();
- //exeBatch cmd issue : the 2nd package can not receive the responsemysqlCon.execCmd("XA END " + xaTxId + ";");
- mysqlCon.execCmd("XA ROLLBACK " + xaTxId + ";");
- }else {
- conn.rollback();
- }
- ++started;
- }
- }
来源: http://www.bubuko.com/infodetail-2003546.html