Search in sources :

Example 1 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class NoNameNodeHandlerBuilder method buildOwn.

@Override
public void buildOwn() {
    PushDownVisitor visitor = new PushDownVisitor(node, true);
    visitor.visit();
    this.canPushDown = true;
    String sql = visitor.getSql().toString();
    String schema = session.getSource().getSchema();
    SchemaConfig schemaConfig = schemaConfigMap.get(schema);
    RouteResultsetNode[] rrss = getTableSources(schemaConfig.getAllDataNodes(), sql);
    hBuilder.checkRRSs(rrss);
    MultiNodeMergeHandler mh = new MultiNodeMergeHandler(getSequenceId(), rrss, session.getSource().isAutocommit() && !session.getSource().isTxStart(), session, null);
    addHandler(mh);
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) MultiNodeMergeHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.MultiNodeMergeHandler) PushDownVisitor(com.actiontech.dble.backend.mysql.nio.handler.builder.sqlvisitor.PushDownVisitor)

Example 2 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class CKVStoreRepository method init.

@Override
public void init() {
    List<UKvBean> allList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getViewPath());
    for (UKvBean bean : allList) {
        String[] key = bean.getKey().split("/");
        if (key.length == 5) {
            String[] value = key[key.length - 1].split(SCHEMA_VIEW_SPLIT);
            if (viewCreateSqlMap.get(value[0]) == null) {
                Map<String, String> schemaMap = new ConcurrentHashMap<String, String>();
                viewCreateSqlMap.put(value[0], schemaMap);
            }
            viewCreateSqlMap.get(value[0]).put(value[1], bean.getValue());
        }
    }
    for (Map.Entry<String, SchemaConfig> schema : DbleServer.getInstance().getConfig().getSchemas().entrySet()) {
        if (viewCreateSqlMap.get(schema.getKey()) == null) {
            viewCreateSqlMap.put(schema.getKey(), new ConcurrentHashMap<String, String>());
        }
    }
}
Also used : SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig 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 4 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig 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 5 with SchemaConfig

use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.

the class ShowDataNode method execute.

public static void execute(ManagerConnection c, String name) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    Map<String, PhysicalDBNode> dataNodes = conf.getDataNodes();
    List<String> keys = new ArrayList<>();
    if (StringUtil.isEmpty(name)) {
        keys.addAll(dataNodes.keySet());
    } else {
        SchemaConfig sc = conf.getSchemas().get(name);
        if (null != sc) {
            keys.addAll(sc.getAllDataNodes());
        }
    }
    Collections.sort(keys, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            Pair<String, Integer> p1 = PairUtil.splitIndex(o1, '[', ']');
            Pair<String, Integer> p2 = PairUtil.splitIndex(o2, '[', ']');
            if (p1.getKey().compareTo(p2.getKey()) == 0) {
                return p1.getValue() - p2.getValue();
            } else {
                return p1.getKey().compareTo(p2.getKey());
            }
        }
    });
    for (String key : keys) {
        RowDataPacket row = getRow(dataNodes.get(key), c.getCharset().getResults());
        if (row != null) {
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) ServerConfig(com.actiontech.dble.config.ServerConfig) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Pair(com.actiontech.dble.route.parser.util.Pair)

Aggregations

SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)70 TableConfig (com.actiontech.dble.config.model.TableConfig)16 SQLNonTransientException (java.sql.SQLNonTransientException)16 Test (org.junit.Test)15 RouteResultset (com.actiontech.dble.route.RouteResultset)6 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)5 ServerConfig (com.actiontech.dble.config.ServerConfig)5 UserConfig (com.actiontech.dble.config.model.UserConfig)5 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 CacheService (com.actiontech.dble.cache.CacheService)4 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)4 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 StringPtr (com.actiontech.dble.plan.common.ptr.StringPtr)4 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)3 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3