use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat-Server by MyCATApache.
the class MySQLConsistencyChecker method checkMaxTimeStamp.
public void checkMaxTimeStamp() {
// ["db3","db2","db1"]
lock.lock();
try {
this.jobCount.set(0);
beginTime = new Date().getTime();
String[] physicalSchemas = source.getDbPool().getSchemas();
for (String dbName : physicalSchemas) {
MySQLConsistencyHelper detector = new MySQLConsistencyHelper(this, null);
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[] { GlobalTableUtil.MAX_COLUMN }, detector);
SQLJob sqlJob = new SQLJob(this.getMaxSQL(), dbName, resultHandler, source);
detector.setSqlJob(sqlJob);
sqlJob.run();
this.jobCount.incrementAndGet();
}
} finally {
lock.unlock();
}
}
use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat-Server by MyCATApache.
the class MySQLConsistencyChecker method checkInnerColumnExist.
/**
* check inner column exist or not
*/
public void checkInnerColumnExist() {
// ["db3","db2","db1"]
lock.lock();
try {
this.jobCount.set(0);
beginTime = new Date().getTime();
String[] physicalSchemas = source.getDbPool().getSchemas();
for (String dbName : physicalSchemas) {
MySQLConsistencyHelper detector = new MySQLConsistencyHelper(this, null, 1);
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[] { GlobalTableUtil.INNER_COLUMN }, detector);
String db = " and table_schema='" + dbName + "'";
SQLJob sqlJob = new SQLJob(this.columnExistSQL + db, dbName, resultHandler, source);
// table_schema='db1'
detector.setSqlJob(sqlJob);
LOGGER.debug(sqlJob.toString());
sqlJob.run();
this.jobCount.incrementAndGet();
}
} finally {
lock.unlock();
}
}
use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat-Server by MyCATApache.
the class MycatServer method performXARecoveryLog.
// XA recovery log check
private void performXARecoveryLog() {
// fetch the recovery log
CoordinatorLogEntry[] coordinatorLogEntries = getCoordinatorLogEntries();
for (int i = 0; i < coordinatorLogEntries.length; i++) {
CoordinatorLogEntry coordinatorLogEntry = coordinatorLogEntries[i];
boolean needRollback = false;
for (int j = 0; j < coordinatorLogEntry.participants.length; j++) {
ParticipantLogEntry participantLogEntry = coordinatorLogEntry.participants[j];
if (participantLogEntry.txState == TxState.TX_PREPARED_STATE) {
needRollback = true;
break;
}
}
if (needRollback) {
for (int j = 0; j < coordinatorLogEntry.participants.length; j++) {
ParticipantLogEntry participantLogEntry = coordinatorLogEntry.participants[j];
// XA rollback
String xacmd = "XA ROLLBACK " + coordinatorLogEntry.id + ';';
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(new String[0], new XARollbackCallback());
outloop: for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) {
for (TableConfig table : schema.getTables().values()) {
for (String dataNode : table.getDataNodes()) {
PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode);
if (dn.getDbPool().getSource().getConfig().getIp().equals(participantLogEntry.uri) && dn.getDatabase().equals(participantLogEntry.resourceName)) {
// XA STATE ROLLBACK
participantLogEntry.txState = TxState.TX_ROLLBACKED_STATE;
SQLJob sqlJob = new SQLJob(xacmd, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
sqlJob.run();
LOGGER.debug(String.format("[XA ROLLBACK] [%s] Host:[%s] schema:[%s]", xacmd, dn.getName(), dn.getDatabase()));
break outloop;
}
}
}
}
}
}
}
// init into in memory cached
for (int i = 0; i < coordinatorLogEntries.length; i++) {
MultiNodeCoordinator.inMemoryRepository.put(coordinatorLogEntries[i].id, coordinatorLogEntries[i]);
}
// discard the recovery log
MultiNodeCoordinator.fileRepository.writeCheckpoint(MultiNodeCoordinator.inMemoryRepository.getAllCoordinatorLogEntries());
}
Aggregations