Search in sources :

Example 16 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class AbstractCommitNodesHandler method commit.

@Override
public void commit() {
    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 commit
    if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
        if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
            return;
        }
    }
    try {
        sendFinishedFlag = false;
        for (RouteResultsetNode rrn : session.getTargetKeys()) {
            final BackendConnection conn = session.getTarget(rrn);
            conn.setResponseHandler(this);
            if (!executeCommit((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 17 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class NormalRollbackNodesHandler method rollback.

public void rollback() {
    final int initCount = session.getTargetCount();
    lock.lock();
    try {
        reset(initCount);
    } finally {
        lock.unlock();
    }
    int position = 0;
    for (final RouteResultsetNode node : session.getTargetKeys()) {
        final BackendConnection conn = session.getTarget(node);
        if (conn.isClosed()) {
            lock.lock();
            try {
                nodeCount--;
            } finally {
                lock.unlock();
            }
            continue;
        }
        position++;
        conn.setResponseHandler(this);
        conn.rollback();
    }
    if (position == 0) {
        if (sendData == null) {
            sendData = OkPacket.OK;
        }
        cleanAndFeedback();
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 18 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection 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 19 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection 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 20 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class ShowBackend method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    byte packetId = EOF.getPacketId();
    for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if (bc != null) {
                RowDataPacket row = getRow(bc, c.getCharset().getResults());
                if (row != null) {
                    row.setPacketId(++packetId);
                    buffer = row.write(buffer, c, true);
                }
            }
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

BackendConnection (com.actiontech.dble.backend.BackendConnection)29 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)12 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)8 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)7 NIOProcessor (com.actiontech.dble.net.NIOProcessor)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 IOException (java.io.IOException)3 ServerConfig (com.actiontech.dble.config.ServerConfig)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 ServerConnection (com.actiontech.dble.server.ServerConnection)2 ByteBuffer (java.nio.ByteBuffer)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConQueue (com.actiontech.dble.backend.ConQueue)1 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 GetConnectionHandler (com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler)1 NewConnectionRespHandler (com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler)1 ArrayMinHeap (com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap)1