Search in sources :

Example 1 with UKvBean

use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.

the class ClusterUcoreSender method getKey.

public static UKvBean getKey(String key) {
    UcoreInterface.GetKvInput input = UcoreInterface.GetKvInput.newBuilder().setKey(key).build();
    if (stub == null) {
        init();
    }
    UcoreInterface.GetKvOutput output = stub.getKv(input);
    UKvBean bean = new UKvBean(key, output.getValue(), 0);
    return bean;
}
Also used : UcoreInterface(com.actiontech.dble.log.alarm.UcoreInterface) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)

Example 2 with UKvBean

use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.

the class CKVStoreRepository method put.

@Override
public void put(String schemaName, String viewName, String createSql) {
    Map<String, String> schemaMap = viewCreateSqlMap.get(schemaName);
    StringBuffer sb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(viewName);
    StringBuffer lsb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(LOCK).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(viewName);
    StringBuffer nsb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(UPDATE).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(viewName);
    UDistributeLock distributeLock = new UDistributeLock(lsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + UPDATE);
    try {
        int time = 0;
        while (!distributeLock.acquire()) {
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
            if (time++ % 10 == 0) {
                LOGGER.info(" view meta waiting for the lock " + schemaName + " " + viewName);
            }
        }
        schemaMap.put(viewName, createSql);
        ClusterUcoreSender.sendDataToUcore(sb.toString(), createSql);
        ClusterUcoreSender.sendDataToUcore(nsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + UPDATE);
        // check if the online node number is equals to the reponse number
        List<UKvBean> onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath() + SEPARATOR);
        List<UKvBean> reponseList = ClusterUcoreSender.getKeyTree(nsb.toString() + SEPARATOR);
        while (reponseList.size() < onlineList.size() - 1) {
            LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
            onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
            reponseList = ClusterUcoreSender.getKeyTree(nsb.toString());
        }
        // check all the node status is success
        for (UKvBean kv : reponseList) {
            if (!kv.getValue().equals(UcorePathUtil.SUCCESS)) {
                LOGGER.info("view mate change error on key " + kv.getKey());
            }
        }
        ClusterUcoreSender.deleteKVTree(nsb.toString() + SEPARATOR);
        distributeLock.release();
    } catch (Exception e) {
        LOGGER.warn(AlarmCode.CORE_ZK_WARN + "delete ucore node error : " + e.getMessage());
    }
}
Also used : UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)

Example 3 with UKvBean

use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean 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 4 with UKvBean

use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.

the class UXmlEhcachesLoader method notifyProcess.

@Override
public void notifyProcess(UKvBean configValue) throws Exception {
    UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
    if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
        return;
    }
    JSONObject jsonObj = JSONObject.parseObject(configValue.getValue());
    if (jsonObj.get(UcorePathUtil.EHCACHE) != null) {
        Ehcache ehcache = parseJsonEhcacheService.parseJsonToBean(jsonObj.getJSONObject(UcorePathUtil.EHCACHE).toJSONString());
        String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
        path = new File(path).getPath() + File.separator + WRITEPATH;
        this.parseEcacheXMl.parseToXmlWrite(ehcache, path, null);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Ehcache(com.actiontech.dble.config.loader.zkprocess.entity.cache.Ehcache) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean) File(java.io.File)

Example 5 with UKvBean

use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.

the class UXmlRuleLoader method notifyProcess.

@Override
public void notifyProcess(UKvBean configValue) throws Exception {
    UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
    if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
        return;
    }
    Rules rule = new Rules();
    // the config Value in ucore is an all in one json config of the schema.xml
    JSONObject jsonObj = JSONObject.parseObject(configValue.getValue());
    List<Function> functions = parseJsonFunctionService.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.FUNCTION).toJSONString());
    rule.setFunction(functions);
    List<TableRule> tableRules = parseJsonTableRuleService.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.TABLE_RULE).toJSONString());
    rule.setTableRule(tableRules);
    String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
    path = new File(path).getPath() + File.separator;
    path += WRITEPATH;
    LOGGER.info("SchemasLoader notifyProcess ucore to object writePath :" + path);
    writeMapFileAddFunction(functions);
    this.parseRulesXMl.parseToXmlWrite(rule, path, "rule");
    LOGGER.info("SchemasLoader notifyProcess ucore to object zk schema      write :" + path + " is success");
}
Also used : TableRule(com.actiontech.dble.config.loader.zkprocess.entity.rule.tablerule.TableRule) Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) JSONObject(com.alibaba.fastjson.JSONObject) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean) Rules(com.actiontech.dble.config.loader.zkprocess.entity.Rules) File(java.io.File)

Aggregations

UKvBean (com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)16 JSONObject (com.alibaba.fastjson.JSONObject)5 File (java.io.File)4 HashMap (java.util.HashMap)4 UcoreInterface (com.actiontech.dble.log.alarm.UcoreInterface)3 Map (java.util.Map)3 BinlogPause (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause)2 UDistributeLock (com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock)1 Rules (com.actiontech.dble.config.loader.zkprocess.entity.Rules)1 Schemas (com.actiontech.dble.config.loader.zkprocess.entity.Schemas)1 Server (com.actiontech.dble.config.loader.zkprocess.entity.Server)1 Ehcache (com.actiontech.dble.config.loader.zkprocess.entity.cache.Ehcache)1 Function (com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function)1 TableRule (com.actiontech.dble.config.loader.zkprocess.entity.rule.tablerule.TableRule)1 DataHost (com.actiontech.dble.config.loader.zkprocess.entity.schema.datahost.DataHost)1 DataNode (com.actiontech.dble.config.loader.zkprocess.entity.schema.datanode.DataNode)1 Schema (com.actiontech.dble.config.loader.zkprocess.entity.schema.schema.Schema)1 DDLInfo (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo)1 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 ArrayList (java.util.ArrayList)1