Search in sources :

Example 6 with MySQLConnection

use of com.alibaba.cobar.mysql.nio.MySQLConnection 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

MySQLConnection (com.alibaba.cobar.mysql.nio.MySQLConnection)6 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)5 CobarConfig (com.alibaba.cobar.CobarConfig)3 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)3 Executor (java.util.concurrent.Executor)2 KillConnectionHandler (com.alibaba.cobar.mysql.nio.handler.KillConnectionHandler)1 RollbackReleaseHandler (com.alibaba.cobar.mysql.nio.handler.RollbackReleaseHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1