Search in sources :

Example 26 with PhysicalDBPool

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

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, 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();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsyncRecords();
                for (Record r : data) {
                    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
                    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));
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String time = sdf.format(new Date(r.getTime()));
                    row.add(StringUtil.encode(time, charset));
                    row.add(LongUtil.toBytes((Long) r.getValue()));
                    list.add(row);
                }
                break;
            }
        }
    }
    return list;
}
Also used : 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) Date(java.util.Date) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) Record(com.actiontech.dble.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Example 27 with PhysicalDBPool

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

the class ShowHeartbeatDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    String ip = "";
    int port = 0;
    DBHeartbeat hb = null;
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            if (name.equals(ds.getName())) {
                hb = ds.getHeartbeat();
                ip = ds.getConfig().getIp();
                port = ds.getConfig().getPort();
                break;
            }
        }
    }
    if (hb != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Queue<HeartbeatRecorder.Record> heartbeatRecorders = hb.getRecorder().getRecordsAll();
        for (HeartbeatRecorder.Record record : heartbeatRecorders) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, charset));
            row.add(StringUtil.encode(ip, charset));
            row.add(IntegerUtil.toBytes(port));
            long time = record.getTime();
            String timeStr = sdf.format(new Date(time));
            row.add(StringUtil.encode(timeStr, charset));
            row.add(LongUtil.toBytes(record.getValue()));
            list.add(row);
        }
    } else {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        list.add(row);
    }
    return list;
}
Also used : DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) HeartbeatRecorder(com.actiontech.dble.statistic.HeartbeatRecorder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 28 with PhysicalDBPool

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

the class RollbackConfig method rollback.

public static void rollback() throws Exception {
    ServerConfig conf = DbleServer.getInstance().getConfig();
    Map<String, PhysicalDBPool> dataHosts = conf.getBackupDataHosts();
    Map<String, UserConfig> users = conf.getBackupUsers();
    Map<String, SchemaConfig> schemas = conf.getBackupSchemas();
    Map<String, PhysicalDBNode> dataNodes = conf.getBackupDataNodes();
    FirewallConfig firewall = conf.getBackupFirewall();
    Map<ERTable, Set<ERTable>> erRelations = conf.getBackupErRelations();
    boolean backDataHostWithoutWR = conf.backDataHostWithoutWR();
    if (conf.canRollback()) {
        conf.rollback(users, schemas, dataNodes, dataHosts, erRelations, firewall, backDataHostWithoutWR);
    } else if (conf.canRollbackAll()) {
        boolean rollbackStatus = true;
        String errorMsg = null;
        for (PhysicalDBPool dn : dataHosts.values()) {
            dn.init(dn.getActiveIndex());
            if (!dn.isInitSuccess()) {
                rollbackStatus = false;
                errorMsg = "dataHost[" + dn.getHostName() + "] inited failure";
                break;
            }
        }
        // INIT FAILED
        if (!rollbackStatus) {
            for (PhysicalDBPool dn : dataHosts.values()) {
                dn.clearDataSources("rollbackup config");
                dn.stopHeartbeat();
            }
            throw new Exception(errorMsg);
        }
        final Map<String, PhysicalDBPool> cNodes = conf.getDataHosts();
        // apply
        conf.rollback(users, schemas, dataNodes, dataHosts, erRelations, firewall, backDataHostWithoutWR);
        // stop old resource heartbeat
        for (PhysicalDBPool dn : cNodes.values()) {
            dn.clearDataSources("clear old config ");
            dn.stopHeartbeat();
        }
        AlarmAppender.rollbackConfig();
    } else {
        throw new Exception("there is no old version");
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Set(java.util.Set) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ERTable(com.actiontech.dble.config.model.ERTable) UserConfig(com.actiontech.dble.config.model.UserConfig) FirewallConfig(com.actiontech.dble.config.model.FirewallConfig) ServerConfig(com.actiontech.dble.config.ServerConfig) Map(java.util.Map)

Example 29 with PhysicalDBPool

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

the class ConfigTest method testReadHostWeight.

/**
 * testReadHostWeight
 *
 * @throws Exception
 */
@Test
public void testReadHostWeight() throws Exception {
    ArrayList<PhysicalDatasource> okSources = new ArrayList<PhysicalDatasource>();
    PhysicalDBPool pool = this.dataHosts.get("localhost2");
    okSources.addAll(pool.getAllDataSources());
    PhysicalDatasource source = pool.randomSelect(okSources);
    Assert.assertTrue(source != null);
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) ArrayList(java.util.ArrayList) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) Test(org.junit.Test)

Example 30 with PhysicalDBPool

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

the class ConfigTest method testTempReadHostAvailable.

/**
 * testTempReadHostAvailable
 */
@Test
public void testTempReadHostAvailable() {
    PhysicalDBPool pool = this.dataHosts.get("localhost2");
    DataHostConfig hostConfig = pool.getSource().getHostConfig();
    Assert.assertTrue(hostConfig.isTempReadHostAvailable() == true);
}
Also used : PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) Test(org.junit.Test)

Aggregations

PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)31 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)16 ServerConfig (com.actiontech.dble.config.ServerConfig)9 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)3 UserConfig (com.actiontech.dble.config.model.UserConfig)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 Set (java.util.Set)3 ConfigInitializer (com.actiontech.dble.config.ConfigInitializer)2 ConfigException (com.actiontech.dble.config.util.ConfigException)2 OkPacket (com.actiontech.dble.net.mysql.OkPacket)2 OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)2