Search in sources :

Example 1 with NormalAutoCommitNodesHandler

use of com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoCommitNodesHandler in project dble by actiontech.

the class MultiNodeQueryHandler method handleEndPacket.

protected void handleEndPacket(byte[] data, AutoTxOperation txOperation, BackendConnection conn) {
    ServerConnection source = session.getSource();
    if (source.isAutocommit() && !source.isTxStart() && conn.isModifiedSQLExecuted()) {
        if (nodeCount < 0) {
            return;
        }
        // Implicit Distributed Transaction,send commit or rollback automatically
        if (txOperation == AutoTxOperation.COMMIT) {
            if (!conn.isDDL()) {
                session.checkBackupStatus();
            }
            if (session.getXaState() == null) {
                NormalAutoCommitNodesHandler autoHandler = new NormalAutoCommitNodesHandler(session, data);
                autoHandler.commit();
            } else {
                XAAutoCommitNodesHandler autoHandler = new XAAutoCommitNodesHandler(session, data, rrs.getNodes());
                autoHandler.commit();
            }
        } else {
            if (session.getXaState() == null) {
                NormalAutoRollbackNodesHandler autoHandler = new NormalAutoRollbackNodesHandler(session, data, rrs.getNodes(), errConnection);
                autoHandler.rollback();
            } else {
                XAAutoRollbackNodesHandler autoHandler = new XAAutoRollbackNodesHandler(session, data, rrs.getNodes(), errConnection);
                autoHandler.rollback();
            }
        }
    } else {
        boolean inTransaction = !source.isAutocommit() || source.isTxStart();
        if (!inTransaction) {
            session.releaseConnection(conn);
        }
        // Explicit Distributed Transaction
        if (inTransaction && (AutoTxOperation.ROLLBACK == txOperation)) {
            source.setTxInterrupt("ROLLBACK");
        }
        if (nodeCount == 0) {
            session.setResponseTime();
            session.getSource().write(data);
        }
    }
}
Also used : NormalAutoRollbackNodesHandler(com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoRollbackNodesHandler) XAAutoRollbackNodesHandler(com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoRollbackNodesHandler) XAAutoCommitNodesHandler(com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoCommitNodesHandler) ServerConnection(com.actiontech.dble.server.ServerConnection) NormalAutoCommitNodesHandler(com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoCommitNodesHandler)

Aggregations

NormalAutoCommitNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoCommitNodesHandler)1 NormalAutoRollbackNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoRollbackNodesHandler)1 XAAutoCommitNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoCommitNodesHandler)1 XAAutoRollbackNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoRollbackNodesHandler)1 ServerConnection (com.actiontech.dble.server.ServerConnection)1