Search in sources :

Example 6 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource 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 7 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowDataNode method getRow.

private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
    PhysicalDBPool pool = node.getDbPool();
    PhysicalDatasource ds = pool.getSource();
    if (ds != null) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(node.getName(), charset));
        row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
        int active = ds.getActiveCountForSchema(node.getDatabase());
        int idle = ds.getIdleCountForSchema(node.getDatabase());
        row.add(IntegerUtil.toBytes(pool.getActiveIndex()));
        row.add(IntegerUtil.toBytes(active));
        row.add(IntegerUtil.toBytes(idle));
        row.add(IntegerUtil.toBytes(ds.getSize()));
        row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
        long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
        row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
        return row;
    } else {
        return null;
    }
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Example 8 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowDatasourceSyn method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            if (!states.isEmpty()) {
                row.add(StringUtil.encode(ds.getName(), charset));
                row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                row.add(StringUtil.encode(states.get("Master_Host"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Master_Port"))));
                row.add(StringUtil.encode(states.get("Master_User"), charset));
                String seconds = states.get("Seconds_Behind_Master");
                row.add(seconds == null ? null : LongUtil.toBytes(Long.parseLong(seconds)));
                row.add(StringUtil.encode(states.get("Slave_IO_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_SQL_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_IO_State"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Connect_Retry"))));
                row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 9 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowHeartbeat method getRows.

private static List<RowDataPacket> getRows() {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(ds.getName().getBytes());
            if (hb != null) {
                row.add(ds.getConfig().getIp().getBytes());
                row.add(IntegerUtil.toBytes(ds.getConfig().getPort()));
                row.add(IntegerUtil.toBytes(hb.getStatus()));
                row.add(IntegerUtil.toBytes(hb.getErrorCount()));
                row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
                row.add(LongUtil.toBytes(hb.getTimeout()));
                row.add(hb.getRecorder().get().getBytes());
                String lat = hb.getLastActiveTime();
                row.add(lat == null ? null : lat.getBytes());
                row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
            } else {
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
            }
            list.add(row);
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 10 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ReloadConfig method recycleOldBackendConnections.

private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
    /* 2.4 put the old connection into a queue */
    Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
    for (PhysicalDBPool dbPool : oldDataHosts.values()) {
        dbPool.stopHeartbeat();
        for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
            for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
                for (BackendConnection con : processor.getBackends().values()) {
                    if (con instanceof MySQLConnection) {
                        MySQLConnection mysqlCon = (MySQLConnection) con;
                        if (mysqlCon.getPool() == ds) {
                            if (con.isBorrowed()) {
                                if (closeFrontCon) {
                                    findAndcloseFrontCon(con);
                                } else {
                                    NIOProcessor.BACKENDS_OLD.add(con);
                                }
                            } else {
                                con.close("old idle conn for reload");
                            }
                        }
                    }
                }
            }
        }
    }
    LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Aggregations

PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)19 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)16 ServerConfig (com.actiontech.dble.config.ServerConfig)7 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 MySQLDataSource (com.actiontech.dble.backend.mysql.nio.MySQLDataSource)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BackendConnection (com.actiontech.dble.backend.BackendConnection)1 MySQLConsistencyChecker (com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker)1 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 ConfigException (com.actiontech.dble.config.util.ConfigException)1 NIOProcessor (com.actiontech.dble.net.NIOProcessor)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1