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;
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations