Search in sources :

Example 16 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class AbstractCommitNodesHandler method commit.

@Override
public void commit() {
    final int initCount = session.getTargetCount();
    lock.lock();
    try {
        reset(initCount);
    } finally {
        lock.unlock();
    }
    int position = 0;
    // then the XA transaction will be not killed, if killed ,then we will not commit
    if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
        if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
            return;
        }
    }
    try {
        sendFinishedFlag = false;
        for (RouteResultsetNode rrn : session.getTargetKeys()) {
            final BackendConnection conn = session.getTarget(rrn);
            conn.setResponseHandler(this);
            if (!executeCommit((MySQLConnection) conn, position++)) {
                break;
            }
        }
    } finally {
        lockForErrorHandle.lock();
        try {
            sendFinishedFlag = true;
            sendFinished.signalAll();
        } finally {
            lockForErrorHandle.unlock();
        }
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 17 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class XACommitNodesHandler method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    this.waitUntilSendFinish();
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.read(err);
    String errMsg = new String(errPacket.getMessage());
    this.setFail(errMsg);
    sendData = makeErrorPacket(errMsg);
    if (conn instanceof MySQLConnection) {
        MySQLConnection mysqlCon = (MySQLConnection) conn;
        if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_ENDED_STATE);
                nextParse();
            }
        // 'xa prepare' error
        } else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                if (session.getXaState() == TxState.TX_ENDED_STATE) {
                    session.setXaState(TxState.TX_PREPARED_STATE);
                }
                nextParse();
            }
        // 'xa commit' err
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
            // TODO:service degradation?
            mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
            if (decrementCountBy(1)) {
                cleanAndFeedback();
            }
        } else if (mysqlCon.getXaStatus() == TxState.TX_COMMIT_FAILED_STATE) {
            if (errPacket.getErrNo() == ErrorCode.ER_XAER_NOTA) {
                // Unknown XID ,if xa transaction only contains select statement, xid will lost after restart server although prepared
                mysqlCon.setXaStatus(TxState.TX_COMMITTED_STATE);
                XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
                mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
                if (decrementCountBy(1)) {
                    if (session.getXaState() == TxState.TX_PREPARED_STATE) {
                        session.setXaState(TxState.TX_INITIALIZE_STATE);
                    }
                    cleanAndFeedback();
                }
            } else {
                mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
                XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
                session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
                if (decrementCountBy(1)) {
                    cleanAndFeedback();
                }
            }
        }
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 18 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class XACommitNodesHandler method okResponse.

@Override
public void okResponse(byte[] ok, BackendConnection conn) {
    this.waitUntilSendFinish();
    MySQLConnection mysqlCon = (MySQLConnection) conn;
    TxState state = mysqlCon.getXaStatus();
    if (state == TxState.TX_STARTED_STATE) {
        mysqlCon.setXaStatus(TxState.TX_ENDED_STATE);
        XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
        if (decrementCountBy(1)) {
            session.setXaState(TxState.TX_ENDED_STATE);
            nextParse();
        }
    } else if (state == TxState.TX_ENDED_STATE) {
        // PREPARE OK
        mysqlCon.setXaStatus(TxState.TX_PREPARED_STATE);
        XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
        if (decrementCountBy(1)) {
            if (session.getXaState() == TxState.TX_ENDED_STATE) {
                session.setXaState(TxState.TX_PREPARED_STATE);
            }
            nextParse();
        }
    } else if (state == TxState.TX_COMMIT_FAILED_STATE || state == TxState.TX_PREPARED_STATE) {
        // COMMIT OK
        // XA reset status now
        mysqlCon.setXaStatus(TxState.TX_COMMITTED_STATE);
        XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
        mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
        if (decrementCountBy(1)) {
            if (session.getXaState() == TxState.TX_PREPARED_STATE) {
                session.setXaState(TxState.TX_INITIALIZE_STATE);
            }
            cleanAndFeedback();
        }
    }
}
Also used : TxState(com.actiontech.dble.backend.mysql.xa.TxState) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 19 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class XACommitNodesHandler method innerConnectError.

private void innerConnectError(BackendConnection conn) {
    if (conn instanceof MySQLConnection) {
        MySQLConnection mysqlCon = (MySQLConnection) conn;
        if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_ENDED_STATE);
                nextParse();
            }
        // 'xa prepare' connectionClose,conn has quit
        } else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
            mysqlCon.setXaStatus(TxState.TX_PREPARE_UNCONNECT_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            session.setXaState(TxState.TX_PREPARE_UNCONNECT_STATE);
            if (decrementCountBy(1)) {
                nextParse();
            }
        // 'xa commit' connectionClose
        } else if (mysqlCon.getXaStatus() == TxState.TX_COMMIT_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
            // TODO:service degradation?
            mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
            if (decrementCountBy(1)) {
                cleanAndFeedback();
            }
        }
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 20 with MySQLConnection

use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.

the class XACommitNodesHandler method commitPhase.

private void commitPhase(MySQLConnection mysqlCon) {
    if (session.getXaState() == TxState.TX_COMMIT_FAILED_STATE) {
        MySQLConnection newConn = session.freshConn(mysqlCon, this);
        if (!newConn.equals(mysqlCon)) {
            mysqlCon = newConn;
        } else if (decrementCountBy(1)) {
            cleanAndFeedback();
            return;
        }
    }
    String xaTxId = mysqlCon.getConnXID(session);
    mysqlCon.execCmd("XA COMMIT " + xaTxId);
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Aggregations

MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)34 BackendConnection (com.actiontech.dble.backend.BackendConnection)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)5 HeapItem (com.actiontech.dble.backend.mysql.nio.handler.util.HeapItem)4 NIOProcessor (com.actiontech.dble.net.NIOProcessor)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)3 TwoTableComparator (com.actiontech.dble.backend.mysql.nio.handler.util.TwoTableComparator)2 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)2 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 Entry (java.util.Map.Entry)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 ResetConnHandler (com.actiontech.dble.backend.mysql.nio.handler.ResetConnHandler)1 ArrayMinHeap (com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap)1 TxState (com.actiontech.dble.backend.mysql.xa.TxState)1