use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo in project dble by actiontech.
the class ProxyMetaManager method notifyClusterDDL.
public void notifyClusterDDL(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus) throws Exception {
if (DbleServer.getInstance().isUseZK()) {
CuratorFramework zkConn = ZKUtils.getConnection();
DDLInfo ddlInfo = new DDLInfo(schema, sql, ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus);
String nodeName = StringUtil.getFullName(schema, table);
String nodePath = ZKPaths.makePath(KVPathUtil.getDDLPath(), nodeName);
zkConn.create().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8));
} else if (DbleServer.getInstance().isUseUcore()) {
DDLInfo ddlInfo = new DDLInfo(schema, sql, UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus);
String nodeName = StringUtil.getUFullName(schema, table);
UDistributeLock lock = new UDistributeLock(UcorePathUtil.getDDLPath(nodeName), ddlInfo.toString());
// ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLPath(nodeName), ddlInfo.toString());
while (!lock.acquire()) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
}
UDistrbtLockManager.addLock(lock);
}
}
use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo 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));
}
}
}
use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo in project dble by actiontech.
the class UDdlChildResponse method notifyProcess.
@Override
public void notifyProcess(UKvBean configValue) throws Exception {
if (configValue.getKey().split("/").length == UcorePathUtil.getDDLPath().split("/").length + 2) {
// only response for the key /un.../d.../clu.../ddl/schema.table
return;
} else {
LOGGER.debug("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
String nodeName = configValue.getKey().split("/")[4];
String[] tableInfo = nodeName.split("\\.");
final String schema = StringUtil.removeBackQuote(tableInfo[0]);
final String table = StringUtil.removeBackQuote(tableInfo[1]);
if (UKvBean.DELETE.equals(configValue.getChangeType()) || "".equals(configValue.getValue())) {
return;
}
DDLInfo ddlInfo = new DDLInfo(configValue.getValue());
if (ddlInfo.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
// self node
return;
}
String fullName = schema + "." + table;
// if the start node is preparing to do the ddl
if (ddlInfo.getStatus() == DDLInfo.DDLStatus.INIT) {
LOGGER.debug("init of ddl " + schema + " " + table);
try {
lockMap.put(fullName, ddlInfo.getFrom());
DbleServer.getInstance().getTmManager().addMetaLock(schema, table);
} catch (Exception t) {
DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
throw t;
}
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.SUCCESS && configValue.getChangeType() != UKvBean.DELETE && lockMap.containsKey(fullName)) {
// if the start node is done the ddl execute
lockMap.remove(fullName);
// to judge the table is be drop
SQLStatementParser parser = new MySqlStatementParser(ddlInfo.getSql());
SQLStatement statement = parser.parseStatement();
if (statement instanceof SQLDropTableStatement) {
DbleServer.getInstance().getTmManager().updateMetaData(ddlInfo.getSchema(), ddlInfo.getSql(), DDLInfo.DDLStatus.SUCCESS.equals(ddlInfo.getStatus()), false);
} else {
// else get the lastest table meta from db
DbleServer.getInstance().getTmManager().updateOnetableWithBackData(DbleServer.getInstance().getConfig(), schema, table);
}
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(fullName), "SUCCESS");
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.FAILED && configValue.getChangeType() != UKvBean.DELETE) {
// if the start node executing ddl with error,just release the lock
lockMap.remove(fullName);
DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(fullName), "FAILED");
}
}
}
Aggregations