Search in sources :

Example 6 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class ReloadUser method execute.

public static void execute(ManagerConnection c) {
    boolean status = false;
    if (status) {
        StringBuilder s = new StringBuilder();
        s.append(c).append("Reload userConfig success by manager");
        logger.warn(s.toString());
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = 1;
        ok.serverStatus = 2;
        ok.message = "Reload userConfig success".getBytes();
        ok.write(c);
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 7 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class RollbackUser method execute.

public static void execute(ManagerConnection c) {
    boolean status = false;
    if (status) {
        StringBuilder s = new StringBuilder();
        s.append(c).append("Rollback user success by manager");
        logger.warn(s.toString());
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = 1;
        ok.serverStatus = 2;
        ok.message = "Rollback user success".getBytes();
        ok.write(c);
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
    }
}
Also used : OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 8 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class StopHeartbeat method execute.

public static void execute(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> keys = ManagerParseStop.getPair(stmt);
    if (keys.getKey() != null && keys.getValue() != null) {
        long time = keys.getValue().intValue() * 1000L;
        Map<String, MySQLDataNode> dns = CobarServer.getInstance().getConfig().getDataNodes();
        for (String key : keys.getKey()) {
            MySQLDataNode dn = dns.get(key);
            if (dn != null) {
                dn.setHeartbeatRecoveryTime(TimeUtil.currentTimeMillis() + time);
                ++count;
                StringBuilder s = new StringBuilder();
                s.append(dn.getName()).append(" stop heartbeat '");
                logger.warn(s.append(FormatUtil.formatTime(time, 3)).append("' by manager."));
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 9 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class RollbackConfig method execute.

public static void execute(ManagerConnection c) {
    final ReentrantLock lock = CobarServer.getInstance().getConfig().getLock();
    lock.lock();
    try {
        if (rollback()) {
            StringBuilder s = new StringBuilder();
            s.append(c).append("Rollback config success by manager");
            LOGGER.warn(s.toString());
            OkPacket ok = new OkPacket();
            ok.packetId = 1;
            ok.affectedRows = 1;
            ok.serverStatus = 2;
            ok.message = "Rollback config success".getBytes();
            ok.write(c);
        } else {
            c.writeErrMessage(ErrorCode.ER_YES, "Rollback config failure");
        }
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Example 10 with OkPacket

use of com.alibaba.cobar.net.mysql.OkPacket in project cobar by alibaba.

the class SwitchDataSource method response.

public static void response(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> pair = ManagerParseSwitch.getPair(stmt);
    Map<String, MySQLDataNode> dns = CobarServer.getInstance().getConfig().getDataNodes();
    Integer idx = pair.getValue();
    for (String key : pair.getKey()) {
        MySQLDataNode dn = dns.get(key);
        if (dn != null) {
            int m = dn.getActivedIndex();
            int n = (idx == null) ? dn.next(m) : idx.intValue();
            if (dn.switchSource(n, false, "MANAGER")) {
                ++count;
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) OkPacket(com.alibaba.cobar.net.mysql.OkPacket)

Aggregations

OkPacket (com.alibaba.cobar.net.mysql.OkPacket)15 ServerConnection (com.alibaba.cobar.server.ServerConnection)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)1 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)1 NIOConnection (com.alibaba.cobar.net.NIOConnection)1 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)1 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)1 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)1 HeartbeatPacket (com.alibaba.cobar.net.mysql.HeartbeatPacket)1 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)1 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)1 LinkedList (java.util.LinkedList)1