Search in sources :

Example 21 with PhysicalDBNode

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

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

the class NonBlockingSession method kill.

protected void kill() {
    AtomicInteger count = new AtomicInteger(0);
    Map<RouteResultsetNode, BackendConnection> toKilled = new HashMap<>();
    for (Map.Entry<RouteResultsetNode, BackendConnection> entry : target.entrySet()) {
        BackendConnection c = entry.getValue();
        if (c != null && !c.isDDL()) {
            toKilled.put(entry.getKey(), c);
            count.incrementAndGet();
        } else if (c != null && c.isDDL()) {
            // if the sql executing is a ddl,do not kill the query,just close the connection
            this.terminate();
            return;
        }
    }
    for (Entry<RouteResultsetNode, BackendConnection> en : toKilled.entrySet()) {
        KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this);
        ServerConfig conf = DbleServer.getInstance().getConfig();
        PhysicalDBNode dn = conf.getDataNodes().get(en.getKey().getName());
        try {
            dn.getConnectionFromSameSource(en.getValue().getSchema(), true, en.getValue(), kill, en.getKey());
        } catch (Exception e) {
            LOGGER.info("get killer connection failed for " + en.getKey(), e);
            kill.connectionError(e, null);
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) BackendConnection(com.actiontech.dble.backend.BackendConnection) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 23 with PhysicalDBNode

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

the class VarsExtractorHandler method execute.

public SystemVariables execute() {
    Map.Entry<String, PhysicalDBNode> entry = dataNodes.entrySet().iterator().next();
    OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_VARIABLES_COLS, new MysqlVarsListener(this));
    PhysicalDBNode dn = entry.getValue();
    SQLJob sqlJob = new SQLJob(MYSQL_SHOW_VARIABLES, dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
    sqlJob.run();
    waitDone();
    return systemVariables;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) OneRawSQLQueryResultHandler(com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler) SQLJob(com.actiontech.dble.sqlengine.SQLJob) Map(java.util.Map)

Example 24 with PhysicalDBNode

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

the class SQLJob method run.

public void run() {
    try {
        if (ds == null) {
            RouteResultsetNode node = new RouteResultsetNode(dataNodeOrDatabase, ServerParse.SELECT, sql);
            // create new connection
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), true, true, node, this, node);
        } else {
            ds.getConnection(dataNodeOrDatabase, true, this, null);
        }
    } catch (Exception e) {
        LOGGER.info("can't get connection for sql ,error:" + e);
        doFinished(true);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 25 with PhysicalDBNode

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

the class ShowTableDataNode method getRows.

private static List<RowDataPacket> getRows(List<String> dataNodes, String charset) {
    List<RowDataPacket> list = new ArrayList<>();
    int sequence = 0;
    for (String dataNode : dataNodes) {
        PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
        DBHostConfig dbConfig = dn.getDbPool().getSource().getConfig();
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(dn.getName(), charset));
        row.add(LongUtil.toBytes(sequence));
        row.add(StringUtil.encode(dbConfig.getIp(), charset));
        row.add(LongUtil.toBytes(dbConfig.getPort()));
        row.add(StringUtil.encode(dn.getDatabase(), charset));
        row.add(StringUtil.encode(dbConfig.getUser(), charset));
        row.add(StringUtil.encode(dbConfig.getPassword(), charset));
        list.add(row);
        sequence++;
    }
    return list;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList)

Aggregations

PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)27 ServerConfig (com.actiontech.dble.config.ServerConfig)9 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)9 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)8 BackendConnection (com.actiontech.dble.backend.BackendConnection)7 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)5 SQLJob (com.actiontech.dble.sqlengine.SQLJob)4 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)3 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)3 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3 UserConfig (com.actiontech.dble.config.model.UserConfig)3 ConfigException (com.actiontech.dble.config.util.ConfigException)3 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)3 OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)3 Map (java.util.Map)3 Set (java.util.Set)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConfigInitializer (com.actiontech.dble.config.ConfigInitializer)2 DBHostConfig (com.actiontech.dble.config.model.DBHostConfig)2