use of com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler in project dble by actiontech.
the class MySQLConsistencyChecker method checkRecordCount.
public void checkRecordCount() {
// ["db3","db2","db1"]
lock.lock();
try {
this.jobCount.set(0);
beginTime = new Date().getTime();
for (String dbName : physicalSchemas) {
MySQLConsistencyHelper detector = new MySQLConsistencyHelper(this, null);
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[] { GlobalTableUtil.COUNT_COLUMN }, detector);
SQLJob sqlJob = new SQLJob(this.getCountSQL(), dbName, resultHandler, source);
detector.setSqlJob(sqlJob);
sqlJob.run();
this.jobCount.incrementAndGet();
}
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler 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.sqlengine.OneRawSQLQueryResultHandler in project dble by actiontech.
the class DbleServer method tryRecovery.
private void tryRecovery(CoordinatorLogEntry coordinatorLogEntry, boolean needCommit) {
StringBuilder xaCmd = new StringBuilder();
if (needCommit) {
xaCmd.append("XA COMMIT ");
} else {
xaCmd.append("XA ROLLBACK ");
}
boolean finished = true;
for (int j = 0; j < coordinatorLogEntry.getParticipants().length; j++) {
ParticipantLogEntry participantLogEntry = coordinatorLogEntry.getParticipants()[j];
// XA commit
if (participantLogEntry.getTxState() != TxState.TX_COMMIT_FAILED_STATE && participantLogEntry.getTxState() != TxState.TX_COMMITTING_STATE && participantLogEntry.getTxState() != TxState.TX_PREPARE_UNCONNECT_STATE && participantLogEntry.getTxState() != TxState.TX_ROLLBACKING_STATE && participantLogEntry.getTxState() != TxState.TX_ROLLBACK_FAILED_STATE && participantLogEntry.getTxState() != TxState.TX_PREPARED_STATE) {
continue;
}
finished = false;
outLoop: for (SchemaConfig schema : DbleServer.getInstance().getConfig().getSchemas().values()) {
for (TableConfig table : schema.getTables().values()) {
for (String dataNode : table.getDataNodes()) {
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
if (participantLogEntry.compareAddress(dn.getDbPool().getSource().getConfig().getIp(), dn.getDbPool().getSource().getConfig().getPort(), dn.getDatabase())) {
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[0], new XARecoverCallback(needCommit, participantLogEntry));
xaCmd.append(coordinatorLogEntry.getId().substring(0, coordinatorLogEntry.getId().length() - 1));
xaCmd.append(".");
xaCmd.append(dn.getDatabase());
xaCmd.append("'");
SQLJob sqlJob = new SQLJob(xaCmd.toString(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
sqlJob.run();
LOGGER.debug(String.format("[%s] Host:[%s] schema:[%s]", xaCmd, dn.getName(), dn.getDatabase()));
// reset xaCmd
xaCmd.setLength(0);
if (needCommit) {
xaCmd.append("XA COMMIT ");
} else {
xaCmd.append("XA ROLLBACK ");
}
break outLoop;
}
}
}
}
}
if (finished) {
XAStateLog.saveXARecoveryLog(coordinatorLogEntry.getId(), needCommit ? TxState.TX_COMMITTED_STATE : TxState.TX_ROLLBACKED_STATE);
XAStateLog.writeCheckpoint(coordinatorLogEntry.getId());
}
}
use of com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler in project dble by actiontech.
the class AbstractTableMetaHandler method execute.
public void execute() {
for (String dataNode : dataNodes) {
if (selfNode != null && selfNode.contains(dataNode)) {
this.countdown();
return;
}
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLS, new MySQLTableStructureListener(dataNode, System.currentTimeMillis(), new ConcurrentHashMap<String, List<String>>()));
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
SQLJob sqlJob = new SQLJob(SQL_PREFIX + tableName, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
sqlJob.run();
}
}
use of com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler in project dble by actiontech.
the class SetHandler method setStmtCallback.
// execute multiStmt and callback to reset conn
private static void setStmtCallback(String multiStmt, ServerConnection c, List<Pair<KeyType, Pair<String, String>>> contextTask) {
c.setContextTask(contextTask);
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[0], new SetCallBack(c));
Iterator<PhysicalDBPool> iterator = DbleServer.getInstance().getConfig().getDataHosts().values().iterator();
if (iterator.hasNext()) {
PhysicalDBPool pool = iterator.next();
SetTestJob sqlJob = new SetTestJob(multiStmt, pool.getSchemas()[0], resultHandler, c);
sqlJob.run();
} else {
c.writeErrMessage(ErrorCode.ER_YES, "no valid data host");
}
}
Aggregations