use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class NonBlockingSession method freshConn.
public MySQLConnection freshConn(MySQLConnection errConn, ResponseHandler queryHandler) {
for (final RouteResultsetNode node : this.getTargetKeys()) {
final MySQLConnection mysqlCon = (MySQLConnection) this.getTarget(node);
if (errConn.equals(mysqlCon)) {
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
try {
MySQLConnection newConn = (MySQLConnection) dn.getConnection(dn.getDatabase(), errConn.isAutocommit(), false);
newConn.setXaStatus(errConn.getXaStatus());
if (!newConn.setResponseHandler(queryHandler)) {
return errConn;
}
this.bindConnection(node, newConn);
return newConn;
} catch (Exception e) {
return errConn;
}
}
}
return errConn;
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class FetchMySQLSequenceHandler method execute.
public void execute(SequenceVal seqVal) {
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode mysqlDN = conf.getDataNodes().get(seqVal.dataNode);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in data node " + seqVal.dataNode + " for fetch sequence sql " + seqVal.sql);
}
// change Select mode to Update mode. Make sure the query send to the write host
mysqlDN.getConnection(mysqlDN.getDatabase(), true, true, new RouteResultsetNode(seqVal.dataNode, ServerParse.UPDATE, seqVal.sql), this, seqVal);
} catch (Exception e) {
LOGGER.info("get connection err " + e);
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class HintDataNodeHandler method route.
@Override
public RouteResultset route(SchemaConfig schema, int sqlType, String realSQL, ServerConnection sc, LayerCachePool cachePool, String hintSQLValue, int hintSqlType, Map hintMap) throws SQLNonTransientException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("route datanode sql hint from " + realSQL);
}
RouteResultset rrs = new RouteResultset(realSQL, sqlType);
PhysicalDBNode dataNode = DbleServer.getInstance().getConfig().getDataNodes().get(hintSQLValue);
if (dataNode != null) {
rrs = RouterUtil.routeToSingleNode(rrs, dataNode.getName());
} else {
String msg = "can't find hint datanode:" + hintSQLValue;
LOGGER.info(msg);
throw new SQLNonTransientException(msg);
}
return rrs;
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class ConfigInitializer method testConnection.
public void testConnection(boolean isStart) {
if (this.dataNodes != null && this.dataHosts != null) {
Map<String, Boolean> map = new HashMap<>();
for (PhysicalDBNode dataNode : dataNodes.values()) {
String database = dataNode.getDatabase();
PhysicalDBPool pool = dataNode.getDbPool();
if (isStart) {
// start for first time, 1.you can set write host as empty
if (pool.getSources() == null || pool.getSources().length == 0) {
continue;
}
DBHostConfig wHost = pool.getSource().getConfig();
// start for first time, 2.you can set write host as yourself
if (("localhost".equalsIgnoreCase(wHost.getIp()) || "127.0.0.1".equalsIgnoreCase(wHost.getIp())) && wHost.getPort() == this.system.getServerPort()) {
continue;
}
}
for (PhysicalDatasource ds : pool.getAllDataSources()) {
String key = ds.getName() + "_" + database;
if (map.get(key) == null) {
map.put(key, false);
try {
boolean isConnected = ds.testConnection(database);
map.put(key, isConnected);
} catch (IOException e) {
LOGGER.info("test conn " + key + " error:", e);
}
}
}
}
boolean isConnectivity = true;
for (Map.Entry<String, Boolean> entry : map.entrySet()) {
String key = entry.getKey();
Boolean value = entry.getValue();
if (!value && isConnectivity) {
LOGGER.info("SelfCheck### test " + key + " database connection failed ");
isConnectivity = false;
} else {
LOGGER.info("SelfCheck### test " + key + " database connection success ");
}
}
if (!isConnectivity) {
throw new ConfigException("SelfCheck### there are some datasource connection failed, pls check!");
}
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDBNode in project dble by actiontech.
the class ShowDataSource method execute.
public static void execute(ManagerConnection c, String name) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
ServerConfig conf = DbleServer.getInstance().getConfig();
if (null != name) {
PhysicalDBNode dn = conf.getDataNodes().get(name);
for (PhysicalDatasource w : dn.getDbPool().getAllDataSources()) {
RowDataPacket row = getRow(w, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
} else {
// add all
for (Map.Entry<String, PhysicalDBPool> entry : conf.getDataHosts().entrySet()) {
PhysicalDBPool dataHost = entry.getValue();
for (int i = 0; i < dataHost.getSources().length; i++) {
RowDataPacket row = getRow(dataHost.getSources()[i], c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
if (dataHost.getrReadSources().get(i) != null) {
for (PhysicalDatasource w : dataHost.getrReadSources().get(i)) {
RowDataPacket sRow = getRow(w, c.getCharset().getResults());
sRow.setPacketId(++packetId);
buffer = sRow.write(buffer, c, true);
}
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
Aggregations