Search in sources :

Example 6 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class ClearSlow method schema.

public static void schema(ManagerConnection c, String name) {
    MycatConfig conf = MycatServer.getInstance().getConfig();
    SchemaConfig schema = conf.getSchemas().get(name);
    if (schema != null) {
        //            Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
        //            for (String n : schema.getAllDataNodes()) {
        //                MySQLDataNode dn = dataNodes.get(n);
        //                MySQLDataSource ds = null;
        //                if (dn != null && (ds = dn.getSource()) != null) {
        //                    ds.getSqlRecorder().clear();
        //                }
        //            }
        c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
    } else {
        c.writeErrMessage(ErrorCode.ER_YES, "Invalid Schema:" + name);
    }
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) MycatConfig(io.mycat.config.MycatConfig)

Example 7 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class ShowDatasourceSyn method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsynRecorder();
            Map<String, String> states = record.getRecords();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            if (!states.isEmpty()) {
                row.add(StringUtil.encode(ds.getName(), charset));
                row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                row.add(StringUtil.encode(states.get("Master_Host"), charset));
                row.add(LongUtil.toBytes(Long.valueOf(states.get("Master_Port"))));
                row.add(StringUtil.encode(states.get("Master_Use"), charset));
                String secords = states.get("Seconds_Behind_Master");
                row.add(secords == null ? null : LongUtil.toBytes(Long.valueOf(secords)));
                row.add(StringUtil.encode(states.get("Slave_IO_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_SQL_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_IO_State"), charset));
                row.add(LongUtil.toBytes(Long.valueOf(states.get("Connect_Retry"))));
                row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) DataSourceSyncRecorder(io.mycat.statistic.DataSourceSyncRecorder) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList)

Example 8 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsynRecorder();
            Map<String, String> states = record.getRecords();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsynRecords();
                for (Record r : data) {
                    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
                    row.add(StringUtil.encode(ds.getName(), charset));
                    row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                    row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                    row.add(StringUtil.encode(states.get("Master_Host"), charset));
                    row.add(LongUtil.toBytes(Long.valueOf(states.get("Master_Port"))));
                    row.add(StringUtil.encode(states.get("Master_Use"), charset));
                    //DateFormat非线程安全
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String time = sdf.format(new Date(r.getTime()));
                    row.add(StringUtil.encode(time, charset));
                    row.add(LongUtil.toBytes((Long) r.getValue()));
                    list.add(row);
                }
                break;
            }
        }
    }
    return list;
}
Also used : DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) DataSourceSyncRecorder(io.mycat.statistic.DataSourceSyncRecorder) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList) Date(java.util.Date) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) Record(io.mycat.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class ShowHeartbeatDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    // host nodes
    String type = "";
    String ip = "";
    int port = 0;
    DBHeartbeat hb = null;
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            if (name.equals(ds.getName())) {
                hb = ds.getHeartbeat();
                type = ds.getConfig().getDbType();
                ip = ds.getConfig().getIp();
                port = ds.getConfig().getPort();
                break;
            }
        }
    }
    if (hb != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Queue<HeartbeatRecorder.Record> heatbeartRecorders = hb.getRecorder().getRecordsAll();
        for (HeartbeatRecorder.Record record : heatbeartRecorders) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, charset));
            row.add(StringUtil.encode(type, charset));
            row.add(StringUtil.encode(ip, charset));
            row.add(IntegerUtil.toBytes(port));
            long time = record.getTime();
            String timeStr = sdf.format(new Date(time));
            row.add(StringUtil.encode(timeStr, charset));
            row.add(LongUtil.toBytes(record.getValue()));
            list.add(row);
        }
    } else {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        list.add(row);
    }
    return list;
}
Also used : DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList) Date(java.util.Date) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) HeartbeatRecorder(io.mycat.statistic.HeartbeatRecorder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with MycatConfig

use of io.mycat.config.MycatConfig in project Mycat-Server by MyCATApache.

the class ShowDataSource method execute.

public static void execute(ManagerConnection c, String name) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    byte packetId = eof.packetId;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, List<PhysicalDatasource>> dataSources = new HashMap<String, List<PhysicalDatasource>>();
    if (null != name) {
        PhysicalDBNode dn = conf.getDataNodes().get(name);
        if (dn != null) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    } else {
        for (PhysicalDBNode dn : conf.getDataNodes().values()) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    }
    for (Map.Entry<String, List<PhysicalDatasource>> dsEntry : dataSources.entrySet()) {
        String dnName = dsEntry.getKey();
        for (PhysicalDatasource ds : dsEntry.getValue()) {
            RowDataPacket row = getRow(dnName, ds, c.getCharset());
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) List(java.util.List) LinkedList(java.util.LinkedList) FieldPacket(io.mycat.net.mysql.FieldPacket) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MycatConfig (io.mycat.config.MycatConfig)32 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)15 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)10 RowDataPacket (io.mycat.net.mysql.RowDataPacket)10 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)9 SchemaConfig (io.mycat.config.model.SchemaConfig)9 LinkedList (java.util.LinkedList)8 RouteResultsetNode (io.mycat.route.RouteResultsetNode)7 BackendConnection (io.mycat.backend.BackendConnection)6 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)5 UserConfig (io.mycat.config.model.UserConfig)5 MycatCluster (io.mycat.config.MycatCluster)4 IOException (java.io.IOException)4 TableConfig (io.mycat.config.model.TableConfig)3 EOFPacket (io.mycat.net.mysql.EOFPacket)3 FieldPacket (io.mycat.net.mysql.FieldPacket)3 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3