use of com.actiontech.dble.sqlengine.SQLJob 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.SQLJob in project dble by actiontech.
the class MySQLConsistencyHelper method close.
public void close(String msg) {
SQLJob curJob = sqlJob;
if (curJob != null && !curJob.isFinished()) {
curJob.terminate(msg);
sqlJob = null;
}
}
use of com.actiontech.dble.sqlengine.SQLJob in project dble by actiontech.
the class MySQLDetector method close.
public void close(String msg) {
SQLJob curJob = sqlJob;
if (curJob != null && !curJob.isFinished()) {
curJob.terminate(msg);
sqlJob = null;
}
}
use of com.actiontech.dble.sqlengine.SQLJob 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.SQLJob 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());
}
}
Aggregations