Search in sources :

Example 16 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class RollbackConfig method execute.

public static void execute(ManagerConnection c) {
    final ReentrantLock lock = MycatServer.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(io.mycat.net.mysql.OkPacket)

Example 17 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

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, PhysicalDBPool> dns = MycatServer.getInstance().getConfig().getDataHosts();
    Integer idx = pair.getValue();
    for (String key : pair.getKey()) {
        PhysicalDBPool 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 : OkPacket(io.mycat.net.mysql.OkPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool)

Example 18 with OkPacket

use of io.mycat.net.mysql.OkPacket in project Mycat-Server by MyCATApache.

the class Heartbeat method response.

public static void response(ServerConnection c, byte[] data) {
    HeartbeatPacket hp = new HeartbeatPacket();
    hp.read(data);
    if (MycatServer.getInstance().isOnline()) {
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = hp.id;
        ok.serverStatus = 2;
        ok.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("OK", c, hp.id));
        }
    } else {
        ErrorPacket error = new ErrorPacket();
        error.packetId = 1;
        error.errno = ErrorCode.ER_SERVER_SHUTDOWN;
        error.message = String.valueOf(hp.id).getBytes();
        error.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("ERROR", c, hp.id));
        }
    }
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) ErrorPacket(io.mycat.net.mysql.ErrorPacket) HeartbeatPacket(io.mycat.net.mysql.HeartbeatPacket)

Aggregations

OkPacket (io.mycat.net.mysql.OkPacket)18 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 UserStat (io.mycat.statistic.stat.UserStat)2 BackendConnection (io.mycat.backend.BackendConnection)1 UserConfig (io.mycat.config.model.UserConfig)1 ConfigException (io.mycat.config.util.ConfigException)1 FrontendConnection (io.mycat.net.FrontendConnection)1 NIOConnection (io.mycat.net.NIOConnection)1 ErrorPacket (io.mycat.net.mysql.ErrorPacket)1 HeartbeatPacket (io.mycat.net.mysql.HeartbeatPacket)1 RouteResultsetNode (io.mycat.route.RouteResultsetNode)1 ServerConnection (io.mycat.server.ServerConnection)1 QueryResult (io.mycat.statistic.stat.QueryResult)1 ArrayList (java.util.ArrayList)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1