Search in sources :

Example 1 with OneRawSQLQueryResultHandler

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();
    }
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) SQLJob(com.actiontech.dble.sqlengine.SQLJob) Date(java.util.Date)

Example 2 with OneRawSQLQueryResultHandler

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));
    }
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) SQLQueryResult(com.actiontech.dble.sqlengine.SQLQueryResult) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) SQLJob(com.actiontech.dble.sqlengine.SQLJob) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 3 with OneRawSQLQueryResultHandler

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());
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) SQLJob(com.actiontech.dble.sqlengine.SQLJob) TableConfig(com.actiontech.dble.config.model.TableConfig)

Example 4 with OneRawSQLQueryResultHandler

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();
    }
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SQLJob(com.actiontech.dble.sqlengine.SQLJob) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with OneRawSQLQueryResultHandler

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");
    }
}
Also used : OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) SetTestJob(com.actiontech.dble.sqlengine.SetTestJob)

Aggregations

OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)9 SQLJob (com.actiontech.dble.sqlengine.SQLJob)8 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 Date (java.util.Date)3 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)2 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 MySQLDataSource (com.actiontech.dble.backend.mysql.nio.MySQLDataSource)1 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 SQLQueryResult (com.actiontech.dble.sqlengine.SQLQueryResult)1 SetTestJob (com.actiontech.dble.sqlengine.SetTestJob)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1