Search in sources :

Example 11 with ServerConnection

use of com.actiontech.dble.server.ServerConnection 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)

Example 12 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class NIOProcessor method frontendCheck.

private void frontendCheck() {
    Iterator<Entry<Long, FrontendConnection>> it = frontends.entrySet().iterator();
    while (it.hasNext()) {
        FrontendConnection c = it.next().getValue();
        // remove empty conn
        if (c == null) {
            it.remove();
            this.frontEndsLength.decrementAndGet();
            continue;
        }
        // clean closed conn or check timeout
        if (c.isClosed()) {
            c.cleanup();
            it.remove();
            this.frontEndsLength.decrementAndGet();
        } else {
            // very important ,for some data maybe not sent
            checkConSendQueue(c);
            if (c instanceof ServerConnection && c.isIdleTimeout()) {
                ServerConnection s = (ServerConnection) c;
                TxState state = s.getSession2().getXaState();
                if (state != null && state != TxState.TX_INITIALIZE_STATE) {
                    if (state != TxState.TX_COMMIT_FAILED_STATE && state != TxState.TX_ROLLBACK_FAILED_STATE) {
                        // Active/IDLE/PREPARED XA FrontendS will be rollbacked
                        s.close("Idle Timeout");
                        DbleServer.getInstance().getXaSessionCheck().addRollbackSession(s.getSession2());
                    }
                    continue;
                }
            }
            c.idleCheck();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TxState(com.actiontech.dble.backend.mysql.xa.TxState) ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 13 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class MultiNodeQueryHandler method rowEofResponse.

@Override
public void rowEofResponse(final byte[] eof, boolean isLeft, BackendConnection conn) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("on row end response " + conn);
    }
    this.netOutBytes += eof.length;
    if (errorResponse.get()) {
        return;
    }
    final ServerConnection source = session.getSource();
    if (!rrs.isCallStatement()) {
        if (clearIfSessionClosed(session)) {
            return;
        } else {
            session.releaseConnectionIfSafe(conn, false);
        }
    }
    if (decrementCountBy(1)) {
        if (!rrs.isCallStatement() || (rrs.isCallStatement() && rrs.getProcedure().isResultSimpleValue())) {
            if (this.sessionAutocommit && !session.getSource().isTxStart() && !session.getSource().isLocked()) {
                // clear all connections
                session.releaseConnections(false);
            }
            if (this.isFail() || session.closed()) {
                tryErrorFinished(true);
                return;
            }
        }
        session.setResponseTime();
        writeEofResult(eof, source);
        doSqlStat(source);
    }
}
Also used : ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 14 with ServerConnection

use of com.actiontech.dble.server.ServerConnection 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)

Example 15 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class MultiNodeQueryHandler method executeFieldEof.

private void executeFieldEof(byte[] header, List<byte[]> fields, byte[] eof) {
    ServerConnection source = session.getSource();
    fieldCount = fields.size();
    header[3] = ++packetId;
    byteBuffer = source.writeToBuffer(header, byteBuffer);
    String primaryKey = null;
    if (rrs.hasPrimaryKeyToCache()) {
        String[] items = rrs.getPrimaryKeyItems();
        primaryKeyTable = items[0];
        primaryKey = items[1];
    }
    for (int i = 0, len = fieldCount; i < len; ++i) {
        byte[] field = fields.get(i);
        FieldPacket fieldPkg = new FieldPacket();
        fieldPkg.read(field);
        if (rrs.getSchema() != null) {
            fieldPkg.setDb(rrs.getSchema().getBytes());
        }
        if (rrs.getTableAlias() != null) {
            fieldPkg.setTable(rrs.getTableAlias().getBytes());
        }
        if (rrs.getTable() != null) {
            fieldPkg.setOrgTable(rrs.getTable().getBytes());
        }
        fieldPackets.add(fieldPkg);
        fieldCount = fields.size();
        if (primaryKey != null && primaryKeyIndex == -1) {
            // find primary key index
            String fieldName = new String(fieldPkg.getName());
            if (primaryKey.equalsIgnoreCase(fieldName)) {
                primaryKeyIndex = i;
            }
        }
        fieldPkg.setPacketId(++packetId);
        byteBuffer = fieldPkg.write(byteBuffer, source, false);
    }
    eof[3] = ++packetId;
    byteBuffer = source.writeToBuffer(eof, byteBuffer);
}
Also used : ServerConnection(com.actiontech.dble.server.ServerConnection)

Aggregations

ServerConnection (com.actiontech.dble.server.ServerConnection)20 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 NIOProcessor (com.actiontech.dble.net.NIOProcessor)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)2 ByteBuffer (java.nio.ByteBuffer)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)1 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)1 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 TxState (com.actiontech.dble.backend.mysql.xa.TxState)1 ServerConfig (com.actiontech.dble.config.ServerConfig)1 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 MySQLItemVisitor (com.actiontech.dble.plan.visitor.MySQLItemVisitor)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1 NonBlockingSession (com.actiontech.dble.server.NonBlockingSession)1