Search in sources :

Example 21 with BackendConnection

use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.

the class NIOProcessor method backendCheck.

// 后端连接检查
private void backendCheck() {
    long sqlTimeout = MycatServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
    Iterator<Entry<Long, BackendConnection>> it = backends.entrySet().iterator();
    while (it.hasNext()) {
        BackendConnection c = it.next().getValue();
        // 删除空连接
        if (c == null) {
            it.remove();
            continue;
        }
        // SQL执行超时的连接关闭
        if (c.isBorrowed() && c.getLastTime() < TimeUtil.currentTimeMillis() - sqlTimeout) {
            LOGGER.warn("found backend connection SQL timeout ,close it " + c);
            c.close("sql timeout");
        }
        // 清理已关闭连接,否则空闲检查。
        if (c.isClosed()) {
            it.remove();
        } else {
            // very important ,for some data maybe not sent
            if (c instanceof AbstractConnection) {
                checkConSendQueue((AbstractConnection) c);
            }
            c.idleCheck();
        }
    }
}
Also used : Entry(java.util.Map.Entry) BackendConnection(io.mycat.backend.BackendConnection)

Example 22 with BackendConnection

use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.

the class NonBlockingSession method closeAndClearResources.

public void closeAndClearResources(String reason) {
    for (BackendConnection node : target.values()) {
        node.close(reason);
    }
    target.clear();
    clearHandlesResources();
}
Also used : BackendConnection(io.mycat.backend.BackendConnection)

Example 23 with BackendConnection

use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.

the class NonBlockingSession method releaseConnection.

public void releaseConnection(RouteResultsetNode rrn, boolean debug, final boolean needRollback) {
    BackendConnection c = target.remove(rrn);
    if (c != null) {
        if (debug) {
            LOGGER.debug("release connection " + c);
        }
        if (c.getAttachment() != null) {
            c.setAttachment(null);
        }
        if (!c.isClosedOrQuit()) {
            if (c.isAutocommit()) {
                c.release();
            } else //if (needRollback)
            {
                c.setResponseHandler(new RollbackReleaseHandler());
                c.rollback();
            }
        //else {
        //	c.release();
        //}
        }
    }
}
Also used : BackendConnection(io.mycat.backend.BackendConnection)

Example 24 with BackendConnection

use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.

the class NonBlockingSession method releaseConnection.

public void releaseConnection(BackendConnection con) {
    Iterator<Entry<RouteResultsetNode, BackendConnection>> itor = target.entrySet().iterator();
    while (itor.hasNext()) {
        BackendConnection theCon = itor.next().getValue();
        if (theCon == con) {
            itor.remove();
            con.release();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("realse connection " + con);
            }
            break;
        }
    }
}
Also used : Entry(java.util.Map.Entry) BackendConnection(io.mycat.backend.BackendConnection)

Example 25 with BackendConnection

use of io.mycat.backend.BackendConnection in project Mycat-Server by MyCATApache.

the class NonBlockingSession method commit.

public void commit() {
    final int initCount = target.size();
    if (initCount <= 0) {
        ByteBuffer buffer = source.allocate();
        buffer = source.writeToBuffer(OkPacket.OK, buffer);
        source.write(buffer);
        return;
    } else if (initCount == 1) {
        BackendConnection con = target.elements().nextElement();
        commitHandler.commit(con);
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("multi node commit to send ,total " + initCount);
        }
        checkDistriTransaxAndExecute();
    }
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BackendConnection (io.mycat.backend.BackendConnection)25 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)6 MycatConfig (io.mycat.config.MycatConfig)6 MySQLConnection (io.mycat.backend.mysql.nio.MySQLConnection)3 NIOProcessor (io.mycat.net.NIOProcessor)3 RowDataPacket (io.mycat.net.mysql.RowDataPacket)3 ByteBuffer (java.nio.ByteBuffer)3 Entry (java.util.Map.Entry)3 ConQueue (io.mycat.backend.ConQueue)2 EOFPacket (io.mycat.net.mysql.EOFPacket)2 FieldPacket (io.mycat.net.mysql.FieldPacket)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)1 JDBCConnection (io.mycat.backend.jdbc.JDBCConnection)1 GetConnectionHandler (io.mycat.backend.mysql.nio.handler.GetConnectionHandler)1 CoordinatorLogEntry (io.mycat.backend.mysql.xa.CoordinatorLogEntry)1