Search in sources :

Example 6 with PhysicalDBPool

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

the class ConfigInitializer method initDataHosts.

private Map<String, PhysicalDBPool> initDataHosts(SchemaLoader schemaLoader) {
    Map<String, DataHostConfig> nodeConf = schemaLoader.getDataHosts();
    // create PhysicalDBPool according to DataHost
    Map<String, PhysicalDBPool> nodes = new HashMap<>(nodeConf.size());
    for (DataHostConfig conf : nodeConf.values()) {
        // create PhysicalDBPool
        PhysicalDBPool pool = getPhysicalDBPool(conf);
        nodes.put(pool.getHostName(), pool);
    }
    return nodes;
}
Also used : PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Example 7 with PhysicalDBPool

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

the class SelectHandler method handle.

public static void handle(String stmt, ManagerConnection c, int offset) {
    switch(ManagerParseSelect.parse(stmt, offset)) {
        case VERSION_COMMENT:
            SelectVersionComment.response(c);
            break;
        case SESSION_TX_READ_ONLY:
            SelectSessionTxReadOnly.execute(c);
            break;
        case MAX_ALLOWED_PACKET:
            SelectMaxAllowedPacket.execute(c);
            break;
        default:
            if (isSupportSelect(stmt)) {
                Iterator<PhysicalDBPool> iterator = DbleServer.getInstance().getConfig().getDataHosts().values().iterator();
                if (iterator.hasNext()) {
                    PhysicalDBPool pool = iterator.next();
                    final PhysicalDatasource source = pool.getSource();
                    TransformSQLJob sqlJob = new TransformSQLJob(stmt, pool.getSchemas()[0], source, c);
                    sqlJob.run();
                } else {
                    c.writeErrMessage(ErrorCode.ER_YES, "no valid data host");
                }
            } else {
                c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
            }
    }
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) TransformSQLJob(com.actiontech.dble.sqlengine.TransformSQLJob)

Example 8 with PhysicalDBPool

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

the class ReloadConfig method reload.

public static void reload() throws Exception {
    /* 1 load new conf, ConfigInitializer will check itself */
    ConfigInitializer loader;
    try {
        loader = new ConfigInitializer(false, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
    } catch (Exception e) {
        throw new Exception(e);
    }
    Map<String, UserConfig> users = loader.getUsers();
    Map<String, SchemaConfig> schemas = loader.getSchemas();
    Map<String, PhysicalDBNode> dataNodes = loader.getDataNodes();
    Map<String, PhysicalDBPool> dataHosts = loader.getDataHosts();
    Map<ERTable, Set<ERTable>> erRelations = loader.getErRelations();
    FirewallConfig firewall = loader.getFirewall();
    /* 2 apply the new conf */
    DbleServer.getInstance().getConfig().reload(users, schemas, dataNodes, dataHosts, erRelations, firewall, DbleServer.getInstance().getSystemVariables(), loader.isDataHostWithoutWH(), false);
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Set(java.util.Set) ConfigInitializer(com.actiontech.dble.config.ConfigInitializer) 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)

Example 9 with PhysicalDBPool

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

the class ReloadConfig method reloadAll.

public static void reloadAll(final int loadAllMode) throws Exception {
    /*
         *  1 load new conf
         *  1.1 ConfigInitializer init adn check itself
         *  1.2 DataNode/DataHost test connection
         */
    ConfigInitializer loader;
    try {
        loader = new ConfigInitializer(true, DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames());
    } catch (Exception e) {
        throw new Exception(e);
    }
    Map<String, UserConfig> newUsers = loader.getUsers();
    Map<String, SchemaConfig> newSchemas = loader.getSchemas();
    Map<String, PhysicalDBNode> newDataNodes = loader.getDataNodes();
    Map<String, PhysicalDBPool> newDataHosts = loader.getDataHosts();
    Map<ERTable, Set<ERTable>> newErRelations = loader.getErRelations();
    FirewallConfig newFirewall = loader.getFirewall();
    SystemVariables newSystemVariables = DbleServer.getInstance().getSystemVariables();
    if (!loader.isDataHostWithoutWH()) {
        VarsExtractorHandler handler = new VarsExtractorHandler(newDataNodes);
        newSystemVariables = handler.execute();
        ConfigInitializer confInit = new ConfigInitializer(newSystemVariables.isLowerCaseTableNames());
        newUsers = confInit.getUsers();
        newSchemas = confInit.getSchemas();
        newDataNodes = confInit.getDataNodes();
        newErRelations = confInit.getErRelations();
        newFirewall = confInit.getFirewall();
        newDataHosts = confInit.getDataHosts();
    }
    if ((loadAllMode & ManagerParseConfig.OPTT_MODE) != 0) {
        try {
            loader.testConnection(false);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
    /*
         *  2 transform
         *  2.1 old dataSource continue to work
         *  2.2 init the new dataSource
         *  2.3 transform
         *  2.4 put the old connection into a queue
         */
    ServerConfig config = DbleServer.getInstance().getConfig();
    /* 2.1 do nothing */
    boolean isReloadStatusOK = true;
    /* 2.2 init the new dataSource */
    for (PhysicalDBPool dbPool : newDataHosts.values()) {
        String hostName = dbPool.getHostName();
        // set schemas
        ArrayList<String> dnSchemas = new ArrayList<>(30);
        for (PhysicalDBNode dn : newDataNodes.values()) {
            if (dn.getDbPool().getHostName().equals(hostName)) {
                dnSchemas.add(dn.getDatabase());
            }
        }
        dbPool.setSchemas(dnSchemas.toArray(new String[dnSchemas.size()]));
        // get data host
        String dnIndex = DnPropertyUtil.loadDnIndexProps().getProperty(dbPool.getHostName(), "0");
        if (!"0".equals(dnIndex)) {
            LOGGER.info("init data host: " + dbPool.getHostName() + " to use datasource index:" + dnIndex);
        }
        dbPool.init(Integer.parseInt(dnIndex));
        if (!dbPool.isInitSuccess()) {
            isReloadStatusOK = false;
            break;
        }
    }
    if (isReloadStatusOK) {
        /* 2.3 apply new conf */
        config.reload(newUsers, newSchemas, newDataNodes, newDataHosts, newErRelations, newFirewall, newSystemVariables, loader.isDataHostWithoutWH(), true);
        recycleOldBackendConnections(config, ((loadAllMode & ManagerParseConfig.OPTF_MODE) != 0));
        AlarmAppender.refreshConfig();
    } else {
        // INIT FAILED
        LOGGER.info("reload failed, clear previously created data sources ");
        for (PhysicalDBPool dbPool : newDataHosts.values()) {
            dbPool.clearDataSources("reload config");
            dbPool.stopHeartbeat();
        }
        throw new Exception("Init DbPool failed");
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) VarsExtractorHandler(com.actiontech.dble.server.variables.VarsExtractorHandler) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Set(java.util.Set) ConfigInitializer(com.actiontech.dble.config.ConfigInitializer) ArrayList(java.util.ArrayList) 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) SystemVariables(com.actiontech.dble.server.variables.SystemVariables) ServerConfig(com.actiontech.dble.config.ServerConfig)

Example 10 with PhysicalDBPool

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

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