Search in sources :

Example 16 with MySQLDataNode

use of com.alibaba.cobar.mysql.MySQLDataNode 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 17 with MySQLDataNode

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

the class ShowDataNode 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, MySQLDataNode> dataNodes = conf.getDataNodes();
    List<String> keys = new ArrayList<String>();
    if (StringUtil.isEmpty(name)) {
        keys.addAll(dataNodes.keySet());
    } else {
        SchemaConfig sc = conf.getSchemas().get(name);
        if (null != sc) {
            keys.addAll(sc.getAllDataNodes());
        }
    }
    Collections.sort(keys, new Comparators<String>());
    for (String key : keys) {
        RowDataPacket row = getRow(dataNodes.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) SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig) 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) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 18 with MySQLDataNode

use of com.alibaba.cobar.mysql.MySQLDataNode 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 19 with MySQLDataNode

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

the class MySQLHeartbeat method switchSource.

/**
     * switch data source
     */
private void switchSource(String reason) {
    if (!isStop.get()) {
        MySQLDataNode node = source.getNode();
        int i = node.next(source.getIndex());
        node.switchSource(i, true, reason);
    }
}
Also used : MySQLDataNode(com.alibaba.cobar.mysql.MySQLDataNode)

Example 20 with MySQLDataNode

use of com.alibaba.cobar.mysql.MySQLDataNode 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)

Aggregations

MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)22 CobarConfig (com.alibaba.cobar.CobarConfig)13 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)8 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)6 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)5 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)5 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)5 ByteBuffer (java.nio.ByteBuffer)5 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)4 MySQLConnection (com.alibaba.cobar.mysql.nio.MySQLConnection)3 ArrayList (java.util.ArrayList)3 CobarCluster (com.alibaba.cobar.CobarCluster)2 QuarantineConfig (com.alibaba.cobar.config.model.QuarantineConfig)2 UserConfig (com.alibaba.cobar.config.model.UserConfig)2 UnknownDataNodeException (com.alibaba.cobar.exception.UnknownDataNodeException)2 Channel (com.alibaba.cobar.mysql.bio.Channel)2 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)2 OkPacket (com.alibaba.cobar.net.mysql.OkPacket)2 RouteResultsetNode (com.alibaba.cobar.route.RouteResultsetNode)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2