use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ConfigTest method getPhysicalDBPool.
private PhysicalDBPool getPhysicalDBPool(DataHostConfig conf) {
String name = conf.getName();
PhysicalDatasource[] writeSources = createDataSource(conf, name, conf.getWriteHosts(), false);
Map<Integer, DBHostConfig[]> readHostsMap = conf.getReadHosts();
Map<Integer, PhysicalDatasource[]> readSourcesMap = new HashMap<Integer, PhysicalDatasource[]>(readHostsMap.size());
for (Map.Entry<Integer, DBHostConfig[]> entry : readHostsMap.entrySet()) {
PhysicalDatasource[] readSources = createDataSource(conf, name, entry.getValue(), true);
readSourcesMap.put(entry.getKey(), readSources);
}
PhysicalDBPool pool = new PhysicalDBPool(conf.getName(), conf, writeSources, readSourcesMap, conf.getBalance());
return pool;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class ConfigTest method createDataSource.
private PhysicalDatasource[] createDataSource(DataHostConfig conf, String hostName, DBHostConfig[] nodes, boolean isRead) {
PhysicalDatasource[] dataSources = new PhysicalDatasource[nodes.length];
for (int i = 0; i < nodes.length; i++) {
nodes[i].setIdleTimeout(system.getIdleTimeout());
MySQLDataSource ds = new MySQLDataSource(nodes[i], conf, isRead);
dataSources[i] = ds;
}
return dataSources;
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.
the class GlobalTableUtil method consistencyCheck.
public static void consistencyCheck() {
ServerConfig config = DbleServer.getInstance().getConfig();
for (TableConfig table : globalTableMap.values()) {
Map<String, ArrayList<PhysicalDBNode>> executedMap = new HashMap<>();
// <table name="travelrecord" dataNode="dn1,dn2,dn3"
for (String nodeName : table.getDataNodes()) {
Map<String, PhysicalDBNode> map = config.getDataNodes();
for (PhysicalDBNode dbNode : map.values()) {
// <dataNode name="dn1" dataHost="localhost1" database="db1" />
if (nodeName.equals(dbNode.getName())) {
// dn1,dn2,dn3
PhysicalDBPool pool = dbNode.getDbPool();
Collection<PhysicalDatasource> allDS = pool.getAllDataSources();
for (PhysicalDatasource pds : allDS) {
if (pds instanceof MySQLDataSource) {
ArrayList<PhysicalDBNode> nodes = executedMap.get(pds.getName());
if (nodes == null) {
nodes = new ArrayList<>();
}
nodes.add(dbNode);
executedMap.put(pds.getName(), nodes);
}
}
}
}
}
for (Map.Entry<String, ArrayList<PhysicalDBNode>> entry : executedMap.entrySet()) {
ArrayList<PhysicalDBNode> nodes = entry.getValue();
String[] schemas = new String[nodes.size()];
for (int index = 0; index < nodes.size(); index++) {
schemas[index] = StringUtil.removeBackQuote(nodes.get(index).getDatabase());
}
Collection<PhysicalDatasource> allDS = nodes.get(0).getDbPool().getAllDataSources();
for (PhysicalDatasource pds : allDS) {
if (pds instanceof MySQLDataSource && entry.getKey().equals(pds.getName())) {
MySQLDataSource mds = (MySQLDataSource) pds;
MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
isInnerColumnCheckFinished = 0;
checker.checkInnerColumnExist();
while (isInnerColumnCheckFinished <= 0) {
LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
LOGGER.info(e.getMessage());
}
}
LOGGER.debug("isInnerColumnCheckFinished:" + isInnerColumnCheckFinished);
// check another measure
checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
isColumnCountCheckFinished = 0;
checker.checkRecordCount();
while (isColumnCountCheckFinished <= 0) {
LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
LOGGER.info(e.getMessage());
}
}
LOGGER.debug("isColumnCountCheckFinished:" + isColumnCountCheckFinished);
checker = new MySQLConsistencyChecker(mds, schemas, table.getName());
checker.checkMaxTimeStamp();
}
}
}
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDatasource 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.PhysicalDatasource 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