Search in sources :

Example 1 with ERTable

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

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

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

the class DruidUpdateParser method isJoinColumn.

/**
 * @param schema
 * @param tableName
 * @return
 */
private boolean isJoinColumn(String column, SchemaConfig schema, String tableName) {
    Map<ERTable, Set<ERTable>> map = schema.getFkErRelations();
    ERTable key = new ERTable(schema.getName(), tableName, column);
    return map.containsKey(key);
}
Also used : Set(java.util.Set) ERTable(com.actiontech.dble.config.model.ERTable)

Example 4 with ERTable

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

the class ERJoinChooser method getLeftOutJoinChildER.

private ERTable getLeftOutJoinChildER(JoinNode joinNode, PlanNode child, Item onItem) {
    if (PlanUtil.existAggregate(child))
        return null;
    else if (!PlanUtil.isERNode(child) && child.type() != PlanNode.PlanNodeType.TABLE)
        return null;
    if (onItem == null || !onItem.type().equals(Item.ItemType.FIELD_ITEM))
        return null;
    Pair<TableNode, ItemField> joinColumnInfo = PlanUtil.findColumnInTableLeaf((ItemField) onItem, joinNode);
    if (joinColumnInfo == null)
        return null;
    TableNode tn = joinColumnInfo.getKey();
    ItemField col = joinColumnInfo.getValue();
    ERTable erKey = new ERTable(tn.getSchema(), tn.getPureName(), col.getItemName());
    if (child.type() == PlanNode.PlanNodeType.TABLE) {
        return erKey;
    } else {
        // joinnode
        List<ERTable> erKeys = ((JoinNode) child).getERkeys();
        for (ERTable cerKey : erKeys) {
            if (isErRelation(erKey, cerKey))
                return erKey;
        }
        return null;
    }
}
Also used : JoinNode(com.actiontech.dble.plan.node.JoinNode) TableNode(com.actiontech.dble.plan.node.TableNode) ERTable(com.actiontech.dble.config.model.ERTable) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Example 5 with ERTable

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

the class ERJoinChooser method getERKey.

private ERTable getERKey(PlanNode tn, Item c) {
    if (!(c instanceof ItemField))
        return null;
    if (tn.type() != PlanNode.PlanNodeType.TABLE && !PlanUtil.isERNode(tn)) {
        return null;
    }
    Pair<TableNode, ItemField> pair = PlanUtil.findColumnInTableLeaf((ItemField) c, tn);
    if (pair == null)
        return null;
    TableNode tableNode = pair.getKey();
    ItemField col = pair.getValue();
    ERTable cm = new ERTable(tableNode.getSchema(), tableNode.getPureName(), col.getItemName());
    if (tn.type() == PlanNode.PlanNodeType.TABLE) {
        return cm;
    } else {
        List<ERTable> erList = ((JoinNode) tn).getERkeys();
        for (ERTable cerKey : erList) {
            if (isErRelation(cm, cerKey))
                return cm;
        }
        return null;
    }
}
Also used : JoinNode(com.actiontech.dble.plan.node.JoinNode) TableNode(com.actiontech.dble.plan.node.TableNode) ERTable(com.actiontech.dble.config.model.ERTable) ItemField(com.actiontech.dble.plan.common.item.ItemField)

Aggregations

ERTable (com.actiontech.dble.config.model.ERTable)7 Set (java.util.Set)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)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 ConfigInitializer (com.actiontech.dble.config.ConfigInitializer)2 ServerConfig (com.actiontech.dble.config.ServerConfig)2 ItemField (com.actiontech.dble.plan.common.item.ItemField)2 JoinNode (com.actiontech.dble.plan.node.JoinNode)2 TableNode (com.actiontech.dble.plan.node.TableNode)2 ItemFuncEqual (com.actiontech.dble.plan.common.item.function.operator.cmpfunc.ItemFuncEqual)1 PlanNode (com.actiontech.dble.plan.node.PlanNode)1 SystemVariables (com.actiontech.dble.server.variables.SystemVariables)1 VarsExtractorHandler (com.actiontech.dble.server.variables.VarsExtractorHandler)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1