Search in sources :

Example 6 with MySQLConnection

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

the class XARollbackNodesHandler method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    this.waitUntilSendFinish();
    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_ROLLBACK_FAILED_STATE || 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();
            }
        // we don't know if the conn prepared or not
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
            ErrorPacket errPacket = new ErrorPacket();
            errPacket.read(err);
            if (errPacket.getErrNo() == ErrorCode.ER_XAER_NOTA) {
                // ERROR 1397 (XAE04): XAER_NOTA: Unknown XID, not prepared
                mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_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 {
                session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
                XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
                if (decrementCountBy(1)) {
                    cleanAndFeedback();
                }
            }
        } else {
            LOGGER.info("Wrong XA status flag!");
        }
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 7 with MySQLConnection

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

the class XARollbackNodesHandler method connectionError.

@Override
public void connectionError(Throwable e, BackendConnection conn) {
    this.waitUntilSendFinish();
    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();
            }
        // we don't know if the conn prepared or not
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
            session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                cleanAndFeedback();
            }
        } else {
            LOGGER.info("Wrong XA status flag!");
        }
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 8 with MySQLConnection

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

the class XARollbackNodesHandler method okResponse.

@Override
public void okResponse(byte[] ok, BackendConnection conn) {
    this.waitUntilSendFinish();
    if (conn instanceof MySQLConnection) {
        MySQLConnection mysqlCon = (MySQLConnection) conn;
        if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
            mysqlCon.setXaStatus(TxState.TX_ENDED_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.setXaStatus(TxState.TX_ROLLBACKED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_INITIALIZE_STATE);
                cleanAndFeedback();
            }
        // 'xa rollback' ok
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE || mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE) {
            // we don't know if the conn prepared or not
            mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_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 {
            LOGGER.info("Wrong XA status flag!");
        }
    }
}
Also used : MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 9 with MySQLConnection

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

the class ReloadConfig method recycleOldBackendConnections.

private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
    /* 2.4 put the old connection into a queue */
    Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
    for (PhysicalDBPool dbPool : oldDataHosts.values()) {
        dbPool.stopHeartbeat();
        for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
            for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
                for (BackendConnection con : processor.getBackends().values()) {
                    if (con instanceof MySQLConnection) {
                        MySQLConnection mysqlCon = (MySQLConnection) con;
                        if (mysqlCon.getPool() == ds) {
                            if (con.isBorrowed()) {
                                if (closeFrontCon) {
                                    findAndcloseFrontCon(con);
                                } else {
                                    NIOProcessor.BACKENDS_OLD.add(con);
                                }
                            } else {
                                con.close("old idle conn for reload");
                            }
                        }
                    }
                }
            }
        }
    }
    LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 10 with MySQLConnection

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

the class ShowBackend method getRow.

private static RowDataPacket getRow(BackendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    if (!(c instanceof MySQLConnection)) {
        return null;
    }
    MySQLConnection conn = (MySQLConnection) c;
    row.add(conn.getProcessor().getName().getBytes());
    row.add(LongUtil.toBytes(c.getId()));
    row.add(LongUtil.toBytes(conn.getThreadId()));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
    row.add(c.isBorrowed() ? "true".getBytes() : "false".getBytes());
    row.add(IntegerUtil.toBytes(conn.getWriteQueue().size()));
    row.add(conn.getSchema().getBytes());
    row.add(conn.getCharset().getClient().getBytes());
    row.add(conn.getCharset().getCollation().getBytes());
    row.add(conn.getCharset().getResults().getBytes());
    row.add((conn.getTxIsolation() + "").getBytes());
    row.add((conn.isAutocommit() + "").getBytes());
    row.add(StringUtil.encode(conn.getStringOfSysVariables(), charset));
    row.add(StringUtil.encode(conn.getStringOfUsrVariables(), charset));
    row.add(StringUtil.encode(conn.getXaStatus().toString(), charset));
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) 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