Search in sources :

Example 21 with MySQLConnection

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

the class XARollbackNodesHandler method rollbackPhase.

private void rollbackPhase(MySQLConnection mysqlCon) {
    if (mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
        MySQLConnection newConn = session.freshConn(mysqlCon, this);
        if (!newConn.equals(mysqlCon)) {
            mysqlCon = newConn;
            String xaTxId = mysqlCon.getConnXID(session);
            mysqlCon.execCmd("XA ROLLBACK " + xaTxId + ";");
        } else if (decrementCountBy(1)) {
            cleanAndFeedback();
        }
    } else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
        String xaTxId = mysqlCon.getConnXID(session);
        mysqlCon.execCmd("XA ROLLBACK " + xaTxId + ";");
    } else if (mysqlCon.getXaStatus() == TxState.TX_CONN_QUIT || mysqlCon.getXaStatus() == TxState.TX_ROLLBACKED_STATE) {
        if (decrementCountBy(1)) {
            cleanAndFeedback();
        }
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 22 with MySQLConnection

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

the class XARollbackNodesHandler method rollback.

public void rollback() {
    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 rollback
    if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
        if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
            return;
        }
    }
    try {
        sendFinishedFlag = false;
        for (final RouteResultsetNode node : session.getTargetKeys()) {
            final BackendConnection conn = session.getTarget(node);
            conn.setResponseHandler(this);
            if (!executeRollback((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 23 with MySQLConnection

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

the class XARollbackNodesHandler method connectionClose.

@Override
public void connectionClose(BackendConnection conn, String reason) {
    this.waitUntilSendFinish();
    this.setFail(reason);
    if (conn instanceof MySQLConnection) {
        MySQLConnection mysqlCon = (MySQLConnection) conn;
        if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_ENDED_STATE);
                rollback();
            }
        // 'xa rollback' ok without prepared
        } else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_INITIALIZE_STATE);
                cleanAndFeedback();
            }
        // 'xa rollback' err
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
            mysqlCon.setXaStatus(TxState.TX_ROLLBACK_FAILED_STATE);
            mysqlCon.quit();
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
            if (decrementCountBy(1)) {
                cleanAndFeedback();
            }
        } else {
            LOGGER.info("Wrong XA status flag!");
        }
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 24 with MySQLConnection

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

the class ShowBackendStat method stat.

private static HashMap<String, BackendStat> stat() {
    HashMap<String, BackendStat> all = new HashMap<String, BackendStat>();
    for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if ((bc == null) || !(bc instanceof MySQLConnection)) {
                break;
            }
            MySQLConnection con = (MySQLConnection) bc;
            String host = con.getHost();
            long port = con.getPort();
            BackendStat info = all.get(host + Long.toString(port));
            if (info == null) {
                info = new BackendStat(host, port);
                all.put(host + Long.toString(port), info);
            }
            if (con.isBorrowed()) {
                info.addActive();
            }
            info.addTotal();
        }
    }
    return all;
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) HashMap(java.util.HashMap) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 25 with MySQLConnection

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

the class ReloadConfig method findAndcloseFrontCon.

private static void findAndcloseFrontCon(BackendConnection con) {
    if (con instanceof MySQLConnection) {
        MySQLConnection mcon1 = (MySQLConnection) con;
        for (NIOProcessor processor : DbleServer.getInstance().getFrontProcessors()) {
            for (FrontendConnection fcon : processor.getFrontends().values()) {
                if (fcon instanceof ServerConnection) {
                    ServerConnection scon = (ServerConnection) fcon;
                    Map<RouteResultsetNode, BackendConnection> bons = scon.getSession2().getTargetMap();
                    for (BackendConnection bcon : bons.values()) {
                        if (bcon instanceof MySQLConnection) {
                            MySQLConnection mcon2 = (MySQLConnection) bcon;
                            if (mcon1 == mcon2) {
                                scon.killAndClose("reload config all");
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ServerConnection(com.actiontech.dble.server.ServerConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor) 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