Search in sources :

Example 21 with MySQLDataNode

use of com.alibaba.cobar.mysql.MySQLDataNode in project cobar by alibaba.

the class ShowDataSources method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write field
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    Map<String, MySQLDataNode> nodes = CobarServer.getInstance().getConfig().getDataNodes();
    for (MySQLDataNode node : nodes.values()) {
        RowDataPacket row = getRow(node, c.getCharset());
        row.packetId = ++packetId;
        buffer = row.write(buffer, c);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // post write
    c.write(buffer);
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 22 with MySQLDataNode

use of com.alibaba.cobar.mysql.MySQLDataNode in project cobar by alibaba.

the class NonBlockingSession method kill.

private void kill(Runnable run) {
    boolean hooked = false;
    AtomicInteger count = null;
    Map<RouteResultsetNode, MySQLConnection> killees = null;
    for (RouteResultsetNode node : target.keySet()) {
        MySQLConnection c = target.get(node);
        if (c != null && c.isRunning()) {
            if (!hooked) {
                hooked = true;
                killees = new HashMap<RouteResultsetNode, MySQLConnection>();
                count = new AtomicInteger(0);
            }
            killees.put(node, c);
            count.incrementAndGet();
        }
    }
    if (hooked) {
        for (Entry<RouteResultsetNode, MySQLConnection> en : killees.entrySet()) {
            KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this, run, count);
            CobarConfig conf = CobarServer.getInstance().getConfig();
            MySQLDataNode dn = conf.getDataNodes().get(en.getKey().getName());
            try {
                dn.getConnection(kill, en.getKey());
            } catch (Exception e) {
                LOGGER.error("get killer connection failed for " + en.getKey(), e);
                kill.connectionError(e, null);
            }
        }
    } else {
        run.run();
    }
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) KillConnectionHandler(com.alibaba.cobar.mysql.nio.handler.KillConnectionHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RouteResultsetNode(com.alibaba.cobar.route.RouteResultsetNode) CobarConfig(com.alibaba.cobar.CobarConfig) MySQLConnection(com.alibaba.cobar.mysql.nio.MySQLConnection)

Aggregations

MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)22 CobarConfig (com.alibaba.cobar.CobarConfig)13 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)8 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)6 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)5 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)5 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)5 ByteBuffer (java.nio.ByteBuffer)5 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)4 MySQLConnection (com.alibaba.cobar.mysql.nio.MySQLConnection)3 ArrayList (java.util.ArrayList)3 CobarCluster (com.alibaba.cobar.CobarCluster)2 QuarantineConfig (com.alibaba.cobar.config.model.QuarantineConfig)2 UserConfig (com.alibaba.cobar.config.model.UserConfig)2 UnknownDataNodeException (com.alibaba.cobar.exception.UnknownDataNodeException)2 Channel (com.alibaba.cobar.mysql.bio.Channel)2 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)2 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)2 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2