Search in sources :

Example 1 with OneRawSQLQueryResultHandler

use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat_plus by coderczp.

the class MySQLTableStructureDetector method run.

@Override
public void run() {
    for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) {
        for (TableConfig table : schema.getTables().values()) {
            for (String dataNode : table.getDataNodes()) {
                try {
                    table.getReentrantReadWriteLock().writeLock().lock();
                    ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<>();
                    table.setDataNodeTableStructureSQLMap(map);
                } finally {
                    table.getReentrantReadWriteLock().writeLock().unlock();
                }
                OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLMS, new MySQLTableStructureListener(dataNode, table));
                resultHandler.setMark("Table Structure");
                PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode);
                SQLJob sqlJob = new SQLJob(sqlPrefix + table.getName(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
                sqlJob.run();
            }
        }
    }
}
Also used : OneRawSQLQueryResultHandler(io.mycat.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) SQLJob(io.mycat.sqlengine.SQLJob) TableConfig(io.mycat.config.model.TableConfig) List(java.util.List) LinkedList(java.util.LinkedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with OneRawSQLQueryResultHandler

use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat_plus by coderczp.

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());
}
Also used : OneRawSQLQueryResultHandler(io.mycat.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) ParticipantLogEntry(io.mycat.backend.mysql.xa.ParticipantLogEntry) SQLJob(io.mycat.sqlengine.SQLJob) XARollbackCallback(io.mycat.backend.mysql.xa.XARollbackCallback) TableConfig(io.mycat.config.model.TableConfig) CoordinatorLogEntry(io.mycat.backend.mysql.xa.CoordinatorLogEntry)

Example 3 with OneRawSQLQueryResultHandler

use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat_plus by coderczp.

the class MySQLConsistencyChecker method checkRecordCout.

public void checkRecordCout() {
    // ["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.COUNT_COLUMN }, detector);
            SQLJob sqlJob = new SQLJob(this.getCountSQL(), dbName, resultHandler, source);
            detector.setSqlJob(sqlJob);
            sqlJob.run();
            this.jobCount.incrementAndGet();
        }
    } finally {
        lock.unlock();
    }
}
Also used : OneRawSQLQueryResultHandler(io.mycat.sqlengine.OneRawSQLQueryResultHandler) SQLJob(io.mycat.sqlengine.SQLJob) Date(java.util.Date)

Example 4 with OneRawSQLQueryResultHandler

use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat_plus by coderczp.

the class MySQLDetector method heartbeat.

public void heartbeat() {
    lastSendQryTime = System.currentTimeMillis();
    MySQLDataSource ds = heartbeat.getSource();
    String databaseName = ds.getDbPool().getSchemas()[0];
    String[] fetchColms = {};
    if (heartbeat.getSource().getHostConfig().isShowSlaveSql()) {
        fetchColms = MYSQL_SLAVE_STAUTS_COLMS;
    }
    if (heartbeat.getSource().getHostConfig().isShowClusterSql()) {
        fetchColms = MYSQL_CLUSTER_STAUTS_COLMS;
    }
    OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(fetchColms, this);
    sqlJob = new SQLJob(heartbeat.getHeartbeatSQL(), databaseName, resultHandler, ds);
    sqlJob.run();
}
Also used : OneRawSQLQueryResultHandler(io.mycat.sqlengine.OneRawSQLQueryResultHandler) SQLJob(io.mycat.sqlengine.SQLJob) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource)

Example 5 with OneRawSQLQueryResultHandler

use of io.mycat.sqlengine.OneRawSQLQueryResultHandler in project Mycat-Server by MyCATApache.

the class MySQLTableStructureDetector method run.

@Override
public void run() {
    for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) {
        for (TableConfig table : schema.getTables().values()) {
            for (String dataNode : table.getDataNodes()) {
                try {
                    table.getReentrantReadWriteLock().writeLock().lock();
                    ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<>();
                    table.setDataNodeTableStructureSQLMap(map);
                } finally {
                    table.getReentrantReadWriteLock().writeLock().unlock();
                }
                OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLMS, new MySQLTableStructureListener(dataNode, table));
                resultHandler.setMark("Table Structure");
                PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode);
                SQLJob sqlJob = new SQLJob(sqlPrefix + table.getName(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
                sqlJob.run();
            }
        }
    }
}
Also used : OneRawSQLQueryResultHandler(io.mycat.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) SQLJob(io.mycat.sqlengine.SQLJob) TableConfig(io.mycat.config.model.TableConfig) List(java.util.List) LinkedList(java.util.LinkedList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

OneRawSQLQueryResultHandler (io.mycat.sqlengine.OneRawSQLQueryResultHandler)13 SQLJob (io.mycat.sqlengine.SQLJob)13 Date (java.util.Date)6 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)4 SchemaConfig (io.mycat.config.model.SchemaConfig)4 TableConfig (io.mycat.config.model.TableConfig)4 MySQLDataSource (io.mycat.backend.mysql.nio.MySQLDataSource)2 CoordinatorLogEntry (io.mycat.backend.mysql.xa.CoordinatorLogEntry)2 ParticipantLogEntry (io.mycat.backend.mysql.xa.ParticipantLogEntry)2 XARollbackCallback (io.mycat.backend.mysql.xa.XARollbackCallback)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PostgreSQLDataSource (io.mycat.backend.postgresql.PostgreSQLDataSource)1