Search in sources :

Example 6 with MySQLDataSource

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

the class ConfigInitializer method getDataNode.

private MySQLDataNode getDataNode(DataNodeConfig dnc, ConfigLoader configLoader) {
    String[] dsNames = SplitUtil.split(dnc.getDataSource(), ',');
    checkDataSourceExists(dsNames);
    MySQLDataNode node = new MySQLDataNode(dnc);
    MySQLDataSource[] dsList = new MySQLDataSource[dsNames.length];
    int size = dnc.getPoolSize();
    for (int i = 0; i < dsList.length; i++) {
        DataSourceConfig dsc = dataSources.get(dsNames[i]);
        dsList[i] = new MySQLDataSource(node, i, dsc, size);
    }
    node.setSources(dsList);
    return node;
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) DataSourceConfig(com.alibaba.cobar.config.model.DataSourceConfig)

Example 7 with MySQLDataSource

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

the class ShowDataNode method getRow.

private static RowDataPacket getRow(MySQLDataNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    row.add(StringUtil.encode(node.getConfig().getDataSource(), charset));
    MySQLDataSource ds = node.getSource();
    if (ds != null) {
        row.add(IntegerUtil.toBytes(ds.getIndex()));
        row.add(ds.getConfig().getType().getBytes());
        row.add(IntegerUtil.toBytes(ds.getActiveCount()));
        row.add(IntegerUtil.toBytes(ds.getIdleCount()));
        row.add(IntegerUtil.toBytes(ds.size()));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    row.add(LongUtil.toBytes(node.getExecuteCount()));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(StringUtil.encode(nf.format(0), charset));
    row.add(LongUtil.toBytes(0));
    long recoveryTime = node.getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
    row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
    return row;
}
Also used : MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Example 8 with MySQLDataSource

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

the class ShowDataSource method execute.

public static void execute(ManagerConnection c, String name) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    CobarConfig conf = CobarServer.getInstance().getConfig();
    Map<String, DataSourceConfig> dataSources = conf.getDataSources();
    List<String> keys = new ArrayList<String>();
    if (null != name) {
        MySQLDataNode dn = conf.getDataNodes().get(name);
        if (dn != null)
            for (MySQLDataSource ds : dn.getSources()) {
                if (ds != null) {
                    keys.add(ds.getName());
                }
            }
    } else {
        keys.addAll(dataSources.keySet());
    }
    Collections.sort(keys, new Comparators<String>());
    for (String key : keys) {
        RowDataPacket row = getRow(dataSources.get(key), 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) DataSourceConfig(com.alibaba.cobar.config.model.DataSourceConfig) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) CobarConfig(com.alibaba.cobar.CobarConfig) ByteBuffer(java.nio.ByteBuffer) MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 9 with MySQLDataSource

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

the class ClearSlow method dataNode.

public static void dataNode(ManagerConnection c, String name) {
    MySQLDataNode dn = CobarServer.getInstance().getConfig().getDataNodes().get(name);
    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 DataNode:" + name);
    }
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode) MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource)

Example 10 with MySQLDataSource

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

the class ShowDataSources method getRow.

private static RowDataPacket getRow(MySQLDataNode node, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(node.getName(), charset));
    MySQLDataSource ds = node.getSource();
    if (ds != null) {
        DataSourceConfig dsc = ds.getConfig();
        row.add(StringUtil.encode(dsc.getType(), charset));
        row.add(StringUtil.encode(dsc.getHost(), charset));
        row.add(IntegerUtil.toBytes(dsc.getPort()));
        row.add(StringUtil.encode(dsc.getDatabase(), charset));
    } else {
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
    }
    return row;
}
Also used : MySQLDataSource(com.alibaba.cobar.mysql.MySQLDataSource) DataSourceConfig(com.alibaba.cobar.config.model.DataSourceConfig) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket)

Aggregations

MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)10 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)8 CobarConfig (com.alibaba.cobar.CobarConfig)6 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)5 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)4 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)3 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)3 ByteBuffer (java.nio.ByteBuffer)3 CobarCluster (com.alibaba.cobar.CobarCluster)2 QuarantineConfig (com.alibaba.cobar.config.model.QuarantineConfig)2 UserConfig (com.alibaba.cobar.config.model.UserConfig)2 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)2 ConfigInitializer (com.alibaba.cobar.ConfigInitializer)1 SQLRecorder (com.alibaba.cobar.statistic.SQLRecorder)1 ArrayList (java.util.ArrayList)1