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;
}
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());
}
}
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>());
}
}
}
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);
}
}
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");
}
Aggregations