use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ShowBinlogStatus method getQueryResult.
/**
* getQueryResult: show master status
*
* @param charset
*/
private static void getQueryResult(final String charset) {
Collection<PhysicalDBPool> allPools = DbleServer.getInstance().getConfig().getDataHosts().values();
sourceCount = new AtomicInteger(allPools.size());
rows = new ArrayList<>(allPools.size());
for (PhysicalDBPool pool : allPools) {
// if WRITE_RANDOM_NODE ,may the binlog is not ready.
final PhysicalDatasource source = pool.getSource();
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(FIELDS, new SQLQueryResultListener<SQLQueryResult<Map<String, String>>>() {
@Override
public void onResult(SQLQueryResult<Map<String, String>> result) {
String url = source.getConfig().getUrl();
if (!result.isSuccess()) {
errMsg = "Getting binlog status from this instance[" + url + "] is failed";
} else {
rows.add(getRow(url, result.getResult(), charset));
}
sourceCount.decrementAndGet();
}
});
SQLJob sqlJob = new SQLJob(SHOW_BINLOG_QUERY, pool.getSchemas()[0], resultHandler, source);
sqlJob.run();
}
while (sourceCount.get() > 0) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10));
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ShowDataNode method getRow.
private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
PhysicalDBPool pool = node.getDbPool();
PhysicalDatasource ds = pool.getSource();
if (ds != null) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
int active = ds.getActiveCountForSchema(node.getDatabase());
int idle = ds.getIdleCountForSchema(node.getDatabase());
row.add(IntegerUtil.toBytes(pool.getActiveIndex()));
row.add(IntegerUtil.toBytes(active));
row.add(IntegerUtil.toBytes(idle));
row.add(IntegerUtil.toBytes(ds.getSize()));
row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
return row;
} else {
return null;
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ShowDatasourceSyn method getRows.
private static List<RowDataPacket> getRows(String charset) {
List<RowDataPacket> list = new LinkedList<>();
ServerConfig conf = DbleServer.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.getAsyncRecorder();
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.parseLong(states.get("Master_Port"))));
row.add(StringUtil.encode(states.get("Master_User"), charset));
String seconds = states.get("Seconds_Behind_Master");
row.add(seconds == null ? null : LongUtil.toBytes(Long.parseLong(seconds)));
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.parseLong(states.get("Connect_Retry"))));
row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
list.add(row);
}
}
}
return list;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ShowHeartbeat method getRows.
private static List<RowDataPacket> getRows() {
List<RowDataPacket> list = new LinkedList<>();
ServerConfig conf = DbleServer.getInstance().getConfig();
// host nodes
Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
for (PhysicalDBPool pool : dataHosts.values()) {
for (PhysicalDatasource ds : pool.getAllDataSources()) {
DBHeartbeat hb = ds.getHeartbeat();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(ds.getName().getBytes());
if (hb != null) {
row.add(ds.getConfig().getIp().getBytes());
row.add(IntegerUtil.toBytes(ds.getConfig().getPort()));
row.add(IntegerUtil.toBytes(hb.getStatus()));
row.add(IntegerUtil.toBytes(hb.getErrorCount()));
row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
row.add(LongUtil.toBytes(hb.getTimeout()));
row.add(hb.getRecorder().get().getBytes());
String lat = hb.getLastActiveTime();
row.add(lat == null ? null : lat.getBytes());
row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
} else {
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
}
list.add(row);
}
}
return list;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ReloadConfig method recycleOldBackendConnections.
private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
/* 2.4 put the old connection into a queue */
Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
for (PhysicalDBPool dbPool : oldDataHosts.values()) {
dbPool.stopHeartbeat();
for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection con : processor.getBackends().values()) {
if (con instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) con;
if (mysqlCon.getPool() == ds) {
if (con.isBorrowed()) {
if (closeFrontCon) {
findAndcloseFrontCon(con);
} else {
NIOProcessor.BACKENDS_OLD.add(con);
}
} else {
con.close("old idle conn for reload");
}
}
}
}
}
}
}
LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
Aggregations