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