use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.
the class UXmlSchemaLoader 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;
}
Schemas schema = new Schemas();
// the config Value in ucore is an all in one json config of the schema.xml
JSONObject jsonObj = JSONObject.parseObject(configValue.getValue());
List<Schema> schemaList = parseJsonSchema.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.SCHEMA_SCHEMA).toJSONString());
schema.setSchema(schemaList);
List<DataNode> dataNodeList = parseJsonDataNode.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.DATA_NODE).toJSONString());
schema.setDataNode(dataNodeList);
List<DataHost> dataHostList = parseJsonDataHost.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.DATA_HOST).toJSONString());
schema.setDataHost(dataHostList);
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);
this.parseSchemaXmlService.parseToXmlWrite(schema, path, "schema");
LOGGER.info("SchemasLoader notifyProcess ucore to object zk schema write :" + path + " is success");
}
use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.
the class UXmlServerLoader 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;
}
Server server = new Server();
JSONObject jsonObj = JSONObject.parseObject(configValue.getValue());
if (jsonObj.get(UcorePathUtil.FIREWALL) != null) {
server.setFirewall(parseJsonFireWall.parseJsonToBean(jsonObj.getJSONObject(UcorePathUtil.FIREWALL).toJSONString()));
}
server.setSystem(parseJsonSystem.parseJsonToBean(jsonObj.getJSONObject(UcorePathUtil.DEFAULT).toJSONString()));
server.setUser(parseJsonUser.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.USER).toJSONString()));
if (jsonObj.get(UcorePathUtil.ALARM) != null) {
server.setAlarm(parseJsonAlarm.parseJsonToBean(jsonObj.getJSONObject(UcorePathUtil.ALARM).toJSONString()));
}
String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
path = new File(path).getPath() + File.separator;
path += WRITEPATH;
this.parseServerXMl.parseToXmlWrite(server, path, "server");
}
use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.
the class CKVStoreRepository method delete.
/**
* delete ucore K/V view meta
* try get the view meta lock & delete the view meta
* then create a delete view node ,wait for all the online node response
* check all the response data send the alarm if not success
* @param schemaName
* @param viewName
*/
@Override
public void delete(String schemaName, String[] viewName) {
for (String view : viewName) {
StringBuffer sb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(view);
StringBuffer nsb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(UPDATE).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(view);
StringBuffer lsb = new StringBuffer().append(UcorePathUtil.getViewPath()).append(SEPARATOR).append(LOCK).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(view);
UDistributeLock distributeLock = new UDistributeLock(lsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + DELETE);
try {
viewCreateSqlMap.get(schemaName).remove(view);
int time = 0;
while (!distributeLock.acquire()) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
if (time++ % 10 == 0) {
LOGGER.warn(" view meta waiting for the lock " + schemaName + " " + view);
}
}
ClusterUcoreSender.deleteKV(sb.toString());
ClusterUcoreSender.sendDataToUcore(nsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + DELETE);
// check if the online node number is equals to the reponse number
List<UKvBean> onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
List<UKvBean> reponseList = ClusterUcoreSender.getKeyTree(nsb.toString());
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
if (reponseList != null) {
for (UKvBean kv : reponseList) {
if (!kv.getValue().equals(UcorePathUtil.SUCCESS)) {
LOGGER.info(AlarmCode.CORE_CLUSTER_WARN + "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 ShowBinlogStatus method showBinlogWithUcore.
private static void showBinlogWithUcore(ManagerConnection c, long timeout) {
// step 1 get the distributeLock of the ucore
UDistributeLock distributeLock = new UDistributeLock(UcorePathUtil.getBinlogPauseLockPath(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
try {
if (!distributeLock.acquire()) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "There is another command is showing BinlogStatus");
return;
}
try {
// step 2 try to lock all the commit flag in server
if (!DbleServer.getInstance().getBackupLocked().compareAndSet(false, true)) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "There is another command is showing BinlogStatus");
} else {
// step 3 notify other dble to stop the commit & set self status
BinlogPause pauseOnInfo = new BinlogPause(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.ON);
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), pauseOnInfo.toString());
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatusSelf(), "true");
// step 4 wait til other dbles to feedback the ucore flag
long beginTime = TimeUtil.currentTimeMillis();
boolean isAllSuccess = true;
List<UKvBean> responseList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getBinlogPauseStatus());
List<UKvBean> onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
while (responseList.size() < onlineList.size()) {
// if it is time out
if (TimeUtil.currentTimeMillis() > beginTime + 2 * timeout) {
isAllSuccess = false;
errMsg = "timeout while waiting for unfinished distributed transactions.";
logger.info(errMsg);
break;
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(1000));
responseList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getBinlogPauseStatus());
onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
}
// step 5 check the result if the all the dbles return sucess
if (isAllSuccess) {
for (UKvBean reponseBean : responseList) {
if (!Boolean.parseBoolean(reponseBean.getValue())) {
isAllSuccess = false;
}
}
}
// step 6 query for the GTID and write back to frontend connections
if (isAllSuccess) {
getQueryResult(c.getCharset().getResults());
}
writeResponse(c);
// step 7 delete the KVtree and notify the cluster
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getBinlogPauseStatus() + SEPARATOR);
BinlogPause pauseOffInfo = new BinlogPause(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.OFF);
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), pauseOffInfo.toString());
}
} catch (Exception e) {
logger.info("catch Exception", e);
} finally {
DbleServer.getInstance().getBackupLocked().compareAndSet(true, false);
distributeLock.release();
}
} catch (Exception e) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, e.getMessage());
}
}
use of com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean in project dble by actiontech.
the class ProxyMetaManager method notifyReponseUcoreDDL.
/**
* Notify the ucore Cluster to do things
*
* @param schema
* @param table
* @param sql
* @param ddlStatus
* @param needNotifyOther
* @throws Exception
*/
public void notifyReponseUcoreDDL(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus, boolean needNotifyOther) throws Exception {
String nodeName = StringUtil.getUFullName(schema, table);
DDLInfo ddlInfo = new DDLInfo(schema, sql, UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus);
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(nodeName), ddlInfo.toString());
if (needNotifyOther) {
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLPath(nodeName), ddlInfo.toString());
while (true) {
List<UKvBean> reponseList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getDDLPath(nodeName));
List<UKvBean> onlineList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getOnlinePath());
if (reponseList.size() >= onlineList.size()) {
// release the lock
UDistrbtLockManager.releaseLock(UcorePathUtil.getDDLPath(nodeName));
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getDDLPath(nodeName) + "/");
break;
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
}
}
}
Aggregations