mirror of
https://github.com/actiontech/dble.git
synced 2026-01-06 04:40:17 -06:00
* #1055 Refactor the cluster related part to support more clustering type * #1055 enableAlert miss * #1055 checkClusterConfig before start cluster helper * #1055 add changeable rootPath * #1055 change alert logic * #1055 delete line
This commit is contained in:
@@ -151,7 +151,7 @@
|
||||
|
||||
<module name="UncommentedMain">
|
||||
<property name="excludedClasses"
|
||||
value="(com\.actiontech\.dble\.DbleStartup)|(com\.actiontech\.dble\.config\.loader\.zkprocess\.xmltozk\.XmltoZkMain)|(com\.actiontech\.dble\.util\.DecryptUtil)|(com\.actiontech\.dble\.util\.dataMigrator\.DataMigrator)|(com\.actiontech\.dble\.config\.loader\.ucoreprocess\.XmltoUcore)"/>
|
||||
value="(com\.actiontech\.dble\.DbleStartup)|(com\.actiontech\.dble\.config\.loader\.zkprocess\.xmltozk\.XmltoZkMain)|(com\.actiontech\.dble\.util\.DecryptUtil)|(com\.actiontech\.dble\.util\.dataMigrator\.DataMigrator)|(com\.actiontech\.dble\.cluster\.xmltoKv\.XmltoCluster)"/>
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="arrayInitIndent" value="8"/>
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<suppress checks=".*" files="StructureMeta.java"/>
|
||||
<suppress checks=".*" files="UcoreInterface.java"/>
|
||||
<suppress checks=".*" files="UcoreGrpc.java"/>
|
||||
<suppress checks=".*" files="UshardInterface.java"/>
|
||||
<suppress checks=".*" files="DbleClusterGrpc.java"/>
|
||||
<suppress checks="Indentation" files="MyTime.java"/>
|
||||
<suppress checks="CyclomaticComplexity" files="MyTime.java"/>
|
||||
<suppress checks="CyclomaticComplexity" files="TimSort.java"/>
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<Match>
|
||||
<Class name="com.actiontech.dble.meta.protocol.StructureMeta$TableMeta$Builder"/>
|
||||
</Match>
|
||||
<Match>
|
||||
<Package name="com.actiontech.dble.cluster.impl.ushard"/>
|
||||
</Match>
|
||||
<Match>
|
||||
<Package name="com.actiontech.dble.alarm"/>
|
||||
</Match>
|
||||
|
||||
@@ -16,9 +16,9 @@ import com.actiontech.dble.backend.mysql.xa.recovery.impl.KVStoreRepository;
|
||||
import com.actiontech.dble.buffer.BufferPool;
|
||||
import com.actiontech.dble.buffer.DirectByteBufferPool;
|
||||
import com.actiontech.dble.cache.CacheService;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.ServerConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.config.model.SchemaConfig;
|
||||
import com.actiontech.dble.config.model.SystemConfig;
|
||||
@@ -75,6 +75,7 @@ public final class DbleServer {
|
||||
private static final long DEFAULT_OLD_CONNECTION_CLEAR_PERIOD = 5 * 1000L;
|
||||
|
||||
private static final DbleServer INSTANCE = new DbleServer();
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("Server");
|
||||
private AtomicBoolean backupLocked;
|
||||
|
||||
@@ -171,8 +172,8 @@ public final class DbleServer {
|
||||
id.append("'" + NAME + "Server.");
|
||||
if (isUseZK()) {
|
||||
id.append(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} else if (isUseUcore()) {
|
||||
id.append(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} else if (isUseGeneralCluster()) {
|
||||
id.append(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} else {
|
||||
id.append(this.getConfig().getSystem().getServerNodeId());
|
||||
|
||||
@@ -363,6 +364,7 @@ public final class DbleServer {
|
||||
if (system.getEnableSlowLog() == 1) {
|
||||
SlowQueryLog.getInstance().setEnableSlowLog(true);
|
||||
}
|
||||
AlertUtil.initAlert();
|
||||
if (system.getEnableAlert() == 1) {
|
||||
AlertUtil.switchAlert(true);
|
||||
}
|
||||
@@ -426,7 +428,7 @@ public final class DbleServer {
|
||||
|
||||
userManager.initForLatest(config.getUsers(), system.getMaxCon());
|
||||
|
||||
if (isUseUcore()) {
|
||||
if (isUseGeneralCluster()) {
|
||||
try {
|
||||
OnlineLockStatus.getInstance().metaUcoreInit(true);
|
||||
} catch (Exception e) {
|
||||
@@ -694,11 +696,12 @@ public final class DbleServer {
|
||||
}
|
||||
|
||||
public boolean isUseZK() {
|
||||
return ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) != null;
|
||||
return ClusterGeneralConfig.getInstance().isUseCluster() && ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) != null;
|
||||
}
|
||||
|
||||
public boolean isUseUcore() {
|
||||
return UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) != null;
|
||||
public boolean isUseGeneralCluster() {
|
||||
return ClusterGeneralConfig.getInstance().isUseCluster() &&
|
||||
ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) == null;
|
||||
}
|
||||
|
||||
public TxnLogProcessor getTxnLogProcessor() {
|
||||
@@ -1081,4 +1084,5 @@ public final class DbleServer {
|
||||
return userManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
package com.actiontech.dble.alarm;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.cluster.ClusterController;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -26,7 +27,12 @@ public final class AlertUtil {
|
||||
|
||||
public static void switchAlert(boolean enableAlert) {
|
||||
isEnable = enableAlert;
|
||||
if (enableAlert && UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) != null) {
|
||||
}
|
||||
|
||||
public static void initAlert() {
|
||||
if (DbleServer.getInstance().isUseGeneralCluster() &&
|
||||
(ClusterController.CONFIG_MODE_UCORE.equals(ClusterGeneralConfig.getInstance().getClusterType()) ||
|
||||
ClusterController.CONFIG_MODE_USHARD.equals(ClusterGeneralConfig.getInstance().getClusterType()))) {
|
||||
alert = UcoreAlert.getInstance();
|
||||
} else {
|
||||
alert = DEFAULT_ALERT;
|
||||
@@ -38,19 +44,23 @@ public final class AlertUtil {
|
||||
}
|
||||
|
||||
public static void alertSelf(String code, Alert.AlertLevel level, String desc, Map<String, String> labels) {
|
||||
alert.alertSelf(code, level, desc, labels);
|
||||
if (isEnable) {
|
||||
alert.alertSelf(code, level, desc, labels);
|
||||
}
|
||||
}
|
||||
|
||||
public static void alert(String code, Alert.AlertLevel level, String desc, String alertComponentType, String alertComponentId, Map<String, String> labels) {
|
||||
alert.alert(code, level, desc, alertComponentType, alertComponentId, labels);
|
||||
if (isEnable) {
|
||||
alert.alert(code, level, desc, alertComponentType, alertComponentId, labels);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean alertResolve(String code, Alert.AlertLevel level, String alertComponentType, String alertComponentId, Map<String, String> labels) {
|
||||
return alert.alertResolve(code, level, alertComponentType, alertComponentId, labels);
|
||||
return isEnable ? alert.alertResolve(code, level, alertComponentType, alertComponentId, labels) : true;
|
||||
}
|
||||
|
||||
public static boolean alertSelfResolve(String code, Alert.AlertLevel level, Map<String, String> labels) {
|
||||
return alert.alertSelfResolve(code, level, labels);
|
||||
return isEnable ? alert.alertSelfResolve(code, level, labels) : true;
|
||||
}
|
||||
|
||||
public static Map<String, String> genSingleLabel(String key, String value) {
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
|
||||
package com.actiontech.dble.alarm;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.cluster.bean.ClusterAlertBean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class UcoreAlert implements Alert {
|
||||
private static final String SOURCE_COMPONENT_TYPE = "dble";
|
||||
private static final String SERVER_ID = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID);
|
||||
private static final String SOURCE_COMPONENT_ID = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
|
||||
private static final UcoreAlert INSTANCE = new UcoreAlert();
|
||||
|
||||
@@ -28,50 +27,48 @@ public final class UcoreAlert implements Alert {
|
||||
|
||||
@Override
|
||||
public void alertSelf(String code, AlertLevel level, String desc, Map<String, String> labels) {
|
||||
alert(code, level, desc, SOURCE_COMPONENT_TYPE, SOURCE_COMPONENT_ID, labels);
|
||||
alert(code, level, desc, SOURCE_COMPONENT_TYPE, ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alert(String code, AlertLevel level, String desc, String alertComponentType, String alertComponentId, Map<String, String> labels) {
|
||||
UcoreInterface.AlertInput.Builder builder = UcoreInterface.AlertInput.newBuilder().
|
||||
setCode(code).
|
||||
setDesc(desc).
|
||||
setLevel(level.toString()).
|
||||
setSourceComponentType(SOURCE_COMPONENT_TYPE).
|
||||
setSourceComponentId(SOURCE_COMPONENT_ID).
|
||||
setAlertComponentId(alertComponentId).
|
||||
setAlertComponentType(alertComponentType).
|
||||
setServerId(SERVER_ID).
|
||||
setTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
ClusterAlertBean alert = new ClusterAlertBean();
|
||||
alert.setCode(code);
|
||||
alert.setDesc(desc);
|
||||
alert.setLevel(level.toString());
|
||||
alert.setSourceComponentType(SOURCE_COMPONENT_TYPE);
|
||||
alert.setSourceComponentId(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
alert.setAlertComponentId(alertComponentId);
|
||||
alert.setAlertComponentType(alertComponentType);
|
||||
alert.setServerId(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID));
|
||||
alert.setTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
if (labels != null) {
|
||||
builder.putAllLabels(labels);
|
||||
alert.setLabels(labels);
|
||||
}
|
||||
UcoreInterface.AlertInput input = builder.build();
|
||||
ClusterUcoreSender.alert(input);
|
||||
ClusterHelper.alert(alert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alertResolve(String code, AlertLevel level, String alertComponentType, String alertComponentId, Map<String, String> labels) {
|
||||
UcoreInterface.AlertInput.Builder builder = UcoreInterface.AlertInput.newBuilder().
|
||||
setCode(code).
|
||||
setDesc("").
|
||||
setLevel(level.toString()).
|
||||
setSourceComponentType(SOURCE_COMPONENT_TYPE).
|
||||
setSourceComponentId(SOURCE_COMPONENT_ID).
|
||||
setAlertComponentId(alertComponentId).
|
||||
setAlertComponentType(alertComponentType).
|
||||
setServerId(SERVER_ID).
|
||||
setResolveTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
ClusterAlertBean alert = new ClusterAlertBean();
|
||||
alert.setCode(code);
|
||||
alert.setDesc("");
|
||||
alert.setLevel(level.toString());
|
||||
alert.setSourceComponentType(SOURCE_COMPONENT_TYPE);
|
||||
alert.setSourceComponentId(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
alert.setAlertComponentId(alertComponentId);
|
||||
alert.setAlertComponentType(alertComponentType);
|
||||
alert.setServerId(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID));
|
||||
alert.setResolveTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
if (labels != null) {
|
||||
builder.putAllLabels(labels);
|
||||
alert.setLabels(labels);
|
||||
}
|
||||
UcoreInterface.AlertInput input = builder.build();
|
||||
return ClusterUcoreSender.alertResolve(input);
|
||||
return ClusterHelper.alertResolve(alert);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alertSelfResolve(String code, AlertLevel level, Map<String, String> labels) {
|
||||
return alertResolve(code, level, SOURCE_COMPONENT_TYPE, SOURCE_COMPONENT_ID, labels);
|
||||
return alertResolve(code, level, SOURCE_COMPONENT_TYPE, ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), labels);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,9 @@ package com.actiontech.dble.backend.mysql.view;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.config.model.SchemaConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -51,8 +48,8 @@ public class CKVStoreRepository implements Repository {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
List<UKvBean> allList = ClusterUcoreSender.getKeyTree(UcorePathUtil.getViewPath());
|
||||
for (UKvBean bean : allList) {
|
||||
List<KvBean> allList = ClusterHelper.getKVPath(ClusterPathUtil.getViewPath());
|
||||
for (KvBean bean : allList) {
|
||||
String[] key = bean.getKey().split("/");
|
||||
if (key.length == 5) {
|
||||
String[] value = key[key.length - 1].split(SCHEMA_VIEW_SPLIT);
|
||||
@@ -81,14 +78,14 @@ public class CKVStoreRepository implements Repository {
|
||||
public void put(String schemaName, String viewName, String createSql) {
|
||||
Map<String, String> schemaMap = viewCreateSqlMap.get(schemaName);
|
||||
|
||||
StringBuffer sb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer sb = new StringBuffer().append(ClusterPathUtil.getViewPath()).
|
||||
append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(viewName);
|
||||
StringBuffer lsb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer lsb = new StringBuffer().append(ClusterPathUtil.getViewPath()).
|
||||
append(SEPARATOR).append(LOCK).append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(viewName);
|
||||
StringBuffer nsb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer nsb = new StringBuffer().append(ClusterPathUtil.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);
|
||||
DistributeLock distributeLock = new DistributeLock(lsb.toString(),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + UPDATE);
|
||||
|
||||
|
||||
try {
|
||||
@@ -102,14 +99,14 @@ public class CKVStoreRepository implements Repository {
|
||||
|
||||
ClusterDelayProvider.delayAfterGetLock();
|
||||
schemaMap.put(viewName, createSql);
|
||||
ClusterUcoreSender.sendDataToUcore(sb.toString(), createSql);
|
||||
ClusterHelper.setKV(sb.toString(), createSql);
|
||||
ClusterDelayProvider.delayAfterViewSetKey();
|
||||
ClusterUcoreSender.sendDataToUcore(nsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + UPDATE);
|
||||
ClusterHelper.setKV(nsb.toString(), ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + UPDATE);
|
||||
ClusterDelayProvider.delayAfterViewNotic();
|
||||
//self reponse set
|
||||
ClusterUcoreSender.sendDataToUcore(nsb.toString() + UcorePathUtil.SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(nsb.toString() + ClusterPathUtil.SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ClusterPathUtil.SUCCESS);
|
||||
|
||||
String errorMsg = ClusterUcoreSender.waitingForAllTheNode(UcorePathUtil.SUCCESS, nsb.toString() + SEPARATOR);
|
||||
String errorMsg = ClusterHelper.waitingForAllTheNode(ClusterPathUtil.SUCCESS, nsb.toString() + SEPARATOR);
|
||||
|
||||
if (errorMsg != null) {
|
||||
throw new RuntimeException(errorMsg);
|
||||
@@ -124,7 +121,7 @@ public class CKVStoreRepository implements Repository {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
ClusterDelayProvider.beforeDeleteViewNotic();
|
||||
ClusterUcoreSender.deleteKVTree(nsb.toString() + SEPARATOR);
|
||||
ClusterHelper.cleanPath(nsb.toString() + SEPARATOR);
|
||||
ClusterDelayProvider.beforeReleaseViewLock();
|
||||
distributeLock.release();
|
||||
}
|
||||
@@ -142,15 +139,15 @@ public class CKVStoreRepository implements Repository {
|
||||
*/
|
||||
@Override
|
||||
public void delete(String schemaName, String view) {
|
||||
StringBuffer sb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer sb = new StringBuffer().append(ClusterPathUtil.getViewPath()).
|
||||
append(SEPARATOR).append(schemaName).append(SCHEMA_VIEW_SPLIT).append(view);
|
||||
StringBuffer nsb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer nsb = new StringBuffer().append(ClusterPathUtil.getViewPath()).
|
||||
append(SEPARATOR).append(UPDATE).append(SEPARATOR).
|
||||
append(schemaName).append(SCHEMA_VIEW_SPLIT).append(view);
|
||||
StringBuffer lsb = new StringBuffer().append(UcorePathUtil.getViewPath()).
|
||||
StringBuffer lsb = new StringBuffer().append(ClusterPathUtil.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);
|
||||
DistributeLock distributeLock = new DistributeLock(lsb.toString(),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + DELETE);
|
||||
|
||||
try {
|
||||
viewCreateSqlMap.get(schemaName).remove(view);
|
||||
@@ -162,15 +159,15 @@ public class CKVStoreRepository implements Repository {
|
||||
}
|
||||
}
|
||||
ClusterDelayProvider.delayAfterGetLock();
|
||||
ClusterUcoreSender.deleteKV(sb.toString());
|
||||
ClusterHelper.cleanKV(sb.toString());
|
||||
ClusterDelayProvider.delayAfterViewSetKey();
|
||||
ClusterUcoreSender.sendDataToUcore(nsb.toString(), UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + DELETE);
|
||||
ClusterHelper.setKV(nsb.toString(), ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID) + SCHEMA_VIEW_SPLIT + DELETE);
|
||||
ClusterDelayProvider.delayAfterViewNotic();
|
||||
|
||||
//self reponse set
|
||||
ClusterUcoreSender.sendDataToUcore(nsb.toString() + UcorePathUtil.SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(nsb.toString() + ClusterPathUtil.SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ClusterPathUtil.SUCCESS);
|
||||
|
||||
String errorMsg = ClusterUcoreSender.waitingForAllTheNode(UcorePathUtil.SUCCESS, nsb.toString() + SEPARATOR);
|
||||
String errorMsg = ClusterHelper.waitingForAllTheNode(ClusterPathUtil.SUCCESS, nsb.toString() + SEPARATOR);
|
||||
|
||||
if (errorMsg != null) {
|
||||
throw new RuntimeException(errorMsg);
|
||||
@@ -184,7 +181,7 @@ public class CKVStoreRepository implements Repository {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
ClusterDelayProvider.beforeDeleteViewNotic();
|
||||
ClusterUcoreSender.deleteKVTree(nsb.toString() + SEPARATOR);
|
||||
ClusterHelper.cleanPath(nsb.toString() + SEPARATOR);
|
||||
ClusterDelayProvider.beforeReleaseViewLock();
|
||||
distributeLock.release();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.kVtoXml.ClusterToXml;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/11.
|
||||
*/
|
||||
public abstract class AbstractClusterSender implements ClusterSender {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(AbstractClusterSender.class);
|
||||
|
||||
|
||||
public String waitingForAllTheNode(String checkString, String path) {
|
||||
Map<String, String> expectedMap = ClusterToXml.getOnlineMap();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
for (; ; ) {
|
||||
errorMsg.setLength(0);
|
||||
if (checkResponseForOneTime(checkString, path, expectedMap, errorMsg)) {
|
||||
break;
|
||||
}
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(50));
|
||||
}
|
||||
return errorMsg.length() <= 0 ? null : errorMsg.toString();
|
||||
}
|
||||
|
||||
public boolean checkResponseForOneTime(String checkString, String path, Map<String, String> expectedMap, StringBuffer errorMsg) {
|
||||
Map<String, String> currentMap = ClusterToXml.getOnlineMap();
|
||||
checkOnline(expectedMap, currentMap);
|
||||
List<KvBean> responseList = ClusterHelper.getKVPath(path);
|
||||
boolean flag = false;
|
||||
for (Map.Entry<String, String> entry : expectedMap.entrySet()) {
|
||||
flag = false;
|
||||
for (KvBean kvBean : responseList) {
|
||||
String responseNode = last(kvBean.getKey().split("/"));
|
||||
if (last(entry.getKey().split("/")).
|
||||
equals(responseNode)) {
|
||||
if (checkString != null) {
|
||||
if (!checkString.equals(kvBean.getValue())) {
|
||||
if (errorMsg != null) {
|
||||
errorMsg.append(responseNode).append(":").append(kvBean.getValue()).append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
public void checkOnline(Map<String, String> expectedMap, Map<String, String> currentMap) {
|
||||
Iterator<Map.Entry<String, String>> iterator = expectedMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (!currentMap.containsKey(entry.getKey()) ||
|
||||
(currentMap.containsKey(entry.getKey()) && !currentMap.get(entry.getKey()).equals(entry.getValue()))) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : currentMap.entrySet()) {
|
||||
if (!expectedMap.containsKey(entry.getKey())) {
|
||||
LOGGER.warn("NODE " + entry.getKey() + " IS NOT EXPECTED TO BE ONLINE,PLEASE CHECK IT ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T last(T[] array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.util.ResourceUtil;
|
||||
import com.google.common.base.Strings;
|
||||
@@ -24,9 +23,11 @@ public final class ClusterController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterController.class);
|
||||
|
||||
public static final String CONFIG_FILE_NAME = "/myid.properties";
|
||||
private static final String CONFIG_MODE_UCORE = "ucore";
|
||||
private static final String CONFIG_MODE_ZK = "zk";
|
||||
private static final String CONFIG_MODE_SINGLE = "false";
|
||||
public static final String CONFIG_MODE_UCORE = "ucore";
|
||||
public static final String CONFIG_MODE_USHARD = "ushard";
|
||||
public static final String CONFIG_MODE_ZK = "zk";
|
||||
public static final String CONFIG_MODE_SINGLE = "false";
|
||||
public static final String CONFIG_MODE_CUSTOMIZATION = "customization";
|
||||
|
||||
public static final int GRPC_SUBTIMEOUT = 70;
|
||||
public static final int GENERAL_GRPC_TIMEOUT = 10;
|
||||
@@ -37,29 +38,23 @@ public final class ClusterController {
|
||||
private ClusterController() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
public static ClusterGeneralConfig init() {
|
||||
//read from myid.properties to tall use zk or ucore
|
||||
try {
|
||||
properties = loadMyidPropersites();
|
||||
if (CONFIG_MODE_UCORE.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
checkUcoreProperties();
|
||||
UcoreConfig.initUcore(properties);
|
||||
} else if (CONFIG_MODE_ZK.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
ZkConfig.initZk(properties);
|
||||
} else {
|
||||
LOGGER.info("No Cluster Config .......start in single mode");
|
||||
}
|
||||
ClusterGeneralConfig clusterGeneralConfig = ClusterGeneralConfig.initConfig(properties);
|
||||
ClusterGeneralConfig.initData(properties);
|
||||
return clusterGeneralConfig;
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("error:", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void initFromShellUcore() {
|
||||
properties = loadMyidPropersites();
|
||||
checkClusterMode(CONFIG_MODE_UCORE);
|
||||
checkUcoreProperties();
|
||||
UcoreConfig.initUcoreFromShell(properties);
|
||||
ClusterGeneralConfig.initConfig(properties);
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().checkClusterConfig(properties);
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().initConInfo(properties);
|
||||
}
|
||||
|
||||
public static void initFromShellZK() {
|
||||
@@ -98,11 +93,5 @@ public final class ClusterController {
|
||||
throw new RuntimeException("Cluster mode is not " + clusterMode);
|
||||
}
|
||||
}
|
||||
private static void checkUcoreProperties() {
|
||||
if (Strings.isNullOrEmpty(properties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_PORT.getKey())) ||
|
||||
Strings.isNullOrEmpty(properties.getProperty(ClusterParamCfg.CLUSTER_CFG_SERVER_ID.getKey()))) {
|
||||
throw new RuntimeException("Cluster Config is not completely set");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.cluster.impl.UcoreSender;
|
||||
import com.actiontech.dble.cluster.impl.ushard.UshardSender;
|
||||
import com.actiontech.dble.cluster.kVtoXml.ClusterToXml;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.actiontech.dble.backend.mysql.nio.handler.ResetConnHandler.LOGGER;
|
||||
import static com.actiontech.dble.cluster.ClusterController.*;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/11.
|
||||
*/
|
||||
public final class ClusterGeneralConfig {
|
||||
|
||||
private static final ClusterGeneralConfig INSTANCE = new ClusterGeneralConfig();
|
||||
private boolean useCluster = false;
|
||||
private AbstractClusterSender clusterSender = null;
|
||||
private Properties properties = null;
|
||||
private String clusterType = null;
|
||||
|
||||
private ClusterGeneralConfig() {
|
||||
|
||||
}
|
||||
|
||||
public static ClusterGeneralConfig initConfig(Properties properties) {
|
||||
INSTANCE.properties = properties;
|
||||
|
||||
if (CONFIG_MODE_USHARD.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
INSTANCE.clusterSender = new UshardSender();
|
||||
INSTANCE.useCluster = true;
|
||||
INSTANCE.clusterType = CONFIG_MODE_USHARD;
|
||||
} else if (CONFIG_MODE_UCORE.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
INSTANCE.clusterSender = new UcoreSender();
|
||||
INSTANCE.useCluster = true;
|
||||
INSTANCE.clusterType = CONFIG_MODE_UCORE;
|
||||
} else if (CONFIG_MODE_ZK.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
INSTANCE.useCluster = true;
|
||||
INSTANCE.clusterType = CONFIG_MODE_ZK;
|
||||
} else if (CONFIG_MODE_SINGLE.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
LOGGER.info("No Cluster Config .......start in single mode");
|
||||
} else {
|
||||
try {
|
||||
String clazz = properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey());
|
||||
INSTANCE.useCluster = true;
|
||||
INSTANCE.clusterType = CONFIG_MODE_CUSTOMIZATION;
|
||||
Class<?> clz = Class.forName(clazz);
|
||||
//all function must be extend from AbstractPartitionAlgorithm
|
||||
if (!AbstractClusterSender.class.isAssignableFrom(clz)) {
|
||||
throw new IllegalArgumentException("No ClusterSender AS " + clazz);
|
||||
}
|
||||
INSTANCE.clusterSender = (AbstractClusterSender) clz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Get error when try to create " + properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()));
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public static void initData(Properties properties) {
|
||||
if (CONFIG_MODE_ZK.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
ZkConfig.initZk(properties);
|
||||
} else if (CONFIG_MODE_SINGLE.equalsIgnoreCase(properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()))) {
|
||||
LOGGER.info("No Cluster Config .......start in single mode");
|
||||
} else {
|
||||
try {
|
||||
INSTANCE.clusterSender.checkClusterConfig(properties);
|
||||
INSTANCE.clusterSender.initCluster(properties);
|
||||
ClusterToXml.loadKVtoFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Get error when try to create " + properties.getProperty(ClusterParamCfg.CLUSTER_FLAG.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public AbstractClusterSender getClusterSender() {
|
||||
return clusterSender;
|
||||
}
|
||||
|
||||
public void setClusterSender(AbstractClusterSender clusterSender) {
|
||||
this.clusterSender = clusterSender;
|
||||
}
|
||||
|
||||
public boolean isUseCluster() {
|
||||
return useCluster;
|
||||
}
|
||||
|
||||
public String getClusterType() {
|
||||
return clusterType;
|
||||
}
|
||||
|
||||
public static ClusterGeneralConfig getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public String getValue(ClusterParamCfg param) {
|
||||
if (properties != null && null != param) {
|
||||
return properties.getProperty(param.getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
69
src/main/java/com/actiontech/dble/cluster/ClusterHelper.java
Normal file
69
src/main/java/com/actiontech/dble/cluster/ClusterHelper.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.cluster.bean.ClusterAlertBean;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/11.
|
||||
*/
|
||||
public final class ClusterHelper {
|
||||
|
||||
private ClusterHelper() {
|
||||
|
||||
}
|
||||
|
||||
public static String lock(String path, String value) throws Exception {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().lock(path, value);
|
||||
}
|
||||
|
||||
public static void unlockKey(String path, String sessionId) {
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().unlockKey(path, sessionId);
|
||||
}
|
||||
|
||||
public static void setKV(String path, String value) throws Exception {
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().setKV(path, value);
|
||||
}
|
||||
|
||||
public static KvBean getKV(String path) {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().getKV(path);
|
||||
}
|
||||
|
||||
public static void cleanKV(String path) {
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().cleanKV(path);
|
||||
}
|
||||
|
||||
public static List<KvBean> getKVPath(String path) {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().getKVPath(path);
|
||||
}
|
||||
|
||||
public static void cleanPath(String path) {
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().cleanPath(path);
|
||||
}
|
||||
|
||||
public static boolean checkResponseForOneTime(String checkString, String path, Map<String, String> expectedMap, StringBuffer errorMsg) {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().checkResponseForOneTime(checkString, path, expectedMap, errorMsg);
|
||||
}
|
||||
|
||||
public static String waitingForAllTheNode(String checkString, String path) {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().waitingForAllTheNode(checkString, path);
|
||||
}
|
||||
|
||||
public static void alert(ClusterAlertBean alert) {
|
||||
ClusterGeneralConfig.getInstance().getClusterSender().alert(alert);
|
||||
}
|
||||
|
||||
public static boolean alertResolve(ClusterAlertBean alert) {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().alertResolve(alert);
|
||||
}
|
||||
|
||||
public static SubscribeReturnBean subscribeKvPrefix(SubscribeRequest request) throws Exception {
|
||||
return ClusterGeneralConfig.getInstance().getClusterSender().subscribeKvPrefix(request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -29,6 +29,12 @@ public enum ClusterParamCfg {
|
||||
*/
|
||||
CLUSTER_CFG_CLUSTERID("clusterId"),
|
||||
|
||||
|
||||
/**
|
||||
* node id
|
||||
*/
|
||||
CLUSTER_CFG_ROOT("rootPath"),
|
||||
|
||||
/**
|
||||
* node id
|
||||
*/
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.Versions;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public final class UcorePathUtil {
|
||||
public final class ClusterPathUtil {
|
||||
|
||||
public static final String UCORE_LOCAL_WRITE_PATH = "./";
|
||||
|
||||
@@ -19,9 +18,9 @@ public final class UcorePathUtil {
|
||||
public static final String DATA_HOST = "dataHost";
|
||||
public static final String DATA_NODE = "dataNode";
|
||||
public static final String SEPARATOR = "/";
|
||||
private static final String ROOT_PATH = "universe" + SEPARATOR + Versions.ROOT_PREFIX;
|
||||
private static final String ROOT_PATH = ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_ROOT) != null ? ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_ROOT) : "universe" + SEPARATOR + Versions.ROOT_PREFIX;
|
||||
|
||||
public static final String BASE_PATH = ROOT_PATH + SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_CLUSTERID) + SEPARATOR;
|
||||
public static final String BASE_PATH = ROOT_PATH + SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_CLUSTERID) + SEPARATOR;
|
||||
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
@@ -67,7 +66,7 @@ public final class UcorePathUtil {
|
||||
public static final String EHCACHE_NAME = "ehcache.xml";
|
||||
public static final String EHCACHE = "ehcache";
|
||||
|
||||
private UcorePathUtil() {
|
||||
private ClusterPathUtil() {
|
||||
|
||||
}
|
||||
|
||||
@@ -104,7 +103,7 @@ public final class UcorePathUtil {
|
||||
}
|
||||
|
||||
public static String getSelfConfStatusPath() {
|
||||
return CONF_BASE_PATH + CONF_STATUS + SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
return CONF_BASE_PATH + CONF_STATUS + SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
}
|
||||
|
||||
//depth:2,child node of base_path
|
||||
@@ -129,7 +128,7 @@ public final class UcorePathUtil {
|
||||
}
|
||||
|
||||
public static String getBinlogPauseStatusSelf() {
|
||||
return getBinlogPauseStatus() + SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
return getBinlogPauseStatus() + SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
}
|
||||
|
||||
//depth:2,child node of base_path
|
||||
@@ -165,7 +164,7 @@ public final class UcorePathUtil {
|
||||
|
||||
//depth:2,child node of base_path
|
||||
public static String getDDLInstancePath(String fullName) {
|
||||
return BASE_PATH + "ddl" + SEPARATOR + fullName + SEPARATOR + UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
return BASE_PATH + "ddl" + SEPARATOR + fullName + SEPARATOR + ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
}
|
||||
|
||||
public static String getViewPath() {
|
||||
124
src/main/java/com/actiontech/dble/cluster/ClusterSender.java
Normal file
124
src/main/java/com/actiontech/dble/cluster/ClusterSender.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.ClusterAlertBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/11.
|
||||
*/
|
||||
public interface ClusterSender {
|
||||
|
||||
/**
|
||||
* only init the connection preperties for the clusterSender
|
||||
* mainly used by shell to upload xml config
|
||||
* do not start any Thread in this function!
|
||||
*
|
||||
* @param ucoreProperties
|
||||
*/
|
||||
void initConInfo(Properties ucoreProperties);
|
||||
|
||||
/**
|
||||
* general config init of clusterSender
|
||||
* There are several task may be start
|
||||
* 1 init the config
|
||||
* 2 start customized connection controller
|
||||
*
|
||||
* @param properties
|
||||
*/
|
||||
void initCluster(Properties properties);
|
||||
|
||||
/**
|
||||
* lock a path,so that other DbleServer in cluster can not hold the path in the same time
|
||||
* return sessionId of the lock,if the return String is not null or "" means lock success
|
||||
* the lock value is also import ,the lock also need to be regarded as a KV
|
||||
* <p>
|
||||
* NOTICE: the lock should only influences it self,the child path should be available to other DbleServer to write
|
||||
*
|
||||
* @param path
|
||||
* @param value
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
String lock(String path, String value) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* use the locked path and sessionId to unlock a path
|
||||
* and the KV of the lock should be removed
|
||||
*
|
||||
* @param key
|
||||
* @param sessionId
|
||||
*/
|
||||
void unlockKey(String key, String sessionId);
|
||||
|
||||
/**
|
||||
* put KV into cluster
|
||||
*
|
||||
* @param path
|
||||
* @param value
|
||||
* @throws Exception
|
||||
*/
|
||||
void setKV(String path, String value) throws Exception;
|
||||
|
||||
/**
|
||||
* get KV from cluster
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
KvBean getKV(String path);
|
||||
|
||||
/**
|
||||
* return all the KV under the path
|
||||
* <p>
|
||||
* NOTICE: the KV in result list should be full path
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
List<KvBean> getKVPath(String path);
|
||||
|
||||
/**
|
||||
* clean/delete all the KV under the path
|
||||
* NOTICE: path itself also need cleaned
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
void cleanPath(String path);
|
||||
|
||||
/**
|
||||
* clean/delete single KV
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
void cleanKV(String path);
|
||||
|
||||
SubscribeReturnBean subscribeKvPrefix(SubscribeRequest request) throws Exception;
|
||||
|
||||
/**
|
||||
* alert something into cluster
|
||||
*
|
||||
* @param alert
|
||||
*/
|
||||
void alert(ClusterAlertBean alert);
|
||||
|
||||
/**
|
||||
* notify cluster some alert is resolved
|
||||
*
|
||||
* @param alert
|
||||
* @return
|
||||
*/
|
||||
boolean alertResolve(ClusterAlertBean alert);
|
||||
|
||||
/**
|
||||
* check if the cluster config is complete,if not throw a RunTimeException
|
||||
*
|
||||
* @param properties
|
||||
*/
|
||||
void checkClusterConfig(Properties properties);
|
||||
}
|
||||
@@ -3,30 +3,30 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/3/6.
|
||||
* this class is save the UDistributeLock when ddl executed
|
||||
* this class is save the DistributeLock when ddl executed
|
||||
*/
|
||||
public final class UDistrbtLockManager {
|
||||
public final class DistrbtLockManager {
|
||||
|
||||
private final Map<String, UDistributeLock> lockTables;
|
||||
private static final UDistrbtLockManager INSTANCE = new UDistrbtLockManager();
|
||||
private final Map<String, DistributeLock> lockTables;
|
||||
private static final DistrbtLockManager INSTANCE = new DistrbtLockManager();
|
||||
|
||||
private UDistrbtLockManager() {
|
||||
private DistrbtLockManager() {
|
||||
this.lockTables = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void addLock(UDistributeLock lock) {
|
||||
public static void addLock(DistributeLock lock) {
|
||||
INSTANCE.lockTables.put(lock.getPath(), lock);
|
||||
}
|
||||
|
||||
public static void releaseLock(String path) {
|
||||
UDistributeLock removedLock = INSTANCE.lockTables.remove(path);
|
||||
DistributeLock removedLock = INSTANCE.lockTables.remove(path);
|
||||
if (removedLock != null) {
|
||||
removedLock.release();
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.cluster;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/31.
|
||||
*/
|
||||
public class DistributeLock {
|
||||
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(DistributeLock.class);
|
||||
private final int maxErrorCnt;
|
||||
private int errorCount = 0;
|
||||
private String path;
|
||||
private String value;
|
||||
private String session;
|
||||
|
||||
//private Thread renewThread;
|
||||
|
||||
public DistributeLock(String path, String value) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.maxErrorCnt = 3;
|
||||
}
|
||||
|
||||
public DistributeLock(String path, String value, int maxErrorCnt) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.maxErrorCnt = maxErrorCnt;
|
||||
}
|
||||
|
||||
|
||||
public void release() {
|
||||
if (session != null) {
|
||||
ClusterHelper.unlockKey(path, session);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean acquire() {
|
||||
try {
|
||||
String sessionId = ClusterHelper.lock(this.path, value);
|
||||
if ("".equals(sessionId)) {
|
||||
errorCount++;
|
||||
if (errorCount == maxErrorCnt) {
|
||||
throw new RuntimeException(" get lock from ucore error,ucore maybe offline ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
session = sessionId;
|
||||
errorCount = 0;
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(" get lock from ucore error", e);
|
||||
errorCount++;
|
||||
if (errorCount == maxErrorCnt) {
|
||||
throw new RuntimeException(" get lock from ucore error,ucore maybe offline ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.actiontech.dble.cluster.bean;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/11.
|
||||
*/
|
||||
public class ClusterAlertBean {
|
||||
String code;
|
||||
String level;
|
||||
String desc;
|
||||
String sourceComponentType;
|
||||
String sourceComponentId;
|
||||
String alertComponentType;
|
||||
String alertComponentId;
|
||||
String serverId;
|
||||
long timestampUnix;
|
||||
long resolveTimestampUnix;
|
||||
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
Map<String, String> labels;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getSourceComponentType() {
|
||||
return sourceComponentType;
|
||||
}
|
||||
|
||||
public void setSourceComponentType(String sourceComponentType) {
|
||||
this.sourceComponentType = sourceComponentType;
|
||||
}
|
||||
|
||||
public String getSourceComponentId() {
|
||||
return sourceComponentId;
|
||||
}
|
||||
|
||||
public void setSourceComponentId(String sourceComponentId) {
|
||||
this.sourceComponentId = sourceComponentId;
|
||||
}
|
||||
|
||||
public String getAlertComponentType() {
|
||||
return alertComponentType;
|
||||
}
|
||||
|
||||
public void setAlertComponentType(String alertComponentType) {
|
||||
this.alertComponentType = alertComponentType;
|
||||
}
|
||||
|
||||
public String getAlertComponentId() {
|
||||
return alertComponentId;
|
||||
}
|
||||
|
||||
public void setAlertComponentId(String alertComponentId) {
|
||||
this.alertComponentId = alertComponentId;
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public void setServerId(String serverId) {
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public long getTimestampUnix() {
|
||||
return timestampUnix;
|
||||
}
|
||||
|
||||
public void setTimestampUnix(long timestampUnix) {
|
||||
this.timestampUnix = timestampUnix;
|
||||
}
|
||||
|
||||
public long getResolveTimestampUnix() {
|
||||
return resolveTimestampUnix;
|
||||
}
|
||||
|
||||
public void setResolveTimestampUnix(long resolveTimestampUnix) {
|
||||
this.resolveTimestampUnix = resolveTimestampUnix;
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.bean;
|
||||
package com.actiontech.dble.cluster.bean;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/31.
|
||||
*/
|
||||
public class UKvBean {
|
||||
public class KvBean {
|
||||
|
||||
public static final String DELETE = "delete";
|
||||
public static final String UPDATE = "update";
|
||||
@@ -20,17 +20,17 @@ public class UKvBean {
|
||||
private String changeType;
|
||||
private long index;
|
||||
|
||||
public UKvBean() {
|
||||
public KvBean() {
|
||||
}
|
||||
|
||||
public UKvBean(String key, String value, long index) {
|
||||
public KvBean(String key, String value, long index) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
|
||||
public UKvBean(String key, String value, String changeType) {
|
||||
public KvBean(String key, String value, String changeType) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.changeType = changeType;
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.actiontech.dble.cluster.bean;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/12.
|
||||
*/
|
||||
public class SubscribeRequest {
|
||||
private long index;
|
||||
private int duration;
|
||||
private String path;
|
||||
|
||||
|
||||
public long getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(long index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.actiontech.dble.cluster.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/12.
|
||||
*/
|
||||
public class SubscribeReturnBean {
|
||||
|
||||
|
||||
private List<KvBean> kvList = new ArrayList<>();
|
||||
|
||||
private long index = 0;
|
||||
|
||||
public int getKeysCount() {
|
||||
return kvList.size();
|
||||
}
|
||||
|
||||
public String getKeys(int i) {
|
||||
return kvList.get(i).getKey();
|
||||
}
|
||||
|
||||
public String getValues(int i) {
|
||||
return kvList.get(i).getValue();
|
||||
}
|
||||
|
||||
public List<KvBean> getKvList() {
|
||||
return kvList;
|
||||
}
|
||||
|
||||
public void setKvList(List<KvBean> kvList) {
|
||||
this.kvList = kvList;
|
||||
}
|
||||
|
||||
public long getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(long index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
}
|
||||
561
src/main/java/com/actiontech/dble/cluster/impl/UcoreSender.java
Normal file
561
src/main/java/com/actiontech/dble/cluster/impl/UcoreSender.java
Normal file
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.cluster.impl;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.alarm.UcoreGrpc;
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.backend.mysql.view.CKVStoreRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.FileSystemRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.Repository;
|
||||
import com.actiontech.dble.cluster.AbstractClusterSender;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.ClusterAlertBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
import com.actiontech.dble.server.status.OnlineLockStatus;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.google.common.base.Strings;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static com.actiontech.dble.cluster.ClusterController.CONFIG_FILE_NAME;
|
||||
import static com.actiontech.dble.cluster.ClusterController.GENERAL_GRPC_TIMEOUT;
|
||||
import static com.actiontech.dble.cluster.ClusterController.GRPC_SUBTIMEOUT;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public final class UcoreSender extends AbstractClusterSender {
|
||||
|
||||
|
||||
private volatile UcoreGrpc.UcoreBlockingStub stub = null;
|
||||
private ConcurrentHashMap<String, Thread> lockMap = new ConcurrentHashMap<>();
|
||||
private Properties properties;
|
||||
private List<String> ipList = new ArrayList<>();
|
||||
private static final String SOURCE_COMPONENT_TYPE = "dble";
|
||||
private String serverId = null;
|
||||
private String sourceComponentId = null;
|
||||
|
||||
|
||||
@Override
|
||||
public void initConInfo(Properties ucoreProperties) {
|
||||
this.properties = ucoreProperties;
|
||||
serverId = getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID);
|
||||
sourceComponentId = getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
try {
|
||||
for (String ip : properties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey()).split(",")) {
|
||||
ipList.add(ip);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("error:", e);
|
||||
}
|
||||
Channel channel = ManagedChannelBuilder.forAddress(getIpList().get(0),
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCluster(Properties ucoreProperties) {
|
||||
this.properties = ucoreProperties;
|
||||
serverId = getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID);
|
||||
sourceComponentId = getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
try {
|
||||
for (String ip : properties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey()).split(",")) {
|
||||
ipList.add(ip);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("error:", e);
|
||||
}
|
||||
Channel channel = ManagedChannelBuilder.forAddress(getIpList().get(0),
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
startUpdateNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lock(String path, String value) throws Exception {
|
||||
UcoreInterface.LockOnSessionInput input = UcoreInterface.LockOnSessionInput.newBuilder().setKey(path).setValue(value).setTTLSeconds(30).build();
|
||||
UcoreInterface.LockOnSessionOutput output;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).lockOnSession(input);
|
||||
if (!"".equals(output.getSessionId())) {
|
||||
final String session = output.getSessionId();
|
||||
Thread renewThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String sessionId = session;
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
LOGGER.debug("renew lock of session start:" + sessionId + " " + path);
|
||||
if ("".equals(ClusterHelper.getKV(path).getValue())) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ");
|
||||
// alert
|
||||
Thread.currentThread().interrupt();
|
||||
} else if (!renewLock(sessionId)) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path);
|
||||
// alert
|
||||
} else {
|
||||
LOGGER.debug("renew lock of session success:" + sessionId + " " + path);
|
||||
}
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10000));
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path, e);
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(5000));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lockMap.put(path, renewThread);
|
||||
renewThread.setName("UCORE_RENEW_" + path);
|
||||
renewThread.start();
|
||||
}
|
||||
return output.getSessionId();
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).lockOnSession(input);
|
||||
return output.getSessionId();
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockKey(String path, String sessionId) {
|
||||
UcoreInterface.UnlockOnSessionInput put = UcoreInterface.UnlockOnSessionInput.newBuilder().setKey(path).setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
|
||||
Thread renewThread = lockMap.get(path);
|
||||
if (renewThread != null) {
|
||||
renewThread.interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.info(sessionId + " unlockKey " + path + " error ," + stub, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKV(String path, String value) throws Exception {
|
||||
UcoreInterface.PutKvInput input = UcoreInterface.PutKvInput.newBuilder().setKey(path).setValue(value).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).putKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).putKv(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KvBean getKV(String path) {
|
||||
UcoreInterface.GetKvInput input = UcoreInterface.GetKvInput.newBuilder().setKey(path).build();
|
||||
UcoreInterface.GetKvOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKv(input);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
KvBean bean = new KvBean(path, output.getValue(), 0);
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KvBean> getKVPath(String path) {
|
||||
if (!(path.charAt(path.length() - 1) == '/')) {
|
||||
path = path + "/";
|
||||
}
|
||||
List<KvBean> result = new ArrayList<KvBean>();
|
||||
UcoreInterface.GetKvTreeInput input = UcoreInterface.GetKvTreeInput.newBuilder().setKey(path).build();
|
||||
|
||||
UcoreInterface.GetKvTreeOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
KvBean bean = new KvBean(output.getKeys(i), output.getValues(i), output.getIndex());
|
||||
result.add(bean);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPath(String path) {
|
||||
if (!(path.charAt(path.length() - 1) == '/')) {
|
||||
path = path + "/";
|
||||
}
|
||||
UcoreInterface.DeleteKvTreeInput input = UcoreInterface.DeleteKvTreeInput.newBuilder().setKey(path).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
boolean flag = false;
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKvTree(input);
|
||||
flag = true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
cleanKV(path.substring(0, path.length() - 1));
|
||||
}
|
||||
|
||||
public void cleanKV(String path) {
|
||||
UcoreInterface.DeleteKvInput input = UcoreInterface.DeleteKvInput.newBuilder().setKey(path).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKv(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribeReturnBean subscribeKvPrefix(SubscribeRequest request) throws Exception {
|
||||
|
||||
UcoreInterface.SubscribeKvPrefixInput input = UcoreInterface.SubscribeKvPrefixInput.newBuilder().
|
||||
setIndex(request.getIndex()).setDuration(request.getDuration()).setKeyPrefix(request.getPath()).build();
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeKvPrefix(input);
|
||||
return groupSubscribeResult(output);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS);
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeKvPrefix(input);
|
||||
return groupSubscribeResult(output);
|
||||
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore at " + ip + " failure", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alert(ClusterAlertBean alert) {
|
||||
UcoreInterface.AlertInput input = getInput(alert);
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alert(input);
|
||||
} catch (Exception e) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip, Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alert(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("alert to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alertResolve(ClusterAlertBean alert) {
|
||||
UcoreInterface.AlertInput input = getInput(alert);
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alertResolve(input);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip, Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alertResolve(input);
|
||||
return true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("alertResolve to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClusterConfig(Properties ucoreProperties) {
|
||||
if (Strings.isNullOrEmpty(ucoreProperties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_PORT.getKey())) ||
|
||||
Strings.isNullOrEmpty(ucoreProperties.getProperty(ClusterParamCfg.CLUSTER_CFG_SERVER_ID.getKey()))) {
|
||||
throw new RuntimeException("Cluster Config is not completely set");
|
||||
}
|
||||
}
|
||||
|
||||
private UcoreInterface.AlertInput getInput(ClusterAlertBean alert) {
|
||||
UcoreInterface.AlertInput.Builder builder = UcoreInterface.AlertInput.newBuilder().
|
||||
setCode(alert.getCode()).
|
||||
setDesc(alert.getDesc()).
|
||||
setLevel(alert.getLevel().toString()).
|
||||
setSourceComponentType(SOURCE_COMPONENT_TYPE).
|
||||
setSourceComponentId(sourceComponentId).
|
||||
setAlertComponentId(alert.getAlertComponentId()).
|
||||
setAlertComponentType(alert.getAlertComponentType()).
|
||||
setServerId(serverId).
|
||||
setTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
if (alert.getLabels() != null) {
|
||||
builder.putAllLabels(alert.getLabels());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
public boolean renewLock(String sessionId) throws Exception {
|
||||
UcoreInterface.RenewSessionInput input = UcoreInterface.RenewSessionInput.newBuilder().setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).renewSession(input);
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
LOGGER.info("connect to ucore renew error and will retry");
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).renewSession(input);
|
||||
return true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore renew error " + stub, e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SubscribeReturnBean groupSubscribeResult(UcoreInterface.SubscribeKvPrefixOutput output) {
|
||||
SubscribeReturnBean result = new SubscribeReturnBean();
|
||||
result.setIndex(output.getIndex());
|
||||
if (output.getKeysCount() > 0) {
|
||||
List<KvBean> kvList = new ArrayList<>();
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
kvList.add(new KvBean(output.getKeys(i), output.getValues(i), 0));
|
||||
}
|
||||
result.setKvList(kvList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public UcoreInterface.SubscribeNodesOutput subscribeNodes(UcoreInterface.SubscribeNodesInput subscribeNodesInput) throws IOException {
|
||||
try {
|
||||
return stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeNodes(subscribeNodesInput);
|
||||
} catch (Exception e) {
|
||||
//the first try failure ,try for all the other ucore ip
|
||||
for (String ip : getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS);
|
||||
return stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeNodes(subscribeNodesInput);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("try connection IP " + ip + " failure ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
|
||||
public void setIp(String ips) {
|
||||
properties.setProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey(), ips);
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
File file = new File(DbleServer.class.getResource(CONFIG_FILE_NAME).getFile());
|
||||
out = new FileOutputStream(file);
|
||||
properties.store(out, "");
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("ips set to ucore failure");
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("open file error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startUpdateNodes() {
|
||||
Thread nodes = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long index = 0;
|
||||
for (; ; ) {
|
||||
try {
|
||||
UcoreInterface.SubscribeNodesInput subscribeNodesInput = UcoreInterface.SubscribeNodesInput.newBuilder().
|
||||
setDuration(60).setIndex(index).build();
|
||||
UcoreInterface.SubscribeNodesOutput output = subscribeNodes(subscribeNodesInput);
|
||||
if (index != output.getIndex()) {
|
||||
index = output.getIndex();
|
||||
List<String> ips = new ArrayList<>();
|
||||
for (int i = 0; i < output.getIpsList().size(); i++) {
|
||||
ips.add(output.getIps(i));
|
||||
}
|
||||
setIpList(ips);
|
||||
setIp(StringUtils.join(ips, ','));
|
||||
}
|
||||
|
||||
if (DbleServer.getInstance().getTmManager() != null) {
|
||||
if (DbleServer.getInstance().getTmManager().getRepository() instanceof FileSystemRepository) {
|
||||
LOGGER.warn("Dble first reconnect to ucore ,local view repository change to CKVStoreRepository");
|
||||
Repository newViewRepository = new CKVStoreRepository();
|
||||
DbleServer.getInstance().getTmManager().setRepository(newViewRepository);
|
||||
Map<String, Map<String, String>> viewCreateSqlMap = newViewRepository.getViewCreateSqlMap();
|
||||
DbleServer.getInstance().getTmManager().reloadViewMeta(viewCreateSqlMap);
|
||||
//init online status
|
||||
LOGGER.warn("Dble first reconnect to ucore ,online status rebuild");
|
||||
OnlineLockStatus.getInstance().metaUcoreInit(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("error in ucore nodes watch,try for another time", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
nodes.setName("NODES_UCORE_LISTENER");
|
||||
nodes.start();
|
||||
}
|
||||
|
||||
private void setIpList(List<String> ipList) {
|
||||
this.ipList = ipList;
|
||||
}
|
||||
|
||||
private List<String> getIpList() {
|
||||
return ipList;
|
||||
}
|
||||
|
||||
|
||||
public String getValue(ClusterParamCfg param) {
|
||||
if (properties != null && null != param) {
|
||||
return properties.getProperty(param.getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,783 @@
|
||||
package com.actiontech.dble.cluster.impl.ushard;
|
||||
|
||||
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
|
||||
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.futureUnaryCall;
|
||||
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
|
||||
|
||||
/**
|
||||
*/
|
||||
@javax.annotation.Generated(
|
||||
value = "by gRPC proto compiler (version 1.4.0)",
|
||||
comments = "Source: dbleCluster.proto")
|
||||
public final class DbleClusterGrpc {
|
||||
|
||||
private DbleClusterGrpc() {}
|
||||
|
||||
public static final String SERVICE_NAME = "ushard.DbleCluster";
|
||||
|
||||
// Static method descriptors that strictly reflect the proto.
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_PUT_KV =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "PutKv"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput> METHOD_GET_KV =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "GetKv"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_DELETE_KV =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "DeleteKv"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_DELETE_KV_TREE =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "DeleteKvTree"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput> METHOD_SUBSCRIBE_KV_PREFIX =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "SubscribeKvPrefix"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput> METHOD_GET_KV_TREE =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "GetKvTree"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_ALERT =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "Alert"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_ALERT_RESOLVE =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "AlertResolve"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput> METHOD_LOCK_ON_SESSION =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "LockOnSession"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_RENEW_SESSION =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "RenewSession"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> METHOD_UNLOCK_ON_SESSION =
|
||||
io.grpc.MethodDescriptor.<com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput, com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"ushard.DbleCluster", "UnlockOnSession"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty.getDefaultInstance()))
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Creates a new async stub that supports all call types for the service
|
||||
*/
|
||||
public static DbleClusterStub newStub(io.grpc.Channel channel) {
|
||||
return new DbleClusterStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
|
||||
*/
|
||||
public static DbleClusterBlockingStub newBlockingStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new DbleClusterBlockingStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ListenableFuture-style stub that supports unary calls on the service
|
||||
*/
|
||||
public static DbleClusterFutureStub newFutureStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new DbleClusterFutureStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static abstract class DbleClusterImplBase implements io.grpc.BindableService {
|
||||
|
||||
/**
|
||||
*/
|
||||
public void putKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_PUT_KV, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void getKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_GET_KV, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void deleteKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_DELETE_KV, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void deleteKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_DELETE_KV_TREE, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void subscribeKvPrefix(com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_SUBSCRIBE_KV_PREFIX, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void getKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_GET_KV_TREE, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void alert(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_ALERT, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void alertResolve(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_ALERT_RESOLVE, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void lockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_LOCK_ON_SESSION, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void renewSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_RENEW_SESSION, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void unlockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_UNLOCK_ON_SESSION, responseObserver);
|
||||
}
|
||||
|
||||
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
|
||||
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
|
||||
.addMethod(
|
||||
METHOD_PUT_KV,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_PUT_KV)))
|
||||
.addMethod(
|
||||
METHOD_GET_KV,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput>(
|
||||
this, METHODID_GET_KV)))
|
||||
.addMethod(
|
||||
METHOD_DELETE_KV,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_DELETE_KV)))
|
||||
.addMethod(
|
||||
METHOD_DELETE_KV_TREE,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_DELETE_KV_TREE)))
|
||||
.addMethod(
|
||||
METHOD_SUBSCRIBE_KV_PREFIX,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput>(
|
||||
this, METHODID_SUBSCRIBE_KV_PREFIX)))
|
||||
.addMethod(
|
||||
METHOD_GET_KV_TREE,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput>(
|
||||
this, METHODID_GET_KV_TREE)))
|
||||
.addMethod(
|
||||
METHOD_ALERT,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_ALERT)))
|
||||
.addMethod(
|
||||
METHOD_ALERT_RESOLVE,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_ALERT_RESOLVE)))
|
||||
.addMethod(
|
||||
METHOD_LOCK_ON_SESSION,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput>(
|
||||
this, METHODID_LOCK_ON_SESSION)))
|
||||
.addMethod(
|
||||
METHOD_RENEW_SESSION,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_RENEW_SESSION)))
|
||||
.addMethod(
|
||||
METHOD_UNLOCK_ON_SESSION,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput,
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>(
|
||||
this, METHODID_UNLOCK_ON_SESSION)))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class DbleClusterStub extends io.grpc.stub.AbstractStub<DbleClusterStub> {
|
||||
private DbleClusterStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private DbleClusterStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected DbleClusterStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new DbleClusterStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void putKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_PUT_KV, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void getKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_GET_KV, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void deleteKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_DELETE_KV, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void deleteKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_DELETE_KV_TREE, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void subscribeKvPrefix(com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_SUBSCRIBE_KV_PREFIX, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void getKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_GET_KV_TREE, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void alert(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_ALERT, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void alertResolve(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_ALERT_RESOLVE, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void lockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_LOCK_ON_SESSION, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void renewSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_RENEW_SESSION, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public void unlockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput request,
|
||||
io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_UNLOCK_ON_SESSION, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class DbleClusterBlockingStub extends io.grpc.stub.AbstractStub<DbleClusterBlockingStub> {
|
||||
private DbleClusterBlockingStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private DbleClusterBlockingStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected DbleClusterBlockingStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new DbleClusterBlockingStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty putKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_PUT_KV, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput getKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_GET_KV, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty deleteKv(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_DELETE_KV, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty deleteKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_DELETE_KV_TREE, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput subscribeKvPrefix(com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_SUBSCRIBE_KV_PREFIX, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput getKvTree(com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_GET_KV_TREE, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty alert(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_ALERT, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty alertResolve(com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_ALERT_RESOLVE, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput lockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_LOCK_ON_SESSION, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty renewSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_RENEW_SESSION, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty unlockOnSession(com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_UNLOCK_ON_SESSION, getCallOptions(), request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static final class DbleClusterFutureStub extends io.grpc.stub.AbstractStub<DbleClusterFutureStub> {
|
||||
private DbleClusterFutureStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private DbleClusterFutureStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected DbleClusterFutureStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new DbleClusterFutureStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> putKv(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_PUT_KV, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput> getKv(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_GET_KV, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> deleteKv(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_DELETE_KV, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> deleteKvTree(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_DELETE_KV_TREE, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput> subscribeKvPrefix(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_SUBSCRIBE_KV_PREFIX, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput> getKvTree(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_GET_KV_TREE, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> alert(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_ALERT, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> alertResolve(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_ALERT_RESOLVE, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput> lockOnSession(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_LOCK_ON_SESSION, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> renewSession(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_RENEW_SESSION, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty> unlockOnSession(
|
||||
com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_UNLOCK_ON_SESSION, getCallOptions()), request);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int METHODID_PUT_KV = 0;
|
||||
private static final int METHODID_GET_KV = 1;
|
||||
private static final int METHODID_DELETE_KV = 2;
|
||||
private static final int METHODID_DELETE_KV_TREE = 3;
|
||||
private static final int METHODID_SUBSCRIBE_KV_PREFIX = 4;
|
||||
private static final int METHODID_GET_KV_TREE = 5;
|
||||
private static final int METHODID_ALERT = 6;
|
||||
private static final int METHODID_ALERT_RESOLVE = 7;
|
||||
private static final int METHODID_LOCK_ON_SESSION = 8;
|
||||
private static final int METHODID_RENEW_SESSION = 9;
|
||||
private static final int METHODID_UNLOCK_ON_SESSION = 10;
|
||||
|
||||
private static final class MethodHandlers<Req, Resp> implements
|
||||
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
|
||||
private final DbleClusterImplBase serviceImpl;
|
||||
private final int methodId;
|
||||
|
||||
MethodHandlers(DbleClusterImplBase serviceImpl, int methodId) {
|
||||
this.serviceImpl = serviceImpl;
|
||||
this.methodId = methodId;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
case METHODID_PUT_KV:
|
||||
serviceImpl.putKv((com.actiontech.dble.cluster.impl.ushard.UshardInterface.PutKvInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_GET_KV:
|
||||
serviceImpl.getKv((com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvOutput>) responseObserver);
|
||||
break;
|
||||
case METHODID_DELETE_KV:
|
||||
serviceImpl.deleteKv((com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_DELETE_KV_TREE:
|
||||
serviceImpl.deleteKvTree((com.actiontech.dble.cluster.impl.ushard.UshardInterface.DeleteKvTreeInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_SUBSCRIBE_KV_PREFIX:
|
||||
serviceImpl.subscribeKvPrefix((com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.SubscribeKvPrefixOutput>) responseObserver);
|
||||
break;
|
||||
case METHODID_GET_KV_TREE:
|
||||
serviceImpl.getKvTree((com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.GetKvTreeOutput>) responseObserver);
|
||||
break;
|
||||
case METHODID_ALERT:
|
||||
serviceImpl.alert((com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_ALERT_RESOLVE:
|
||||
serviceImpl.alertResolve((com.actiontech.dble.cluster.impl.ushard.UshardInterface.AlertInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_LOCK_ON_SESSION:
|
||||
serviceImpl.lockOnSession((com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.LockOnSessionOutput>) responseObserver);
|
||||
break;
|
||||
case METHODID_RENEW_SESSION:
|
||||
serviceImpl.renewSession((com.actiontech.dble.cluster.impl.ushard.UshardInterface.RenewSessionInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_UNLOCK_ON_SESSION:
|
||||
serviceImpl.unlockOnSession((com.actiontech.dble.cluster.impl.ushard.UshardInterface.UnlockOnSessionInput) request,
|
||||
(io.grpc.stub.StreamObserver<com.actiontech.dble.cluster.impl.ushard.UshardInterface.Empty>) responseObserver);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public io.grpc.stub.StreamObserver<Req> invoke(
|
||||
io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class DbleClusterDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
|
||||
return com.actiontech.dble.cluster.impl.ushard.UshardInterface.getDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
|
||||
|
||||
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
|
||||
io.grpc.ServiceDescriptor result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
synchronized (DbleClusterGrpc.class) {
|
||||
result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
|
||||
.setSchemaDescriptor(new DbleClusterDescriptorSupplier())
|
||||
.addMethod(METHOD_PUT_KV)
|
||||
.addMethod(METHOD_GET_KV)
|
||||
.addMethod(METHOD_DELETE_KV)
|
||||
.addMethod(METHOD_DELETE_KV_TREE)
|
||||
.addMethod(METHOD_SUBSCRIBE_KV_PREFIX)
|
||||
.addMethod(METHOD_GET_KV_TREE)
|
||||
.addMethod(METHOD_ALERT)
|
||||
.addMethod(METHOD_ALERT_RESOLVE)
|
||||
.addMethod(METHOD_LOCK_ON_SESSION)
|
||||
.addMethod(METHOD_RENEW_SESSION)
|
||||
.addMethod(METHOD_UNLOCK_ON_SESSION)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,280 @@
|
||||
package com.actiontech.dble.cluster.impl.ushard;
|
||||
|
||||
import com.actiontech.dble.cluster.AbstractClusterSender;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.bean.ClusterAlertBean;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
import com.google.common.base.Strings;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static com.actiontech.dble.cluster.ClusterController.GENERAL_GRPC_TIMEOUT;
|
||||
import static com.actiontech.dble.cluster.ClusterController.GRPC_SUBTIMEOUT;
|
||||
|
||||
/**
|
||||
* Created by szf on 2019/3/13.
|
||||
*/
|
||||
public class UshardSender extends AbstractClusterSender {
|
||||
|
||||
private volatile DbleClusterGrpc.DbleClusterBlockingStub stub = null;
|
||||
private ConcurrentHashMap<String, Thread> lockMap = new ConcurrentHashMap<>();
|
||||
private Properties ushardProperties;
|
||||
private final String sourceComponentType = "dble";
|
||||
private String serverId = null;
|
||||
private String sourceComponentId = null;
|
||||
|
||||
@Override
|
||||
public void initConInfo(Properties properties) {
|
||||
this.ushardProperties = properties;
|
||||
serverId = getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID);
|
||||
sourceComponentId = getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
Channel channel = ManagedChannelBuilder.forAddress("127.0.0.1",
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = DbleClusterGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initCluster(Properties properties) {
|
||||
this.ushardProperties = properties;
|
||||
serverId = getValue(ClusterParamCfg.CLUSTER_CFG_SERVER_ID);
|
||||
sourceComponentId = getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
Channel channel = ManagedChannelBuilder.forAddress("127.0.0.1",
|
||||
Integer.parseInt(getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = DbleClusterGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lock(String path, String value) throws Exception {
|
||||
UshardInterface.LockOnSessionInput input = UshardInterface.LockOnSessionInput.newBuilder().setKey(path).setValue(value).setTTLSeconds(30).build();
|
||||
UshardInterface.LockOnSessionOutput output;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).lockOnSession(input);
|
||||
if (!"".equals(output.getSessionId())) {
|
||||
final String session = output.getSessionId();
|
||||
Thread renewThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String sessionId = session;
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
LOGGER.debug("renew lock of session start:" + sessionId + " " + path);
|
||||
if ("".equals(ClusterHelper.getKV(path).getValue())) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ");
|
||||
// alert
|
||||
Thread.currentThread().interrupt();
|
||||
} else if (!renewLock(sessionId)) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path);
|
||||
// alert
|
||||
} else {
|
||||
LOGGER.debug("renew lock of session success:" + sessionId + " " + path);
|
||||
}
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10000));
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path, e);
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(5000));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lockMap.put(path, renewThread);
|
||||
renewThread.setName("UCORE_RENEW_" + path);
|
||||
renewThread.start();
|
||||
}
|
||||
return output.getSessionId();
|
||||
} catch (Exception e1) {
|
||||
throw new IOException("ushard connect failure", e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockKey(String path, String sessionId) {
|
||||
UshardInterface.UnlockOnSessionInput put = UshardInterface.UnlockOnSessionInput.newBuilder().setKey(path).setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
|
||||
Thread renewThread = lockMap.get(path);
|
||||
if (renewThread != null) {
|
||||
renewThread.interrupt();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.info(sessionId + " unlockKey " + path + " error ," + stub, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKV(String path, String value) throws Exception {
|
||||
UshardInterface.PutKvInput input = UshardInterface.PutKvInput.newBuilder().setKey(path).setValue(value).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).putKv(input);
|
||||
} catch (Exception e1) {
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KvBean getKV(String path) {
|
||||
UshardInterface.GetKvInput input = UshardInterface.GetKvInput.newBuilder().setKey(path).build();
|
||||
UshardInterface.GetKvOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKv(input);
|
||||
} catch (Exception e1) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
KvBean bean = new KvBean(path, output.getValue(), 0);
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KvBean> getKVPath(String path) {
|
||||
if (!(path.charAt(path.length() - 1) == '/')) {
|
||||
path = path + "/";
|
||||
}
|
||||
List<KvBean> result = new ArrayList<KvBean>();
|
||||
UshardInterface.GetKvTreeInput input = UshardInterface.GetKvTreeInput.newBuilder().setKey(path).build();
|
||||
|
||||
UshardInterface.GetKvTreeOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
KvBean bean = new KvBean(output.getKeys(i), output.getValues(i), output.getIndex());
|
||||
result.add(bean);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPath(String path) {
|
||||
if (!(path.charAt(path.length() - 1) == '/')) {
|
||||
path = path + "/";
|
||||
}
|
||||
UshardInterface.DeleteKvTreeInput input = UshardInterface.DeleteKvTreeInput.newBuilder().setKey(path).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
cleanKV(path.substring(0, path.length() - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanKV(String path) {
|
||||
UshardInterface.DeleteKvInput input = UshardInterface.DeleteKvInput.newBuilder().setKey(path).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKv(input);
|
||||
} catch (Exception e1) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribeReturnBean subscribeKvPrefix(SubscribeRequest request) throws Exception {
|
||||
UshardInterface.SubscribeKvPrefixInput input = UshardInterface.SubscribeKvPrefixInput.newBuilder().
|
||||
setIndex(request.getIndex()).setDuration(request.getDuration()).setKeyPrefix(request.getPath()).build();
|
||||
try {
|
||||
UshardInterface.SubscribeKvPrefixOutput output = stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeKvPrefix(input);
|
||||
return groupSubscribeResult(output);
|
||||
} catch (Exception e1) {
|
||||
throw new IOException("ushard connect failure");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alert(ClusterAlertBean alert) {
|
||||
UshardInterface.AlertInput input = getInput(alert);
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alert(input);
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("alert to ushard error ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alertResolve(ClusterAlertBean alert) {
|
||||
UshardInterface.AlertInput input = getInput(alert);
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alertResolve(input);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClusterConfig(Properties properties) {
|
||||
if (Strings.isNullOrEmpty(properties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_PORT.getKey())) ||
|
||||
Strings.isNullOrEmpty(properties.getProperty(ClusterParamCfg.CLUSTER_CFG_SERVER_ID.getKey()))) {
|
||||
throw new RuntimeException("Cluster Config is not completely set");
|
||||
}
|
||||
}
|
||||
|
||||
public String getValue(ClusterParamCfg param) {
|
||||
if (ushardProperties != null && null != param) {
|
||||
return ushardProperties.getProperty(param.getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean renewLock(String sessionId) throws Exception {
|
||||
UshardInterface.RenewSessionInput input = UshardInterface.RenewSessionInput.newBuilder().setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).renewSession(input);
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
LOGGER.info("connect to ushard renew error and will retry");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SubscribeReturnBean groupSubscribeResult(UshardInterface.SubscribeKvPrefixOutput output) {
|
||||
SubscribeReturnBean result = new SubscribeReturnBean();
|
||||
result.setIndex(output.getIndex());
|
||||
if (output != null && output.getKeysCount() > 0) {
|
||||
List<KvBean> kvList = new ArrayList<>();
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
kvList.add(new KvBean(output.getKeys(i), output.getValues(i), 0));
|
||||
}
|
||||
result.setKvList(kvList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private UshardInterface.AlertInput getInput(ClusterAlertBean alert) {
|
||||
UshardInterface.AlertInput.Builder builder = UshardInterface.AlertInput.newBuilder().
|
||||
setCode(alert.getCode()).
|
||||
setDesc(alert.getDesc()).
|
||||
setLevel(alert.getLevel().toString()).
|
||||
setSourceComponentType(sourceComponentType).
|
||||
setSourceComponentId(sourceComponentId).
|
||||
setAlertComponentId(alert.getAlertComponentId()).
|
||||
setAlertComponentType(alert.getAlertComponentType()).
|
||||
setServerId(serverId).
|
||||
setTimestampUnix(System.currentTimeMillis() * 1000000);
|
||||
if (alert.getLabels() != null) {
|
||||
builder.putAllLabels(alert.getLabels());
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
syntax = "proto3";
|
||||
option java_multiple_files = false;
|
||||
option java_package = "com.actiontech.dble.cluster.impl.ushard";
|
||||
option java_outer_classname = "UshardInterface";
|
||||
option objc_class_prefix = "ushard";
|
||||
|
||||
package ushard;
|
||||
|
||||
service DbleCluster {
|
||||
|
||||
rpc PutKv (PutKvInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc GetKv (GetKvInput) returns (GetKvOutput) {
|
||||
}
|
||||
|
||||
rpc DeleteKv (DeleteKvInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc DeleteKvTree (DeleteKvTreeInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc SubscribeKvPrefix (SubscribeKvPrefixInput) returns (SubscribeKvPrefixOutput) {
|
||||
}
|
||||
|
||||
rpc GetKvTree (GetKvTreeInput) returns (GetKvTreeOutput) {
|
||||
}
|
||||
|
||||
rpc Alert (AlertInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc AlertResolve (AlertInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc LockOnSession (LockOnSessionInput) returns (LockOnSessionOutput) {
|
||||
}
|
||||
|
||||
rpc RenewSession (RenewSessionInput) returns (Empty) {
|
||||
}
|
||||
|
||||
rpc UnlockOnSession (UnlockOnSessionInput) returns (Empty) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
message Empty {
|
||||
}
|
||||
|
||||
message PutKvInput {
|
||||
string Key = 1;
|
||||
string Value = 2;
|
||||
}
|
||||
|
||||
message GetKvInput {
|
||||
string Key = 1;
|
||||
}
|
||||
|
||||
message GetKvOutput {
|
||||
string Value = 1;
|
||||
}
|
||||
|
||||
message DeleteKvInput {
|
||||
string Key = 1;
|
||||
}
|
||||
|
||||
message DeleteKvTreeInput {
|
||||
string Key = 1;
|
||||
}
|
||||
|
||||
message SubscribeKvPrefixInput {
|
||||
string KeyPrefix = 1;
|
||||
uint64 Index = 2;
|
||||
uint32 Duration = 3;
|
||||
}
|
||||
|
||||
message SubscribeKvPrefixOutput {
|
||||
uint64 Index = 1;
|
||||
repeated string Keys = 2;
|
||||
repeated string Values = 3;
|
||||
}
|
||||
|
||||
message GetKvTreeInput {
|
||||
string Key = 1;
|
||||
}
|
||||
|
||||
message GetKvTreeOutput {
|
||||
uint64 Index = 1;
|
||||
repeated string Keys = 2;
|
||||
repeated string Values = 3;
|
||||
}
|
||||
|
||||
message AlertInput {
|
||||
string Code = 1;
|
||||
string Level = 2;
|
||||
string Desc = 3;
|
||||
string SourceComponentType = 4;
|
||||
string SourceComponentId = 5;
|
||||
string AlertComponentType = 6;
|
||||
string AlertComponentId = 7;
|
||||
string ServerId = 8;
|
||||
map<string, string> Labels = 9;
|
||||
map<string, string> Annotations = 10;
|
||||
int64 TimestampUnix = 11;
|
||||
int64 ResolveTimestampUnix = 12;
|
||||
}
|
||||
|
||||
|
||||
message LockOnSessionInput {
|
||||
string Key = 1;
|
||||
string Value = 2;
|
||||
uint64 TTLSeconds = 3;
|
||||
}
|
||||
|
||||
|
||||
message LockOnSessionOutput {
|
||||
bool Locked = 1;
|
||||
string SessionId = 2;
|
||||
}
|
||||
|
||||
message RenewSessionInput {
|
||||
string SessionId = 1;
|
||||
}
|
||||
|
||||
message UnlockOnSessionInput {
|
||||
string Key = 1;
|
||||
string SessionId = 2;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.cluster.kVtoXml;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.cluster.response.*;
|
||||
import com.actiontech.dble.cluster.listener.ClusterOffLineListener;
|
||||
import com.actiontech.dble.cluster.listener.ClusterSingleKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.parse.XmlProcessBase;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/24.
|
||||
*/
|
||||
public final class ClusterToXml {
|
||||
|
||||
private static ClusterClearKeyListener listener = null;
|
||||
|
||||
private static ClusterSingleKeyListener ddlListener = null;
|
||||
|
||||
private static ClusterSingleKeyListener viewListener = null;
|
||||
|
||||
private static ClusterOffLineListener onlineListener = null;
|
||||
|
||||
|
||||
private ClusterToXml() {
|
||||
|
||||
}
|
||||
|
||||
public static void loadKVtoFile() {
|
||||
try {
|
||||
//create a new listener to the ucore config change
|
||||
listener = new ClusterClearKeyListener();
|
||||
XmlProcessBase xmlProcess = new XmlProcessBase();
|
||||
//add all loader into listener map list
|
||||
new XmlRuleLoader(xmlProcess, listener);
|
||||
new XmlSchemaLoader(xmlProcess, listener);
|
||||
new XmlServerLoader(xmlProcess, listener);
|
||||
new XmlEhcachesLoader(xmlProcess, listener);
|
||||
new CacheserviceResponse(listener);
|
||||
new PropertySequenceLoader(listener);
|
||||
xmlProcess.initJaxbClass();
|
||||
|
||||
//add listener to watch the Prefix of the keys
|
||||
new ConfigStatusResponse(listener);
|
||||
new BinlogPauseStatusResponse(listener);
|
||||
new PauseDataNodeResponse(listener);
|
||||
|
||||
|
||||
ddlListener = new ClusterSingleKeyListener(ClusterPathUtil.getDDLPath() + SEPARATOR, new DdlChildResponse());
|
||||
|
||||
viewListener = new ClusterSingleKeyListener(ClusterPathUtil.getViewChangePath() + SEPARATOR, new ViewChildResponse());
|
||||
|
||||
onlineListener = new ClusterOffLineListener();
|
||||
|
||||
|
||||
listener.initForXml();
|
||||
Thread thread = new Thread(listener);
|
||||
thread.setName("UCORE_KEY_LISTENER");
|
||||
thread.start();
|
||||
|
||||
Thread thread2 = new Thread(ddlListener);
|
||||
thread2.setName("DDL_UCORE_LISTENER");
|
||||
thread2.start();
|
||||
|
||||
Thread thread3 = new Thread(viewListener);
|
||||
thread3.setName("VIEW_UCORE_LISTENER");
|
||||
thread3.start();
|
||||
|
||||
Thread thread4 = new Thread(onlineListener);
|
||||
thread4.setName("ONLINE_UCORE_LISTENER");
|
||||
thread4.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static ClusterClearKeyListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public static Map<String, String> getOnlineMap() {
|
||||
return onlineListener.copyOnlineMap();
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.listen;
|
||||
package com.actiontech.dble.cluster.listener;
|
||||
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
import com.actiontech.dble.cluster.response.ClusterXmlLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -22,11 +23,11 @@ import java.util.concurrent.locks.LockSupport;
|
||||
/**
|
||||
* Created by szf on 2018/1/24.
|
||||
*/
|
||||
public class UcoreClearKeyListener implements Runnable {
|
||||
public class ClusterClearKeyListener implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreClearKeyListener.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterClearKeyListener.class);
|
||||
|
||||
private Map<String, UcoreXmlLoader> childService = new HashMap<>();
|
||||
private Map<String, ClusterXmlLoader> childService = new HashMap<>();
|
||||
|
||||
private Map<String, String> cache = new HashMap<>();
|
||||
|
||||
@@ -37,11 +38,13 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
public void run() {
|
||||
for (; ; ) {
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixInput input
|
||||
= UcoreInterface.SubscribeKvPrefixInput.newBuilder().setIndex(index).setDuration(60).setKeyPrefix(UcorePathUtil.CONF_BASE_PATH).build();
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = ClusterUcoreSender.subscribeKvPrefix(input);
|
||||
SubscribeRequest request = new SubscribeRequest();
|
||||
request.setIndex(index);
|
||||
request.setDuration(60);
|
||||
request.setPath(ClusterPathUtil.CONF_BASE_PATH);
|
||||
SubscribeReturnBean output = ClusterHelper.subscribeKvPrefix(request);
|
||||
if (output.getIndex() != index) {
|
||||
Map<String, UKvBean> diffMap = getDiffMapWithOrder(output);
|
||||
Map<String, KvBean> diffMap = getDiffMapWithOrder(output);
|
||||
handle(diffMap);
|
||||
index = output.getIndex();
|
||||
}
|
||||
@@ -53,28 +56,28 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private Map<String, UKvBean> getDiffMapWithOrder(UcoreInterface.SubscribeKvPrefixOutput output) {
|
||||
Map<String, UKvBean> diffMap = new LinkedHashMap<String, UKvBean>();
|
||||
private Map<String, KvBean> getDiffMapWithOrder(SubscribeReturnBean output) {
|
||||
Map<String, KvBean> diffMap = new LinkedHashMap<String, KvBean>();
|
||||
Map<String, String> newKeyMap = new LinkedHashMap<String, String>();
|
||||
|
||||
UKvBean reloadKv = null;
|
||||
KvBean reloadKv = null;
|
||||
|
||||
//find out the new key & changed key
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
newKeyMap.put(output.getKeys(i), output.getValues(i));
|
||||
if (cache.get(output.getKeys(i)) != null) {
|
||||
if (!cache.get(output.getKeys(i)).equals(output.getValues(i))) {
|
||||
if (output.getKeys(i).equalsIgnoreCase(UcorePathUtil.getConfStatusPath())) {
|
||||
reloadKv = new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.UPDATE);
|
||||
if (output.getKeys(i).equalsIgnoreCase(ClusterPathUtil.getConfStatusPath())) {
|
||||
reloadKv = new KvBean(output.getKeys(i), output.getValues(i), KvBean.UPDATE);
|
||||
} else {
|
||||
diffMap.put(output.getKeys(i), new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.UPDATE));
|
||||
diffMap.put(output.getKeys(i), new KvBean(output.getKeys(i), output.getValues(i), KvBean.UPDATE));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (output.getKeys(i).equalsIgnoreCase(UcorePathUtil.getConfStatusPath())) {
|
||||
reloadKv = new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.ADD);
|
||||
if (output.getKeys(i).equalsIgnoreCase(ClusterPathUtil.getConfStatusPath())) {
|
||||
reloadKv = new KvBean(output.getKeys(i), output.getValues(i), KvBean.ADD);
|
||||
} else {
|
||||
diffMap.put(output.getKeys(i), new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.ADD));
|
||||
diffMap.put(output.getKeys(i), new KvBean(output.getKeys(i), output.getValues(i), KvBean.ADD));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,10 +85,10 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
//find out the deleted Key
|
||||
for (Map.Entry<String, String> entry : cache.entrySet()) {
|
||||
if (!newKeyMap.containsKey(entry.getKey())) {
|
||||
if (entry.getKey().equalsIgnoreCase(UcorePathUtil.getConfStatusPath())) {
|
||||
reloadKv = new UKvBean(entry.getKey(), entry.getValue(), UKvBean.DELETE);
|
||||
if (entry.getKey().equalsIgnoreCase(ClusterPathUtil.getConfStatusPath())) {
|
||||
reloadKv = new KvBean(entry.getKey(), entry.getValue(), KvBean.DELETE);
|
||||
} else {
|
||||
diffMap.put(entry.getKey(), new UKvBean(entry.getKey(), entry.getValue(), UKvBean.DELETE));
|
||||
diffMap.put(entry.getKey(), new KvBean(entry.getKey(), entry.getValue(), KvBean.DELETE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,13 +104,15 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
|
||||
public void initForXml() {
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixInput input
|
||||
= UcoreInterface.SubscribeKvPrefixInput.newBuilder().setIndex(0).setDuration(60).setKeyPrefix(UcorePathUtil.BASE_PATH).build();
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = ClusterUcoreSender.subscribeKvPrefix(input);
|
||||
SubscribeRequest request = new SubscribeRequest();
|
||||
request.setIndex(0);
|
||||
request.setDuration(60);
|
||||
request.setPath(ClusterPathUtil.BASE_PATH);
|
||||
SubscribeReturnBean output = ClusterHelper.subscribeKvPrefix(request);
|
||||
index = output.getIndex();
|
||||
Map<String, UKvBean> diffMap = new HashMap<String, UKvBean>();
|
||||
Map<String, KvBean> diffMap = new HashMap<String, KvBean>();
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
diffMap.put(output.getKeys(i), new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.ADD));
|
||||
diffMap.put(output.getKeys(i), new KvBean(output.getKeys(i), output.getValues(i), KvBean.ADD));
|
||||
cache.put(output.getKeys(i), output.getValues(i));
|
||||
}
|
||||
handle(diffMap);
|
||||
@@ -122,10 +127,10 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
* if the config version changes,write the file
|
||||
* or just start a new waiting
|
||||
*/
|
||||
public void handle(Map<String, UKvBean> diffMap) {
|
||||
public void handle(Map<String, KvBean> diffMap) {
|
||||
try {
|
||||
for (Map.Entry<String, UKvBean> entry : diffMap.entrySet()) {
|
||||
UcoreXmlLoader x = childService.get(entry.getKey());
|
||||
for (Map.Entry<String, KvBean> entry : diffMap.entrySet()) {
|
||||
ClusterXmlLoader x = childService.get(entry.getKey());
|
||||
if (x != null) {
|
||||
x.notifyProcess(entry.getValue());
|
||||
}
|
||||
@@ -143,20 +148,20 @@ public class UcoreClearKeyListener implements Runnable {
|
||||
* @param loader
|
||||
* @param path
|
||||
*/
|
||||
public void addChild(UcoreXmlLoader loader, String path) {
|
||||
public void addChild(ClusterXmlLoader loader, String path) {
|
||||
this.childService.put(path, loader);
|
||||
}
|
||||
|
||||
public UcoreXmlLoader getReponse(String key) {
|
||||
public ClusterXmlLoader getReponse(String key) {
|
||||
return this.childService.get(key);
|
||||
}
|
||||
|
||||
public void initAllNode() {
|
||||
for (Map.Entry<String, UcoreXmlLoader> service : childService.entrySet()) {
|
||||
for (Map.Entry<String, ClusterXmlLoader> service : childService.entrySet()) {
|
||||
try {
|
||||
service.getValue().notifyCluster();
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(" UcoreClearKeyListener init all node error:", e);
|
||||
LOGGER.warn(" ClusterClearKeyListener init all node error:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,19 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.listen;
|
||||
package com.actiontech.dble.cluster.listener;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.KVtoXml.UcoreToXml;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.loader.UDdlChildResponse;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
import com.actiontech.dble.cluster.kVtoXml.ClusterToXml;
|
||||
import com.actiontech.dble.cluster.response.ClusterXmlLoader;
|
||||
import com.actiontech.dble.cluster.response.DdlChildResponse;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.PauseInfo;
|
||||
import com.actiontech.dble.server.status.OnlineLockStatus;
|
||||
@@ -24,14 +25,14 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/2/8.
|
||||
*/
|
||||
public class UOffLineListener implements Runnable {
|
||||
public class ClusterOffLineListener implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UOffLineListener.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterOffLineListener.class);
|
||||
private volatile Map<String, String> onlineMap = new HashMap<>();
|
||||
private long index = 0;
|
||||
|
||||
@@ -43,11 +44,11 @@ public class UOffLineListener implements Runnable {
|
||||
private void checkDDLAndRelease(String serverId) {
|
||||
//deal with the status when the ddl is init notified
|
||||
//and than the ddl server is shutdown
|
||||
for (Map.Entry<String, String> en : UDdlChildResponse.getLockMap().entrySet()) {
|
||||
for (Map.Entry<String, String> en : DdlChildResponse.getLockMap().entrySet()) {
|
||||
if (serverId.equals(en.getValue())) {
|
||||
DbleServer.getInstance().getTmManager().removeMetaLock(en.getKey().split("\\.")[0], en.getKey().split("\\.")[1]);
|
||||
UDdlChildResponse.getLockMap().remove(en.getKey());
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getDDLPath(en.getKey()) + "/");
|
||||
DdlChildResponse.getLockMap().remove(en.getKey());
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getDDLPath(en.getKey()) + "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,17 +56,17 @@ public class UOffLineListener implements Runnable {
|
||||
private void checkBinlogStatusRelease(String serverId) {
|
||||
try {
|
||||
//check the latest bing_log status
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getBinlogPauseLockPath());
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getBinlogPauseLockPath());
|
||||
if ("".equals(lock.getValue()) || serverId.equals(lock.getValue())) {
|
||||
DbleServer.getInstance().getBackupLocked().compareAndSet(true, false);
|
||||
}
|
||||
UKvBean status = ClusterUcoreSender.getKey(UcorePathUtil.getBinlogPauseStatus());
|
||||
KvBean status = ClusterHelper.getKV(ClusterPathUtil.getBinlogPauseStatus());
|
||||
if (!"".equals(status.getValue())) {
|
||||
BinlogPause pauseInfo = new BinlogPause(status.getValue());
|
||||
if (pauseInfo.getStatus() == BinlogPause.BinlogPauseStatus.ON && serverId.equals(pauseInfo.getFrom())) {
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getBinlogPauseStatus() + "/");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), (new BinlogPause("", BinlogPause.BinlogPauseStatus.OFF)).toString());
|
||||
ClusterUcoreSender.deleteKV(UcorePathUtil.getBinlogPauseLockPath());
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getBinlogPauseStatus() + "/");
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatus(), (new BinlogPause("", BinlogPause.BinlogPauseStatus.OFF)).toString());
|
||||
ClusterHelper.cleanKV(ClusterPathUtil.getBinlogPauseLockPath());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -75,7 +76,7 @@ public class UOffLineListener implements Runnable {
|
||||
|
||||
private void checkPauseStatusRelease(String serverId) {
|
||||
try {
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getPauseDataNodePath());
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getPauseDataNodePath());
|
||||
boolean needRelease = false;
|
||||
if (!"".equals(lock.getValue())) {
|
||||
PauseInfo pauseInfo = new PauseInfo(lock.getValue());
|
||||
@@ -86,7 +87,7 @@ public class UOffLineListener implements Runnable {
|
||||
needRelease = true;
|
||||
}
|
||||
if (needRelease) {
|
||||
UcoreXmlLoader loader = UcoreToXml.getListener().getReponse(UcorePathUtil.getPauseDataNodePath());
|
||||
ClusterXmlLoader loader = ClusterToXml.getListener().getReponse(ClusterPathUtil.getPauseDataNodePath());
|
||||
loader.notifyCluster();
|
||||
}
|
||||
|
||||
@@ -101,11 +102,11 @@ public class UOffLineListener implements Runnable {
|
||||
boolean lackSelf = false;
|
||||
for (; ; ) {
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixInput input
|
||||
= UcoreInterface.SubscribeKvPrefixInput.newBuilder().
|
||||
setIndex(index).setDuration(60).
|
||||
setKeyPrefix(UcorePathUtil.getOnlinePath() + SEPARATOR).build();
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = ClusterUcoreSender.subscribeKvPrefix(input);
|
||||
SubscribeRequest request = new SubscribeRequest();
|
||||
request.setIndex(index);
|
||||
request.setDuration(60);
|
||||
request.setPath(ClusterPathUtil.getOnlinePath() + SEPARATOR);
|
||||
SubscribeReturnBean output = ClusterHelper.subscribeKvPrefix(request);
|
||||
if (output.getIndex() == index) {
|
||||
if (lackSelf) {
|
||||
lackSelf = !reInitOnlineStatus();
|
||||
@@ -127,8 +128,8 @@ public class UOffLineListener implements Runnable {
|
||||
checkPauseStatusRelease(serverId);
|
||||
}
|
||||
}
|
||||
String serverId = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
String selfPath = UcorePathUtil.getOnlinePath(serverId);
|
||||
String serverId = ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
String selfPath = ClusterPathUtil.getOnlinePath(serverId);
|
||||
if (!newMap.containsKey(selfPath)) {
|
||||
lackSelf = !reInitOnlineStatus();
|
||||
newMap.put(selfPath, serverId);
|
||||
@@ -3,12 +3,13 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.listen;
|
||||
package com.actiontech.dble.cluster.listener;
|
||||
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeRequest;
|
||||
import com.actiontech.dble.cluster.bean.SubscribeReturnBean;
|
||||
import com.actiontech.dble.cluster.response.ClusterXmlLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -17,14 +18,15 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/2/2.
|
||||
*/
|
||||
public class UcoreSingleKeyListener implements Runnable {
|
||||
public class ClusterSingleKeyListener implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreSingleKeyListener.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterSingleKeyListener.class);
|
||||
private long index = 0;
|
||||
UcoreXmlLoader child;
|
||||
ClusterXmlLoader child;
|
||||
String path;
|
||||
|
||||
private Map<String, String> cache = new HashMap<>();
|
||||
@@ -34,11 +36,13 @@ public class UcoreSingleKeyListener implements Runnable {
|
||||
public void run() {
|
||||
for (; ; ) {
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixInput input
|
||||
= UcoreInterface.SubscribeKvPrefixInput.newBuilder().setIndex(index).setDuration(60).setKeyPrefix(path).build();
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = ClusterUcoreSender.subscribeKvPrefix(input);
|
||||
SubscribeRequest request = new SubscribeRequest();
|
||||
request.setIndex(index);
|
||||
request.setDuration(60);
|
||||
request.setPath(path);
|
||||
SubscribeReturnBean output = ClusterHelper.subscribeKvPrefix(request);
|
||||
if (output.getIndex() != index) {
|
||||
Map<String, UKvBean> diffMap = getDiffMap(output);
|
||||
Map<String, KvBean> diffMap = getDiffMap(output);
|
||||
handle(diffMap);
|
||||
index = output.getIndex();
|
||||
}
|
||||
@@ -50,14 +54,14 @@ public class UcoreSingleKeyListener implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public UcoreSingleKeyListener(String path, UcoreXmlLoader child) {
|
||||
public ClusterSingleKeyListener(String path, ClusterXmlLoader child) {
|
||||
this.child = child;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void handle(Map<String, UKvBean> diffMap) {
|
||||
public void handle(Map<String, KvBean> diffMap) {
|
||||
try {
|
||||
for (Map.Entry<String, UKvBean> entry : diffMap.entrySet()) {
|
||||
for (Map.Entry<String, KvBean> entry : diffMap.entrySet()) {
|
||||
child.notifyProcess(entry.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -66,8 +70,8 @@ public class UcoreSingleKeyListener implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
private Map<String, UKvBean> getDiffMap(UcoreInterface.SubscribeKvPrefixOutput output) {
|
||||
Map<String, UKvBean> diffMap = new HashMap<String, UKvBean>();
|
||||
private Map<String, KvBean> getDiffMap(SubscribeReturnBean output) {
|
||||
Map<String, KvBean> diffMap = new HashMap<String, KvBean>();
|
||||
Map<String, String> newKeyMap = new HashMap<String, String>();
|
||||
|
||||
//find out the new key & changed key
|
||||
@@ -75,17 +79,17 @@ public class UcoreSingleKeyListener implements Runnable {
|
||||
newKeyMap.put(output.getKeys(i), output.getValues(i));
|
||||
if (cache.get(output.getKeys(i)) != null) {
|
||||
if (!cache.get(output.getKeys(i)).equals(output.getValues(i))) {
|
||||
diffMap.put(output.getKeys(i), new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.UPDATE));
|
||||
diffMap.put(output.getKeys(i), new KvBean(output.getKeys(i), output.getValues(i), KvBean.UPDATE));
|
||||
}
|
||||
} else {
|
||||
diffMap.put(output.getKeys(i), new UKvBean(output.getKeys(i), output.getValues(i), UKvBean.ADD));
|
||||
diffMap.put(output.getKeys(i), new KvBean(output.getKeys(i), output.getValues(i), KvBean.ADD));
|
||||
}
|
||||
}
|
||||
|
||||
//find out the deleted Key
|
||||
for (Map.Entry<String, String> entry : cache.entrySet()) {
|
||||
if (!newKeyMap.containsKey(entry.getKey())) {
|
||||
diffMap.put(entry.getKey(), new UKvBean(entry.getKey(), entry.getValue(), UKvBean.DELETE));
|
||||
diffMap.put(entry.getKey(), new KvBean(entry.getKey(), entry.getValue(), KvBean.DELETE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause;
|
||||
import com.actiontech.dble.manager.response.ShowBinlogStatus;
|
||||
import org.slf4j.Logger;
|
||||
@@ -21,40 +20,40 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Created by szf on 2018/1/31.
|
||||
*/
|
||||
public class UBinlogPauseStatusResponse implements UcoreXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UBinlogPauseStatusResponse.class);
|
||||
public class BinlogPauseStatusResponse implements ClusterXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BinlogPauseStatusResponse.class);
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getBinlogPauseStatus();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getBinlogPauseStatus();
|
||||
|
||||
|
||||
public UBinlogPauseStatusResponse(UcoreClearKeyListener confListener) {
|
||||
public BinlogPauseStatusResponse(ClusterClearKeyListener confListener) {
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
|
||||
//step 1 check if the block is from the server itself
|
||||
BinlogPause pauseInfo = new BinlogPause(configValue.getValue());
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
if (pauseInfo.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
if (pauseInfo.getFrom().equals(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
LOGGER.info("Self Notice,Do nothing return");
|
||||
return;
|
||||
}
|
||||
|
||||
//step 2 if the flag is on than try to lock all the commit
|
||||
if (pauseInfo.getStatus() == BinlogPause.BinlogPauseStatus.ON && !UKvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
if (pauseInfo.getStatus() == BinlogPause.BinlogPauseStatus.ON && !KvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
DbleServer.getInstance().getBackupLocked().compareAndSet(false, true);
|
||||
LOGGER.info("start pause for binlog status");
|
||||
boolean isPaused = ShowBinlogStatus.waitAllSession();
|
||||
if (!isPaused) {
|
||||
cleanResource();
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatusSelf(), "Error can't wait all session finished ");
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatusSelf(), "Error can't wait all session finished ");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatusSelf(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatusSelf(), ClusterPathUtil.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
cleanResource();
|
||||
LOGGER.warn("create binlogPause instance failed", e);
|
||||
@@ -3,15 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ConfFileRWUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -20,24 +19,24 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Created by szf on 2018/5/16.
|
||||
*/
|
||||
public class UCacheserviceResponse implements UcoreXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UCacheserviceResponse.class);
|
||||
public class CacheserviceResponse implements ClusterXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CacheserviceResponse.class);
|
||||
|
||||
private static final String PROPERTIES_SUFFIX = ".properties";
|
||||
|
||||
private static final String PROPERTIES_CACHESERVER_NAME = "cacheservice";
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getEhcacheProPath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getEhcacheProPath();
|
||||
|
||||
public UCacheserviceResponse(UcoreClearKeyListener confListener) {
|
||||
public CacheserviceResponse(ClusterClearKeyListener confListener) {
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
return;
|
||||
}
|
||||
if (configValue.getValue() != null && !"".equals(configValue.getValue())) {
|
||||
@@ -56,6 +55,6 @@ public class UCacheserviceResponse implements UcoreXmlLoader {
|
||||
if (cacheService != null && !"".equals(cacheService)) {
|
||||
jsonObject.put(PROPERTIES_CACHESERVER_NAME, cacheService);
|
||||
}
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, jsonObject.toJSONString());
|
||||
ClusterHelper.setKV(CONFIG_PATH, jsonObject.toJSONString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public interface ClusterXmlLoader {
|
||||
|
||||
void notifyProcess(KvBean configValue) throws Exception;
|
||||
|
||||
void notifyCluster() throws Exception;
|
||||
}
|
||||
@@ -3,14 +3,16 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus;
|
||||
import com.actiontech.dble.manager.response.ReloadConfig;
|
||||
import com.actiontech.dble.manager.response.RollbackConfig;
|
||||
@@ -20,32 +22,32 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Created by szf on 2018/1/31.
|
||||
*/
|
||||
public class UConfigStatusResponse implements UcoreXmlLoader {
|
||||
public class ConfigStatusResponse implements ClusterXmlLoader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UBinlogPauseStatusResponse.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BinlogPauseStatusResponse.class);
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getConfStatusPath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getConfStatusPath();
|
||||
|
||||
public UConfigStatusResponse(UcoreClearKeyListener confListener) {
|
||||
public ConfigStatusResponse(ClusterClearKeyListener confListener) {
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean pathValue) throws Exception {
|
||||
public void notifyProcess(KvBean pathValue) throws Exception {
|
||||
|
||||
ClusterDelayProvider.delayAfterGetNotice();
|
||||
if (DbleServer.getInstance().getFrontProcessors() != null) {
|
||||
//step 1 check if the change is from itself
|
||||
LOGGER.info("notify " + pathValue.getKey() + " " + pathValue.getValue() + " " + pathValue.getChangeType());
|
||||
ConfStatus status = new ConfStatus(pathValue.getValue());
|
||||
if (status.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
if (status.getFrom().equals(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
//self node
|
||||
return;
|
||||
}
|
||||
|
||||
//check if the reload is already be done by this node
|
||||
if (!"".equals(ClusterUcoreSender.getKey(UcorePathUtil.getSelfConfStatusPath()).getValue()) ||
|
||||
"".equals(ClusterUcoreSender.getKey(UcorePathUtil.getConfStatusPath()).getValue())) {
|
||||
if (!"".equals(ClusterHelper.getKV(ClusterPathUtil.getSelfConfStatusPath()).getValue()) ||
|
||||
"".equals(ClusterHelper.getKV(ClusterPathUtil.getConfStatusPath()).getValue())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,12 +60,12 @@ public class UConfigStatusResponse implements UcoreXmlLoader {
|
||||
RollbackConfig.rollback();
|
||||
ClusterDelayProvider.delayAfterSlaveRollback();
|
||||
LOGGER.info("rollback config: sent config status success to ucore start");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), ClusterPathUtil.SUCCESS);
|
||||
LOGGER.info("rollback config: sent config status success to ucore end");
|
||||
} catch (Exception e) {
|
||||
String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
|
||||
LOGGER.info("rollback config: sent config status failed to ucore start");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), errorinfo);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), errorinfo);
|
||||
LOGGER.info("rollback config: sent config status failed to ucore end");
|
||||
}
|
||||
return;
|
||||
@@ -81,12 +83,12 @@ public class UConfigStatusResponse implements UcoreXmlLoader {
|
||||
}
|
||||
ClusterDelayProvider.delayAfterSlaveReload();
|
||||
LOGGER.info("reload config: sent config status success to ucore start");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), ClusterPathUtil.SUCCESS);
|
||||
LOGGER.info("reload config: sent config status success to ucore end");
|
||||
} catch (Exception e) {
|
||||
String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
|
||||
LOGGER.info("reload config: sent config status failed to ucore start");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), errorinfo);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), errorinfo);
|
||||
LOGGER.info("reload config: sent config status failed to ucore end");
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
@@ -24,14 +23,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* Created by szf on 2018/2/1.
|
||||
*/
|
||||
public class UDdlChildResponse implements UcoreXmlLoader {
|
||||
public class DdlChildResponse implements ClusterXmlLoader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UDdlChildResponse.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DdlChildResponse.class);
|
||||
private static Map<String, String> lockMap = new ConcurrentHashMap<String, String>();
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
if (configValue.getKey().split("/").length == UcorePathUtil.getDDLPath().split("/").length + 2) {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
if (configValue.getKey().split("/").length == ClusterPathUtil.getDDLPath().split("/").length + 2) {
|
||||
//child change the listener is not supported
|
||||
//only response for the key /un.../d.../clu.../ddl/schema.table
|
||||
return;
|
||||
@@ -43,13 +42,13 @@ public class UDdlChildResponse implements UcoreXmlLoader {
|
||||
final String schema = StringUtil.removeBackQuote(tableInfo[0]);
|
||||
final String table = StringUtil.removeBackQuote(tableInfo[1]);
|
||||
|
||||
if (UKvBean.DELETE.equals(configValue.getChangeType()) || "".equals(configValue.getValue())) {
|
||||
if (KvBean.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))) {
|
||||
if (ddlInfo.getFrom().equals(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
return; //self node
|
||||
}
|
||||
|
||||
@@ -65,7 +64,7 @@ public class UDdlChildResponse implements UcoreXmlLoader {
|
||||
throw t;
|
||||
}
|
||||
|
||||
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.SUCCESS && !UKvBean.DELETE.equals(configValue.getChangeType()) &&
|
||||
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.SUCCESS && !KvBean.DELETE.equals(configValue.getChangeType()) &&
|
||||
lockMap.containsKey(fullName)) {
|
||||
LOGGER.info("ddl execute success notice");
|
||||
// if the start node is done the ddl execute
|
||||
@@ -81,14 +80,14 @@ public class UDdlChildResponse implements UcoreXmlLoader {
|
||||
}
|
||||
|
||||
ClusterDelayProvider.delayBeforeDdlResponse();
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(fullName), UcorePathUtil.SUCCESS);
|
||||
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.FAILED && !UKvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
ClusterHelper.setKV(ClusterPathUtil.getDDLInstancePath(fullName), ClusterPathUtil.SUCCESS);
|
||||
} else if (ddlInfo.getStatus() == DDLInfo.DDLStatus.FAILED && !KvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
LOGGER.info("ddl execute failed notice");
|
||||
//if the start node executing ddl with error,just release the lock
|
||||
lockMap.remove(fullName);
|
||||
DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
|
||||
ClusterDelayProvider.delayBeforeDdlResponse();
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(fullName), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getDDLInstancePath(fullName), ClusterPathUtil.SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +103,6 @@ public class UDdlChildResponse implements UcoreXmlLoader {
|
||||
}
|
||||
|
||||
public static void setLockMap(Map<String, String> lockMap) {
|
||||
UDdlChildResponse.lockMap = lockMap;
|
||||
DdlChildResponse.lockMap = lockMap;
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,16 @@
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.BackendConnection;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.PauseInfo;
|
||||
import com.actiontech.dble.net.FrontendConnection;
|
||||
import com.actiontech.dble.net.NIOProcessor;
|
||||
@@ -30,31 +29,31 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean.DELETE;
|
||||
import static com.actiontech.dble.cluster.bean.KvBean.DELETE;
|
||||
|
||||
|
||||
public class UPauseDataNodeResponse implements UcoreXmlLoader {
|
||||
public class PauseDataNodeResponse implements ClusterXmlLoader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UPauseDataNodeResponse.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PauseDataNodeResponse.class);
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getPauseDataNodePath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getPauseDataNodePath();
|
||||
|
||||
private Thread waitThread;
|
||||
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
public UPauseDataNodeResponse(UcoreClearKeyListener confListener) {
|
||||
public PauseDataNodeResponse(ClusterClearKeyListener confListener) {
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
confListener.addChild(this, UcorePathUtil.getPauseResumePath());
|
||||
confListener.addChild(this, ClusterPathUtil.getPauseResumePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
LOGGER.info("get key in UPauseDataNodeResponse:" + configValue.getKey() + " " + configValue.getValue());
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("get key in PauseDataNodeResponse:" + configValue.getKey() + " " + configValue.getValue());
|
||||
if (!DELETE.equals(configValue.getChangeType())) {
|
||||
if (configValue.getKey().equals(UcorePathUtil.getPauseDataNodePath()) || UcorePathUtil.getPauseResumePath().equals(configValue.getKey())) {
|
||||
if (configValue.getKey().equals(ClusterPathUtil.getPauseDataNodePath()) || ClusterPathUtil.getPauseResumePath().equals(configValue.getKey())) {
|
||||
final PauseInfo pauseInfo = new PauseInfo(configValue.getValue());
|
||||
if (!pauseInfo.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
if (!pauseInfo.getFrom().equals(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
if (PauseInfo.PAUSE.equals(pauseInfo.getType())) {
|
||||
final String dataNodes = pauseInfo.getDataNodes();
|
||||
waitThread = new Thread(new Runnable() {
|
||||
@@ -90,8 +89,8 @@ public class UPauseDataNodeResponse implements UcoreXmlLoader {
|
||||
}
|
||||
}
|
||||
if (!nextTurn) {
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getPauseResultNodePath(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
ClusterHelper.setKV(ClusterPathUtil.getPauseResultNodePath(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
@@ -118,8 +117,8 @@ public class UPauseDataNodeResponse implements UcoreXmlLoader {
|
||||
}
|
||||
LOGGER.info("resume dataNodes for get notice");
|
||||
DbleServer.getInstance().getMiManager().resume();
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getPauseResumePath(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
ClusterHelper.setKV(ClusterPathUtil.getPauseResumePath(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ConfFileRWUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -18,9 +20,9 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Created by szf on 2018/1/29.
|
||||
*/
|
||||
public class UPropertySequenceLoader implements UcoreXmlLoader {
|
||||
public class PropertySequenceLoader implements ClusterXmlLoader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UPropertySequenceLoader.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertySequenceLoader.class);
|
||||
|
||||
private static final String PROPERTIES_SUFFIX = ".properties";
|
||||
|
||||
@@ -29,18 +31,18 @@ public class UPropertySequenceLoader implements UcoreXmlLoader {
|
||||
private static final String PROPERTIES_SEQUENCE_DB_CONF = "sequence_db_conf";
|
||||
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getSequencesPath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getSequencesPath();
|
||||
|
||||
|
||||
public UPropertySequenceLoader(UcoreClearKeyListener confListener) {
|
||||
public PropertySequenceLoader(ClusterClearKeyListener confListener) {
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
return;
|
||||
}
|
||||
if (configValue.getValue() != null && !"".equals(configValue.getValue())) {
|
||||
@@ -68,7 +70,7 @@ public class UPropertySequenceLoader implements UcoreXmlLoader {
|
||||
if (sequenceDbConf != null && !"".equals(sequenceDbConf)) {
|
||||
jsonObject.put(PROPERTIES_SEQUENCE_DB_CONF, sequenceDbConf);
|
||||
}
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, jsonObject.toJSONString());
|
||||
ClusterHelper.setKV(CONFIG_PATH, jsonObject.toJSONString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,16 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.mysql.view.Repository;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.meta.ViewMeta;
|
||||
import com.actiontech.dble.net.mysql.ErrorPacket;
|
||||
import org.slf4j.Logger;
|
||||
@@ -18,18 +20,18 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/2/5.
|
||||
*/
|
||||
public class UViewChildResponse implements UcoreXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UViewChildResponse.class);
|
||||
public class ViewChildResponse implements ClusterXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ViewChildResponse.class);
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
if (configValue.getKey().split("/").length != UcorePathUtil.getViewChangePath().split("/").length + 1) {
|
||||
if (configValue.getKey().split("/").length != ClusterPathUtil.getViewChangePath().split("/").length + 1) {
|
||||
//only with the type u.../d.../clu.../view/update(delete)/schema.table
|
||||
return;
|
||||
}
|
||||
@@ -43,8 +45,8 @@ public class UViewChildResponse implements UcoreXmlLoader {
|
||||
|
||||
String serverId = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[0];
|
||||
String optionType = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[1];
|
||||
String myId = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
if (myId.equals(serverId) || UKvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
String myId = ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
if (myId.equals(serverId) || KvBean.DELETE.equals(configValue.getChangeType())) {
|
||||
// self node do noting
|
||||
return;
|
||||
} else {
|
||||
@@ -58,15 +60,15 @@ public class UViewChildResponse implements UcoreXmlLoader {
|
||||
DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().remove(viewName);
|
||||
|
||||
ClusterDelayProvider.delayBeforeReponseView();
|
||||
ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(configValue.getKey() + SEPARATOR + myId, ClusterPathUtil.SUCCESS);
|
||||
} else if (Repository.UPDATE.equals(optionType)) {
|
||||
LOGGER.info("update view " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
ClusterDelayProvider.delayBeforeReponseGetView();
|
||||
String stmt = ClusterUcoreSender.getKey(UcorePathUtil.getViewPath() + SEPARATOR + schema + Repository.SCHEMA_VIEW_SPLIT + viewName).getValue();
|
||||
String stmt = ClusterHelper.getKV(ClusterPathUtil.getViewPath() + SEPARATOR + schema + Repository.SCHEMA_VIEW_SPLIT + viewName).getValue();
|
||||
if (DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName) != null &&
|
||||
stmt.equals(DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName).getCreateSql())) {
|
||||
ClusterDelayProvider.delayBeforeReponseView();
|
||||
ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(configValue.getKey() + SEPARATOR + myId, ClusterPathUtil.SUCCESS);
|
||||
return;
|
||||
}
|
||||
ViewMeta vm = new ViewMeta(stmt, schema, DbleServer.getInstance().getTmManager());
|
||||
@@ -79,15 +81,15 @@ public class UViewChildResponse implements UcoreXmlLoader {
|
||||
LOGGER.info("update view result == " + error);
|
||||
if (error != null) {
|
||||
ClusterDelayProvider.delayBeforeReponseView();
|
||||
ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, new String(error.getMessage()));
|
||||
ClusterHelper.setKV(configValue.getKey() + SEPARATOR + myId, new String(error.getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
ClusterDelayProvider.delayBeforeReponseView();
|
||||
ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(configValue.getKey() + SEPARATOR + myId, ClusterPathUtil.SUCCESS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ClusterUcoreSender.sendDataToUcore(configValue.getKey() + "/" + myId, e.toString());
|
||||
ClusterHelper.setKV(configValue.getKey() + "/" + myId, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.cache.Ehcache;
|
||||
import com.actiontech.dble.config.loader.zkprocess.parse.ParseJsonServiceInf;
|
||||
import com.actiontech.dble.config.loader.zkprocess.parse.ParseXmlServiceInf;
|
||||
@@ -25,8 +27,8 @@ import java.io.File;
|
||||
/**
|
||||
* Created by szf on 2018/1/29.
|
||||
*/
|
||||
public class UXmlEhcachesLoader implements UcoreXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UXmlEhcachesLoader.class);
|
||||
public class XmlEhcachesLoader implements ClusterXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(XmlEhcachesLoader.class);
|
||||
|
||||
private final ParseXmlServiceInf<Ehcache> parseEcacheXMl;
|
||||
|
||||
@@ -34,24 +36,24 @@ public class UXmlEhcachesLoader implements UcoreXmlLoader {
|
||||
|
||||
private static final String WRITEPATH = "ehcache.xml";
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getEhcacheNamePath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getEhcacheNamePath();
|
||||
|
||||
public UXmlEhcachesLoader(XmlProcessBase xmlParseBase, UcoreClearKeyListener confListener) {
|
||||
public XmlEhcachesLoader(XmlProcessBase xmlParseBase, ClusterClearKeyListener confListener) {
|
||||
this.parseEcacheXMl = new EhcacheParseXmlImpl(xmlParseBase);
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.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);
|
||||
if (jsonObj.get(ClusterPathUtil.EHCACHE) != null) {
|
||||
Ehcache ehcache = parseJsonEhcacheService.parseJsonToBean(jsonObj.getJSONObject(ClusterPathUtil.EHCACHE).toJSONString());
|
||||
String path = ResourceUtil.getResourcePathFromRoot(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
path = new File(path).getPath() + File.separator + WRITEPATH;
|
||||
this.parseEcacheXMl.parseToXmlWrite(ehcache, path, null);
|
||||
}
|
||||
@@ -59,9 +61,9 @@ public class UXmlEhcachesLoader implements UcoreXmlLoader {
|
||||
|
||||
@Override
|
||||
public void notifyCluster() throws Exception {
|
||||
Ehcache ehcache = this.parseEcacheXMl.parseXmlToBean(UcorePathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
Ehcache ehcache = this.parseEcacheXMl.parseXmlToBean(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
JSONObject ehcacheObj = new JSONObject();
|
||||
ehcacheObj.put(UcorePathUtil.EHCACHE, ehcache);
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, ehcacheObj.toJSONString());
|
||||
ehcacheObj.put(ClusterPathUtil.EHCACHE, ehcache);
|
||||
ClusterHelper.setKV(CONFIG_PATH, ehcacheObj.toJSONString());
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreXmlLoader;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ConfFileRWUtils;
|
||||
import com.actiontech.dble.config.loader.zkprocess.console.ParseParamEnum;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.Property;
|
||||
@@ -37,8 +36,8 @@ import java.util.List;
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public class UXmlRuleLoader implements UcoreXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreXmlLoader.class);
|
||||
public class XmlRuleLoader implements ClusterXmlLoader {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterXmlLoader.class);
|
||||
|
||||
private ParseJsonServiceInf<List<TableRule>> parseJsonTableRuleService = new TableRuleJsonParse();
|
||||
|
||||
@@ -48,34 +47,34 @@ public class UXmlRuleLoader implements UcoreXmlLoader {
|
||||
|
||||
private ParseXmlServiceInf<Rules> parseRulesXMl;
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getConfRulePath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getConfRulePath();
|
||||
|
||||
|
||||
public UXmlRuleLoader(XmlProcessBase xmlParseBase, UcoreClearKeyListener confListener) {
|
||||
public XmlRuleLoader(XmlProcessBase xmlParseBase, ClusterClearKeyListener confListener) {
|
||||
this.parseRulesXMl = new RuleParseXmlImpl(xmlParseBase);
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.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());
|
||||
List<Function> functions = parseJsonFunctionService.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.FUNCTION).toJSONString());
|
||||
rule.setFunction(functions);
|
||||
|
||||
List<TableRule> tableRules = parseJsonTableRuleService.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.TABLE_RULE).toJSONString());
|
||||
List<TableRule> tableRules = parseJsonTableRuleService.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.TABLE_RULE).toJSONString());
|
||||
rule.setTableRule(tableRules);
|
||||
|
||||
rule.setVersion(jsonObj.getString(UcorePathUtil.VERSION));
|
||||
rule.setVersion(jsonObj.getString(ClusterPathUtil.VERSION));
|
||||
|
||||
String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
String path = ResourceUtil.getResourcePathFromRoot(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
path = new File(path).getPath() + File.separator;
|
||||
path += WRITEPATH;
|
||||
|
||||
@@ -90,14 +89,14 @@ public class UXmlRuleLoader implements UcoreXmlLoader {
|
||||
|
||||
@Override
|
||||
public void notifyCluster() throws Exception {
|
||||
Rules rules = this.parseRulesXMl.parseXmlToBean(UcorePathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
Rules rules = this.parseRulesXMl.parseXmlToBean(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
JSONObject rule = new JSONObject();
|
||||
|
||||
readMapFileAddFunction(rules.getFunction());
|
||||
rule.put(UcorePathUtil.VERSION, rules.getVersion());
|
||||
rule.put(UcorePathUtil.TABLE_RULE, rules.getTableRule());
|
||||
rule.put(UcorePathUtil.FUNCTION, rules.getFunction());
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, rule.toJSONString());
|
||||
rule.put(ClusterPathUtil.VERSION, rules.getVersion());
|
||||
rule.put(ClusterPathUtil.TABLE_RULE, rules.getTableRule());
|
||||
rule.put(ClusterPathUtil.FUNCTION, rules.getFunction());
|
||||
ClusterHelper.setKV(CONFIG_PATH, rule.toJSONString());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.Schemas;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.schema.datahost.DataHost;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.schema.datanode.DataNode;
|
||||
@@ -31,9 +33,9 @@ import java.util.List;
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public class UXmlSchemaLoader implements UcoreXmlLoader {
|
||||
public class XmlSchemaLoader implements ClusterXmlLoader {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UXmlSchemaLoader.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(XmlSchemaLoader.class);
|
||||
|
||||
private ParseJsonServiceInf<List<Schema>> parseJsonSchema = new SchemaJsonParse();
|
||||
|
||||
@@ -45,36 +47,36 @@ public class UXmlSchemaLoader implements UcoreXmlLoader {
|
||||
|
||||
private static final String WRITEPATH = "schema.xml";
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getConfSchemaPath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getConfSchemaPath();
|
||||
|
||||
|
||||
public UXmlSchemaLoader(XmlProcessBase xmlParseBase, UcoreClearKeyListener confListener) {
|
||||
public XmlSchemaLoader(XmlProcessBase xmlParseBase, ClusterClearKeyListener confListener) {
|
||||
this.parseSchemaXmlService = new SchemasParseXmlImpl(xmlParseBase);
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.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());
|
||||
List<Schema> schemaList = parseJsonSchema.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.SCHEMA_SCHEMA).toJSONString());
|
||||
schema.setSchema(schemaList);
|
||||
|
||||
List<DataNode> dataNodeList = parseJsonDataNode.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.DATA_NODE).toJSONString());
|
||||
List<DataNode> dataNodeList = parseJsonDataNode.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.DATA_NODE).toJSONString());
|
||||
schema.setDataNode(dataNodeList);
|
||||
|
||||
List<DataHost> dataHostList = parseJsonDataHost.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.DATA_HOST).toJSONString());
|
||||
List<DataHost> dataHostList = parseJsonDataHost.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.DATA_HOST).toJSONString());
|
||||
schema.setDataHost(dataHostList);
|
||||
|
||||
schema.setVersion(jsonObj.getString(UcorePathUtil.VERSION));
|
||||
schema.setVersion(jsonObj.getString(ClusterPathUtil.VERSION));
|
||||
|
||||
String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
String path = ResourceUtil.getResourcePathFromRoot(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
path = new File(path).getPath() + File.separator;
|
||||
path += WRITEPATH;
|
||||
|
||||
@@ -88,13 +90,13 @@ public class UXmlSchemaLoader implements UcoreXmlLoader {
|
||||
|
||||
@Override
|
||||
public void notifyCluster() throws Exception {
|
||||
Schemas schema = this.parseSchemaXmlService.parseXmlToBean(UcorePathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
Schemas schema = this.parseSchemaXmlService.parseXmlToBean(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
JSONObject schemas = new JSONObject();
|
||||
schemas.put(UcorePathUtil.VERSION, schema.getVersion());
|
||||
schemas.put(UcorePathUtil.SCHEMA_SCHEMA, schema.getSchema());
|
||||
schemas.put(UcorePathUtil.DATA_NODE, schema.getDataNode());
|
||||
schemas.put(UcorePathUtil.DATA_HOST, schema.getDataHost());
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, schemas.toJSONString());
|
||||
schemas.put(ClusterPathUtil.VERSION, schema.getVersion());
|
||||
schemas.put(ClusterPathUtil.SCHEMA_SCHEMA, schema.getSchema());
|
||||
schemas.put(ClusterPathUtil.DATA_NODE, schema.getDataNode());
|
||||
schemas.put(ClusterPathUtil.DATA_HOST, schema.getDataHost());
|
||||
ClusterHelper.setKV(CONFIG_PATH, schemas.toJSONString());
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.loader;
|
||||
package com.actiontech.dble.cluster.response;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.Server;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.server.FireWall;
|
||||
import com.actiontech.dble.config.loader.zkprocess.entity.server.System;
|
||||
@@ -31,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public class UXmlServerLoader implements UcoreXmlLoader {
|
||||
public class XmlServerLoader implements ClusterXmlLoader {
|
||||
|
||||
private ParseXmlServiceInf<Server> parseServerXMl;
|
||||
|
||||
@@ -43,32 +45,32 @@ public class UXmlServerLoader implements UcoreXmlLoader {
|
||||
|
||||
private static final String WRITEPATH = "server.xml";
|
||||
|
||||
private static final String CONFIG_PATH = UcorePathUtil.getConfServerPath();
|
||||
private static final String CONFIG_PATH = ClusterPathUtil.getConfServerPath();
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UXmlServerLoader.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(XmlServerLoader.class);
|
||||
|
||||
public UXmlServerLoader(XmlProcessBase xmlParseBase, UcoreClearKeyListener confListener) {
|
||||
public XmlServerLoader(XmlProcessBase xmlParseBase, ClusterClearKeyListener confListener) {
|
||||
this.parseServerXMl = new ServerParseXmlImpl(xmlParseBase);
|
||||
confListener.addChild(this, CONFIG_PATH);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void notifyProcess(UKvBean configValue) throws Exception {
|
||||
public void notifyProcess(KvBean configValue) throws Exception {
|
||||
LOGGER.info("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
|
||||
UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
|
||||
if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
|
||||
KvBean lock = ClusterHelper.getKV(ClusterPathUtil.getConfChangeLockPath());
|
||||
if (ClusterGeneralConfig.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()));
|
||||
if (jsonObj.get(ClusterPathUtil.FIREWALL) != null) {
|
||||
server.setFirewall(parseJsonFireWall.parseJsonToBean(jsonObj.getJSONObject(ClusterPathUtil.FIREWALL).toJSONString()));
|
||||
}
|
||||
server.setVersion(jsonObj.getString(UcorePathUtil.VERSION));
|
||||
server.setSystem(parseJsonSystem.parseJsonToBean(jsonObj.getJSONObject(UcorePathUtil.DEFAULT).toJSONString()));
|
||||
server.setUser(parseJsonUser.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.USER).toJSONString()));
|
||||
String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
server.setVersion(jsonObj.getString(ClusterPathUtil.VERSION));
|
||||
server.setSystem(parseJsonSystem.parseJsonToBean(jsonObj.getJSONObject(ClusterPathUtil.DEFAULT).toJSONString()));
|
||||
server.setUser(parseJsonUser.parseJsonToBean(jsonObj.getJSONArray(ClusterPathUtil.USER).toJSONString()));
|
||||
String path = ResourceUtil.getResourcePathFromRoot(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH);
|
||||
path = new File(path).getPath() + File.separator;
|
||||
path += WRITEPATH;
|
||||
this.parseServerXMl.parseToXmlWrite(server, path, "server");
|
||||
@@ -76,13 +78,13 @@ public class UXmlServerLoader implements UcoreXmlLoader {
|
||||
|
||||
@Override
|
||||
public void notifyCluster() throws Exception {
|
||||
Server servers = this.parseServerXMl.parseXmlToBean(UcorePathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
Server servers = this.parseServerXMl.parseXmlToBean(ClusterPathUtil.UCORE_LOCAL_WRITE_PATH + WRITEPATH);
|
||||
JSONObject server = new JSONObject();
|
||||
server.put(UcorePathUtil.VERSION, servers.getVersion());
|
||||
server.put(UcorePathUtil.DEFAULT, servers.getSystem());
|
||||
server.put(UcorePathUtil.FIREWALL, servers.getFirewall());
|
||||
server.put(UcorePathUtil.USER, servers.getUser());
|
||||
ClusterUcoreSender.sendDataToUcore(CONFIG_PATH, server.toJSONString());
|
||||
server.put(ClusterPathUtil.VERSION, servers.getVersion());
|
||||
server.put(ClusterPathUtil.DEFAULT, servers.getSystem());
|
||||
server.put(ClusterPathUtil.FIREWALL, servers.getFirewall());
|
||||
server.put(ClusterPathUtil.USER, servers.getUser());
|
||||
ClusterHelper.setKV(CONFIG_PATH, server.toJSONString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,21 +3,21 @@
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
package com.actiontech.dble.cluster.xmltoKv;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterController;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.loader.*;
|
||||
import com.actiontech.dble.cluster.listener.ClusterClearKeyListener;
|
||||
import com.actiontech.dble.cluster.response.*;
|
||||
import com.actiontech.dble.config.loader.zkprocess.parse.XmlProcessBase;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/29.
|
||||
*/
|
||||
public final class XmltoUcore {
|
||||
public final class XmltoCluster {
|
||||
|
||||
|
||||
private XmltoUcore() {
|
||||
private XmltoCluster() {
|
||||
|
||||
}
|
||||
|
||||
@@ -28,21 +28,21 @@ public final class XmltoUcore {
|
||||
}
|
||||
|
||||
public static void initFileToUcore() throws Exception {
|
||||
UcoreClearKeyListener ucoreListen = new UcoreClearKeyListener();
|
||||
ClusterClearKeyListener ucoreListen = new ClusterClearKeyListener();
|
||||
|
||||
XmlProcessBase xmlProcess = new XmlProcessBase();
|
||||
|
||||
new UXmlRuleLoader(xmlProcess, ucoreListen);
|
||||
new XmlRuleLoader(xmlProcess, ucoreListen);
|
||||
|
||||
new UXmlServerLoader(xmlProcess, ucoreListen);
|
||||
new XmlServerLoader(xmlProcess, ucoreListen);
|
||||
|
||||
new UXmlSchemaLoader(xmlProcess, ucoreListen);
|
||||
new XmlSchemaLoader(xmlProcess, ucoreListen);
|
||||
|
||||
new UXmlEhcachesLoader(xmlProcess, ucoreListen);
|
||||
new XmlEhcachesLoader(xmlProcess, ucoreListen);
|
||||
|
||||
new UCacheserviceResponse(ucoreListen);
|
||||
new CacheserviceResponse(ucoreListen);
|
||||
|
||||
new UPropertySequenceLoader(ucoreListen);
|
||||
new PropertySequenceLoader(ucoreListen);
|
||||
|
||||
xmlProcess.initJaxbClass();
|
||||
ucoreListen.initAllNode();
|
||||
@@ -1,451 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
|
||||
import com.actiontech.dble.alarm.UcoreGrpc;
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.KVtoXml.UcoreToXml;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static com.actiontech.dble.cluster.ClusterController.GENERAL_GRPC_TIMEOUT;
|
||||
import static com.actiontech.dble.cluster.ClusterController.GRPC_SUBTIMEOUT;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public final class ClusterUcoreSender {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreXmlLoader.class);
|
||||
|
||||
private ClusterUcoreSender() {
|
||||
|
||||
}
|
||||
|
||||
private static volatile UcoreGrpc.UcoreBlockingStub stub = null;
|
||||
|
||||
{
|
||||
Channel channel = ManagedChannelBuilder.forAddress(UcoreConfig.getInstance().getIpList().get(0),
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public static void sendDataToUcore(String key, String value) throws Exception {
|
||||
UcoreInterface.PutKvInput input = UcoreInterface.PutKvInput.newBuilder().setKey(key).setValue(value).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).putKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).putKv(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String lockKey(String key, String value) throws Exception {
|
||||
UcoreInterface.LockOnSessionInput input = UcoreInterface.LockOnSessionInput.newBuilder().setKey(key).setValue(value).setTTLSeconds(30).build();
|
||||
UcoreInterface.LockOnSessionOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).lockOnSession(input);
|
||||
return output.getSessionId();
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).lockOnSession(input);
|
||||
return output.getSessionId();
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
static boolean renewLock(String sessionId) throws Exception {
|
||||
UcoreInterface.RenewSessionInput input = UcoreInterface.RenewSessionInput.newBuilder().setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).renewSession(input);
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
LOGGER.info("connect to ucore renew error and will retry");
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).renewSession(input);
|
||||
return true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore renew error " + stub, e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void unlockKey(String key, String sessionId) {
|
||||
UcoreInterface.UnlockOnSessionInput put = UcoreInterface.UnlockOnSessionInput.newBuilder().setKey(key).setSessionId(sessionId).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).unlockOnSession(put);
|
||||
} catch (Exception e) {
|
||||
LOGGER.info(sessionId + " unlockKey " + key + " error ," + stub, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UKvBean> getKeyTree(String key) {
|
||||
if (!(key.charAt(key.length() - 1) == '/')) {
|
||||
key = key + "/";
|
||||
}
|
||||
List<UKvBean> result = new ArrayList<UKvBean>();
|
||||
UcoreInterface.GetKvTreeInput input = UcoreInterface.GetKvTreeInput.newBuilder().setKey(key).build();
|
||||
|
||||
UcoreInterface.GetKvTreeOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < output.getKeysCount(); i++) {
|
||||
UKvBean bean = new UKvBean(output.getKeys(i), output.getValues(i), output.getIndex());
|
||||
result.add(bean);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static UKvBean getKey(String key) {
|
||||
UcoreInterface.GetKvInput input = UcoreInterface.GetKvInput.newBuilder().setKey(key).build();
|
||||
UcoreInterface.GetKvOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKv(input);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
UKvBean bean = new UKvBean(key, output.getValue(), 0);
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
public static int getKeyTreeSize(String key) {
|
||||
UcoreInterface.GetKvTreeInput input = UcoreInterface.GetKvTreeInput.newBuilder().setKey(key).build();
|
||||
UcoreInterface.GetKvTreeOutput output = null;
|
||||
|
||||
try {
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
output = stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).getKvTree(input);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output == null) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
return output.getKeysCount();
|
||||
}
|
||||
|
||||
public static void deleteKVTree(String key) {
|
||||
if (!(key.charAt(key.length() - 1) == '/')) {
|
||||
key = key + "/";
|
||||
}
|
||||
UcoreInterface.DeleteKvTreeInput input = UcoreInterface.DeleteKvTreeInput.newBuilder().setKey(key).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKvTree(input);
|
||||
} catch (Exception e1) {
|
||||
boolean flag = false;
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKvTree(input);
|
||||
flag = true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
deleteKV(key.substring(0, key.length() - 1));
|
||||
}
|
||||
|
||||
public static void deleteKV(String key) {
|
||||
UcoreInterface.DeleteKvInput input = UcoreInterface.DeleteKvInput.newBuilder().setKey(key).build();
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKv(input);
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).deleteKv(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("ALL the ucore connect failure");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static UcoreInterface.SubscribeKvPrefixOutput subscribeKvPrefix(UcoreInterface.SubscribeKvPrefixInput input) throws IOException {
|
||||
try {
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeKvPrefix(input);
|
||||
return output;
|
||||
} catch (Exception e1) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS);
|
||||
UcoreInterface.SubscribeKvPrefixOutput output = stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeKvPrefix(input);
|
||||
return output;
|
||||
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("connect to ucore at " + ip + " failure", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
|
||||
public static UcoreInterface.SubscribeNodesOutput subscribeNodes(UcoreInterface.SubscribeNodesInput subscribeNodesInput) throws IOException {
|
||||
try {
|
||||
return stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeNodes(subscribeNodesInput);
|
||||
} catch (Exception e) {
|
||||
//the first try failure ,try for all the other ucore ip
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip,
|
||||
Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS);
|
||||
return stub.withDeadlineAfter(GRPC_SUBTIMEOUT, TimeUnit.SECONDS).subscribeNodes(subscribeNodesInput);
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("try connection IP " + ip + " failure ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IOException("ALL the ucore connect failure");
|
||||
}
|
||||
|
||||
|
||||
public static void alert(UcoreInterface.AlertInput input) {
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alert(input);
|
||||
} catch (Exception e) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip, Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alert(input);
|
||||
return;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("alert to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean alertResolve(UcoreInterface.AlertInput input) {
|
||||
try {
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alertResolve(input);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
for (String ip : UcoreConfig.getInstance().getIpList()) {
|
||||
ManagedChannel channel = null;
|
||||
try {
|
||||
channel = ManagedChannelBuilder.forAddress(ip, Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
|
||||
stub = UcoreGrpc.newBlockingStub(channel).withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS);
|
||||
stub.withDeadlineAfter(GENERAL_GRPC_TIMEOUT, TimeUnit.SECONDS).alertResolve(input);
|
||||
return true;
|
||||
} catch (Exception e2) {
|
||||
LOGGER.info("alertResolve to ucore error ", e2);
|
||||
if (channel != null) {
|
||||
channel.shutdownNow();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String waitingForAllTheNode(String checkString, String path) {
|
||||
Map<String, String> expectedMap = UcoreToXml.getOnlineMap();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
for (; ; ) {
|
||||
errorMsg.setLength(0);
|
||||
if (checkResponseForOneTime(checkString, path, expectedMap, errorMsg)) {
|
||||
break;
|
||||
}
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(50));
|
||||
}
|
||||
return errorMsg.length() <= 0 ? null : errorMsg.toString();
|
||||
}
|
||||
|
||||
|
||||
public static boolean checkResponseForOneTime(String checkString, String path, Map<String, String> expectedMap, StringBuffer errorMsg) {
|
||||
Map<String, String> currentMap = UcoreToXml.getOnlineMap();
|
||||
checkOnline(expectedMap, currentMap);
|
||||
List<UKvBean> responseList = ClusterUcoreSender.getKeyTree(path);
|
||||
boolean flag = false;
|
||||
for (Map.Entry<String, String> entry : expectedMap.entrySet()) {
|
||||
flag = false;
|
||||
for (UKvBean uKvBean : responseList) {
|
||||
String responseNode = last(uKvBean.getKey().split("/"));
|
||||
if (last(entry.getKey().split("/")).
|
||||
equals(responseNode)) {
|
||||
if (checkString != null) {
|
||||
if (!checkString.equals(uKvBean.getValue())) {
|
||||
if (errorMsg != null) {
|
||||
errorMsg.append(responseNode).append(":").append(uKvBean.getValue()).append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
||||
public static void checkOnline(Map<String, String> expectedMap, Map<String, String> currentMap) {
|
||||
Iterator<Map.Entry<String, String>> iterator = expectedMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
if (!currentMap.containsKey(entry.getKey()) ||
|
||||
(currentMap.containsKey(entry.getKey()) && !currentMap.get(entry.getKey()).equals(entry.getValue()))) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : currentMap.entrySet()) {
|
||||
if (!expectedMap.containsKey(entry.getKey())) {
|
||||
LOGGER.warn("NODE " + entry.getKey() + " IS NOT EXPECTED TO BE ONLINE,PLEASE CHECK IT ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T last(T[] array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.KVtoXml;
|
||||
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UOffLineListener;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreClearKeyListener;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreNodesListener;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreSingleKeyListener;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.loader.*;
|
||||
import com.actiontech.dble.config.loader.zkprocess.parse.XmlProcessBase;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/24.
|
||||
*/
|
||||
public final class UcoreToXml {
|
||||
|
||||
private static UcoreClearKeyListener listener = null;
|
||||
|
||||
private static UcoreSingleKeyListener ddlListener = null;
|
||||
|
||||
private static UcoreSingleKeyListener viewListener = null;
|
||||
|
||||
private static UOffLineListener onlineListener = null;
|
||||
|
||||
private static UcoreNodesListener ucoreNodesListener = null;
|
||||
|
||||
private UcoreToXml() {
|
||||
|
||||
}
|
||||
|
||||
public static void loadKVtoFile() {
|
||||
try {
|
||||
//create a new listener to the ucore config change
|
||||
listener = new UcoreClearKeyListener();
|
||||
XmlProcessBase xmlProcess = new XmlProcessBase();
|
||||
//add all loader into listener map list
|
||||
new UXmlRuleLoader(xmlProcess, listener);
|
||||
new UXmlSchemaLoader(xmlProcess, listener);
|
||||
new UXmlServerLoader(xmlProcess, listener);
|
||||
new UXmlEhcachesLoader(xmlProcess, listener);
|
||||
new UCacheserviceResponse(listener);
|
||||
new UPropertySequenceLoader(listener);
|
||||
xmlProcess.initJaxbClass();
|
||||
|
||||
//add listener to watch the Prefix of the keys
|
||||
new UConfigStatusResponse(listener);
|
||||
new UBinlogPauseStatusResponse(listener);
|
||||
new UPauseDataNodeResponse(listener);
|
||||
|
||||
|
||||
ddlListener = new UcoreSingleKeyListener(UcorePathUtil.getDDLPath() + SEPARATOR, new UDdlChildResponse());
|
||||
|
||||
viewListener = new UcoreSingleKeyListener(UcorePathUtil.getViewChangePath() + SEPARATOR, new UViewChildResponse());
|
||||
|
||||
onlineListener = new UOffLineListener();
|
||||
|
||||
ucoreNodesListener = new UcoreNodesListener();
|
||||
|
||||
listener.initForXml();
|
||||
Thread thread = new Thread(listener);
|
||||
thread.setName("UCORE_KEY_LISTENER");
|
||||
thread.start();
|
||||
|
||||
Thread thread2 = new Thread(ddlListener);
|
||||
thread2.setName("DDL_UCORE_LISTENER");
|
||||
thread2.start();
|
||||
|
||||
Thread thread3 = new Thread(viewListener);
|
||||
thread3.setName("VIEW_UCORE_LISTENER");
|
||||
thread3.start();
|
||||
|
||||
Thread thread4 = new Thread(onlineListener);
|
||||
thread4.setName("ONLINE_UCORE_LISTENER");
|
||||
thread4.start();
|
||||
|
||||
Thread thread5 = new Thread(ucoreNodesListener);
|
||||
thread5.setName("NODES_UCORE_LISTENER");
|
||||
thread5.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static UcoreClearKeyListener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public static Map<String, String> getOnlineMap() {
|
||||
return onlineListener.copyOnlineMap();
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/31.
|
||||
*/
|
||||
public class UDistributeLock {
|
||||
|
||||
protected static final Logger LOGGER = LoggerFactory.getLogger(UDistributeLock.class);
|
||||
private final int maxErrorCnt;
|
||||
private int errorCount = 0;
|
||||
private String path;
|
||||
private String value;
|
||||
private String session;
|
||||
|
||||
private Thread renewThread;
|
||||
|
||||
public UDistributeLock(String path, String value) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.maxErrorCnt = 3;
|
||||
}
|
||||
|
||||
public UDistributeLock(String path, String value, int maxErrorCnt) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.maxErrorCnt = maxErrorCnt;
|
||||
}
|
||||
|
||||
|
||||
public void release() {
|
||||
if (renewThread != null) {
|
||||
renewThread.interrupt();
|
||||
}
|
||||
if (session != null) {
|
||||
ClusterUcoreSender.unlockKey(path, session);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean acquire() {
|
||||
try {
|
||||
String sessionId = ClusterUcoreSender.lockKey(this.path, value);
|
||||
if ("".equals(sessionId)) {
|
||||
errorCount++;
|
||||
if (errorCount == maxErrorCnt) {
|
||||
throw new RuntimeException(" get lock from ucore error,ucore maybe offline ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
session = sessionId;
|
||||
errorCount = 0;
|
||||
renewThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String sessionId = session;
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
LOGGER.debug("renew lock of session start:" + sessionId + " " + path);
|
||||
if ("".equals(ClusterUcoreSender.getKey(path).getValue())) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path + ", the key is missing ");
|
||||
// alert
|
||||
renewThread.interrupt();
|
||||
} else if (!ClusterUcoreSender.renewLock(sessionId)) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path);
|
||||
// alert
|
||||
} else {
|
||||
LOGGER.debug("renew lock of session success:" + sessionId + " " + path);
|
||||
}
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10000));
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("renew lock of session failure:" + sessionId + " " + path, e);
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(5000));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
renewThread.setName("UCORE_RENEW_" + path);
|
||||
renewThread.start();
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(" get lock from ucore error", e);
|
||||
errorCount++;
|
||||
if (errorCount == maxErrorCnt) {
|
||||
throw new RuntimeException(" get lock from ucore error,ucore maybe offline ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.KVtoXml.UcoreToXml;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.listen.UcoreNodesListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.actiontech.dble.cluster.ClusterController.CONFIG_FILE_NAME;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/24.
|
||||
*/
|
||||
public final class UcoreConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreConfig.class);
|
||||
private static UcoreConfig instance = new UcoreConfig();
|
||||
|
||||
|
||||
private List<String> ipList = new ArrayList<>();
|
||||
|
||||
private Properties ucoreProperties = null;
|
||||
|
||||
private UcoreConfig() {
|
||||
|
||||
}
|
||||
|
||||
public static UcoreConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getValue(ClusterParamCfg param) {
|
||||
if (ucoreProperties != null && null != param) {
|
||||
return ucoreProperties.getProperty(param.getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the ucore and set keys
|
||||
*
|
||||
* @param cluterProperties
|
||||
*/
|
||||
public static void initUcore(Properties cluterProperties) {
|
||||
try {
|
||||
getInstance().ucoreProperties = cluterProperties;
|
||||
for (String ip : cluterProperties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey()).split(",")) {
|
||||
getInstance().ipList.add(ip);
|
||||
}
|
||||
UcoreToXml.loadKVtoFile();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the ucore and set keys
|
||||
*
|
||||
* @param cluterProperties
|
||||
*/
|
||||
public static void initUcoreFromShell(Properties cluterProperties) {
|
||||
try {
|
||||
getInstance().ucoreProperties = cluterProperties;
|
||||
for (String ip : cluterProperties.getProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey()).split(",")) {
|
||||
getInstance().ipList.add(ip);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setUcoreProperties(Properties ucoreProperties) {
|
||||
getInstance().ucoreProperties = ucoreProperties;
|
||||
}
|
||||
|
||||
public void setIpList(List<String> ipList) {
|
||||
this.ipList = ipList;
|
||||
}
|
||||
|
||||
public void setIp(String ips) {
|
||||
getInstance().ucoreProperties.setProperty(ClusterParamCfg.CLUSTER_PLUGINS_IP.getKey(), ips);
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
File file = new File(UcoreNodesListener.class.getResource(CONFIG_FILE_NAME).getFile());
|
||||
out = new FileOutputStream(file);
|
||||
getInstance().ucoreProperties.store(out, "");
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("ips set to ucore failure");
|
||||
} finally {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("open file error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getIpList() {
|
||||
return ipList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess;
|
||||
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/1/26.
|
||||
*/
|
||||
public interface UcoreXmlLoader {
|
||||
|
||||
void notifyProcess(UKvBean configValue) throws Exception;
|
||||
|
||||
void notifyCluster() throws Exception;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 ActionTech.
|
||||
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
|
||||
*/
|
||||
|
||||
package com.actiontech.dble.config.loader.ucoreprocess.listen;
|
||||
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.alarm.UcoreInterface;
|
||||
import com.actiontech.dble.backend.mysql.view.CKVStoreRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.FileSystemRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.Repository;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.server.status.OnlineLockStatus;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Created by szf on 2018/4/27.
|
||||
*/
|
||||
public class UcoreNodesListener implements Runnable {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UcoreNodesListener.class);
|
||||
private long index = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (; ; ) {
|
||||
try {
|
||||
UcoreInterface.SubscribeNodesInput subscribeNodesInput = UcoreInterface.SubscribeNodesInput.newBuilder().
|
||||
setDuration(60).setIndex(index).build();
|
||||
UcoreInterface.SubscribeNodesOutput output = ClusterUcoreSender.subscribeNodes(subscribeNodesInput);
|
||||
if (index != output.getIndex()) {
|
||||
index = output.getIndex();
|
||||
List<String> ips = new ArrayList<>();
|
||||
for (int i = 0; i < output.getIpsList().size(); i++) {
|
||||
ips.add(output.getIps(i));
|
||||
}
|
||||
UcoreConfig.getInstance().setIpList(ips);
|
||||
UcoreConfig.getInstance().setIp(StringUtils.join(ips, ','));
|
||||
}
|
||||
|
||||
if (DbleServer.getInstance().getTmManager().getRepository() instanceof FileSystemRepository) {
|
||||
LOGGER.warn("Dble first reconnect to ucore ,local view repository change to CKVStoreRepository");
|
||||
Repository newViewRepository = new CKVStoreRepository();
|
||||
DbleServer.getInstance().getTmManager().setRepository(newViewRepository);
|
||||
Map<String, Map<String, String>> viewCreateSqlMap = newViewRepository.getViewCreateSqlMap();
|
||||
DbleServer.getInstance().getTmManager().reloadViewMeta(viewCreateSqlMap);
|
||||
//init online status
|
||||
LOGGER.warn("Dble first reconnect to ucore ,online status rebuild");
|
||||
OnlineLockStatus.getInstance().metaUcoreInit(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("error in ucore nodes watch,try for another time");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ package com.actiontech.dble.manager.response;
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDBNode;
|
||||
import com.actiontech.dble.backend.mysql.PacketUtil;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.*;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.config.model.SchemaConfig;
|
||||
import com.actiontech.dble.config.model.TableConfig;
|
||||
import com.actiontech.dble.config.model.UserConfig;
|
||||
@@ -115,7 +115,7 @@ public final class DryRun {
|
||||
|
||||
userCheck(list, serverConfig);
|
||||
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
ucoreConnectionTest(list);
|
||||
} else {
|
||||
list.add(new ErrorInfo("Cluster", "NOTICE", "Dble is in single mod"));
|
||||
@@ -127,9 +127,9 @@ public final class DryRun {
|
||||
|
||||
private static void ucoreConnectionTest(List<ErrorInfo> list) {
|
||||
try {
|
||||
String serverId = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
String selfPath = UcorePathUtil.getOnlinePath(serverId);
|
||||
ClusterUcoreSender.getKey(selfPath);
|
||||
String serverId = ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
|
||||
String selfPath = ClusterPathUtil.getOnlinePath(serverId);
|
||||
ClusterHelper.getKV(selfPath);
|
||||
} catch (Exception e) {
|
||||
list.add(new ErrorInfo("Cluster", "ERROR", "Dble in cluster but all the ucore can't connect"));
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ package com.actiontech.dble.manager.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UDistrbtLockManager;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.cluster.DistrbtLockManager;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.manager.ManagerConnection;
|
||||
import com.actiontech.dble.net.mysql.OkPacket;
|
||||
import com.actiontech.dble.util.StringUtil;
|
||||
@@ -37,8 +37,8 @@ public final class KillDdlLock {
|
||||
String schema = matcher.group(2);
|
||||
String table = matcher.group(4);
|
||||
// release distributed lock
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
UDistrbtLockManager.releaseLock(UcorePathUtil.getDDLPath(StringUtil.getUFullName(schema, table)));
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
DistrbtLockManager.releaseLock(ClusterPathUtil.getDDLPath(StringUtil.getUFullName(schema, table)));
|
||||
}
|
||||
boolean isRemoved = DbleServer.getInstance().getTmManager().removeMetaLock(schema, table);
|
||||
OkPacket packet = new OkPacket();
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
package com.actiontech.dble.manager.response;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.cluster.ClusterGeneralConfig;
|
||||
import com.actiontech.dble.cluster.ClusterHelper;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.cluster.bean.KvBean;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.PauseInfo;
|
||||
import com.actiontech.dble.manager.ManagerConnection;
|
||||
import com.actiontech.dble.net.mysql.OkPacket;
|
||||
@@ -44,11 +44,11 @@ public final class PauseEnd {
|
||||
|
||||
public static void resume(ManagerConnection c) {
|
||||
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
try {
|
||||
UKvBean value = ClusterUcoreSender.getKey(UcorePathUtil.getPauseDataNodePath());
|
||||
KvBean value = ClusterHelper.getKV(ClusterPathUtil.getPauseDataNodePath());
|
||||
PauseInfo pauseInfo = new PauseInfo(value.getValue());
|
||||
if (!pauseInfo.getFrom().equals(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
if (!pauseInfo.getFrom().equals(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
|
||||
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "This node is not the node which start pause");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ import com.actiontech.dble.backend.datasource.PhysicalDBPoolDiff;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDatasource;
|
||||
import com.actiontech.dble.backend.mysql.nio.MySQLConnection;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.cluster.xmltoKv.XmltoCluster;
|
||||
import com.actiontech.dble.config.ConfigInitializer;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.ServerConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.xmltozk.XmltoZkMain;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zktoxml.listen.ConfigStatusListener;
|
||||
@@ -50,7 +50,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
|
||||
/**
|
||||
* @author mycat
|
||||
@@ -99,21 +99,21 @@ public final class ReloadConfig {
|
||||
LOGGER.info("reload config using ZK failure", e);
|
||||
writeErrorResult(c, e.getMessage() == null ? e.toString() : e.getMessage());
|
||||
}
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
UDistributeLock distributeLock = new UDistributeLock(UcorePathUtil.getConfChangeLockPath(),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
DistributeLock distributeLock = new DistributeLock(ClusterPathUtil.getConfChangeLockPath(),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
try {
|
||||
if (!distributeLock.acquire()) {
|
||||
c.writeErrMessage(ErrorCode.ER_YES, "Other instance is reloading/rolling back, please try again later.");
|
||||
return;
|
||||
}
|
||||
LOGGER.info("reload config: added distributeLock " + UcorePathUtil.getConfChangeLockPath() + " to ucore");
|
||||
LOGGER.info("reload config: added distributeLock " + ClusterPathUtil.getConfChangeLockPath() + " to ucore");
|
||||
ClusterDelayProvider.delayAfterReloadLock();
|
||||
try {
|
||||
reloadWithUcore(loadAll, loadAllMode, c);
|
||||
} finally {
|
||||
distributeLock.release();
|
||||
LOGGER.info("reload config: release distributeLock " + UcorePathUtil.getConfChangeLockPath() + " from ucore");
|
||||
LOGGER.info("reload config: release distributeLock " + ClusterPathUtil.getConfChangeLockPath() + " from ucore");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("reload config failure using ucore", e);
|
||||
@@ -155,23 +155,23 @@ public final class ReloadConfig {
|
||||
ClusterDelayProvider.delayAfterMasterLoad();
|
||||
|
||||
//step 3 if the reload with no error ,than write the config file into ucore remote
|
||||
XmltoUcore.initFileToUcore();
|
||||
XmltoCluster.initFileToUcore();
|
||||
LOGGER.info("reload config: sent config file to ucore");
|
||||
//step 4 write the reload flag and self reload result into ucore,notify the other dble to reload
|
||||
ConfStatus status = new ConfStatus(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID),
|
||||
ConfStatus status = new ConfStatus(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID),
|
||||
loadAll ? ConfStatus.Status.RELOAD_ALL : ConfStatus.Status.RELOAD,
|
||||
loadAll ? String.valueOf(loadAllMode) : null);
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getConfStatusPath(), status.toString());
|
||||
ClusterHelper.setKV(ClusterPathUtil.getConfStatusPath(), status.toString());
|
||||
LOGGER.info("reload config: sent config status to ucore");
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), ClusterPathUtil.SUCCESS);
|
||||
LOGGER.info("reload config: sent finished status to ucore, waiting other instances");
|
||||
//step 5 start a loop to check if all the dble in cluster is reload finished
|
||||
|
||||
final String errorMsg = ClusterUcoreSender.waitingForAllTheNode(UcorePathUtil.SUCCESS, UcorePathUtil.getConfStatusPath() + SEPARATOR);
|
||||
final String errorMsg = ClusterHelper.waitingForAllTheNode(ClusterPathUtil.SUCCESS, ClusterPathUtil.getConfStatusPath() + SEPARATOR);
|
||||
LOGGER.info("reload config: all instances finished ");
|
||||
ClusterDelayProvider.delayBeforeDeleteReloadLock();
|
||||
//step 6 delete the reload flag
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getConfStatusPath() + SEPARATOR);
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getConfStatusPath() + SEPARATOR);
|
||||
|
||||
if (errorMsg != null) {
|
||||
writeErrorResultForCluster(c, errorMsg);
|
||||
@@ -354,8 +354,6 @@ public final class ReloadConfig {
|
||||
/* 2.2 init the dataSource with diff*/
|
||||
|
||||
|
||||
|
||||
|
||||
LOGGER.info("reload config: init new data host start");
|
||||
|
||||
boolean mergeReload = true;
|
||||
|
||||
@@ -9,10 +9,9 @@ import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDBNode;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDBPool;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.ServerConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.xmltozk.XmltoZkMain;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus;
|
||||
@@ -37,7 +36,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
|
||||
|
||||
/**
|
||||
@@ -68,9 +67,9 @@ public final class RollbackConfig {
|
||||
LOGGER.info("reload config failure", e);
|
||||
writeErrorResult(c, e.getMessage() == null ? e.toString() : e.getMessage());
|
||||
}
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
UDistributeLock distributeLock = new UDistributeLock(UcorePathUtil.getConfChangeLockPath(),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
DistributeLock distributeLock = new DistributeLock(ClusterPathUtil.getConfChangeLockPath(),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
try {
|
||||
|
||||
if (!distributeLock.acquire()) {
|
||||
@@ -113,18 +112,18 @@ public final class RollbackConfig {
|
||||
ClusterDelayProvider.delayAfterMasterRollback();
|
||||
|
||||
//step 3 tail the ucore & notify the other dble
|
||||
ConfStatus status = new ConfStatus(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ConfStatus.Status.ROLLBACK, null);
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getConfStatusPath(), status.toString());
|
||||
ConfStatus status = new ConfStatus(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ConfStatus.Status.ROLLBACK, null);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getConfStatusPath(), status.toString());
|
||||
|
||||
//step 4 set self status success
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getSelfConfStatusPath(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getSelfConfStatusPath(), ClusterPathUtil.SUCCESS);
|
||||
|
||||
|
||||
String errorMsg = ClusterUcoreSender.waitingForAllTheNode(UcorePathUtil.SUCCESS, UcorePathUtil.getConfStatusPath() + SEPARATOR);
|
||||
String errorMsg = ClusterHelper.waitingForAllTheNode(ClusterPathUtil.SUCCESS, ClusterPathUtil.getConfStatusPath() + SEPARATOR);
|
||||
|
||||
ClusterDelayProvider.delayBeforeDeleterollbackLock();
|
||||
//step 6 delete the reload flag
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getConfStatusPath());
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getConfStatusPath());
|
||||
|
||||
if (errorMsg != null) {
|
||||
throw new RuntimeException(errorMsg);
|
||||
|
||||
@@ -9,14 +9,11 @@ import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDBPool;
|
||||
import com.actiontech.dble.backend.datasource.PhysicalDatasource;
|
||||
import com.actiontech.dble.backend.mysql.PacketUtil;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.Fields;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.KVtoXml.UcoreToXml;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.cluster.kVtoXml.ClusterToXml;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause;
|
||||
import com.actiontech.dble.manager.ManagerConnection;
|
||||
@@ -50,7 +47,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.cluster.ClusterPathUtil.SEPARATOR;
|
||||
import static com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause.BinlogPauseStatus;
|
||||
|
||||
public final class ShowBinlogStatus {
|
||||
@@ -87,7 +84,7 @@ public final class ShowBinlogStatus {
|
||||
long timeout = DbleServer.getInstance().getConfig().getSystem().getShowBinlogStatusTimeout();
|
||||
if (isUseZK) {
|
||||
showBinlogWithZK(c, timeout);
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
showBinlogWithUcore(c, timeout);
|
||||
} else {
|
||||
if (!DbleServer.getInstance().getBackupLocked().compareAndSet(false, true)) {
|
||||
@@ -110,7 +107,7 @@ public final class ShowBinlogStatus {
|
||||
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));
|
||||
DistributeLock distributeLock = new DistributeLock(ClusterPathUtil.getBinlogPauseLockPath(), ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
try {
|
||||
if (!distributeLock.acquire()) {
|
||||
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "There is another command is showing BinlogStatus");
|
||||
@@ -122,7 +119,7 @@ public final class ShowBinlogStatus {
|
||||
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);
|
||||
BinlogPause pauseOnInfo = new BinlogPause(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.ON);
|
||||
|
||||
//step 4 wait til other dbles to feedback the ucore flag
|
||||
long beginTime = TimeUtil.currentTimeMillis();
|
||||
@@ -131,13 +128,13 @@ public final class ShowBinlogStatus {
|
||||
writeResponse(c);
|
||||
return;
|
||||
}
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatus(), pauseOnInfo.toString());
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getBinlogPauseStatusSelf(), UcorePathUtil.SUCCESS);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatus(), pauseOnInfo.toString());
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatusSelf(), ClusterPathUtil.SUCCESS);
|
||||
|
||||
Map<String, String> expectedMap = UcoreToXml.getOnlineMap();
|
||||
Map<String, String> expectedMap = ClusterToXml.getOnlineMap();
|
||||
while (true) {
|
||||
StringBuffer errorStringBuf = new StringBuffer();
|
||||
if (ClusterUcoreSender.checkResponseForOneTime(UcorePathUtil.SUCCESS, UcorePathUtil.getBinlogPauseStatus(), expectedMap, errorStringBuf)) {
|
||||
if (ClusterHelper.checkResponseForOneTime(ClusterPathUtil.SUCCESS, ClusterPathUtil.getBinlogPauseStatus(), expectedMap, errorStringBuf)) {
|
||||
errMsg = errorStringBuf.length() <= 0 ? null : errorStringBuf.toString();
|
||||
break;
|
||||
} else if (TimeUtil.currentTimeMillis() > beginTime + 2 * timeout) {
|
||||
@@ -154,9 +151,9 @@ public final class ShowBinlogStatus {
|
||||
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());
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getBinlogPauseStatus() + SEPARATOR);
|
||||
BinlogPause pauseOffInfo = new BinlogPause(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), BinlogPauseStatus.OFF);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getBinlogPauseStatus(), pauseOffInfo.toString());
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -6,12 +6,9 @@ package com.actiontech.dble.meta;
|
||||
|
||||
import com.actiontech.dble.DbleServer;
|
||||
import com.actiontech.dble.backend.BackendConnection;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.KVtoXml.UcoreToXml;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.cluster.kVtoXml.ClusterToXml;
|
||||
import com.actiontech.dble.cluster.ClusterPathUtil;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.PauseInfo;
|
||||
import com.actiontech.dble.config.model.SchemaConfig;
|
||||
import com.actiontech.dble.config.model.TableConfig;
|
||||
@@ -44,7 +41,7 @@ public class PauseDatanodeManager {
|
||||
private volatile Set<String> dataNodes = null;
|
||||
private Map<String, Set<String>> pauseMap = new ConcurrentHashMap<>();
|
||||
private AtomicBoolean isPausing = new AtomicBoolean(false);
|
||||
private UDistributeLock uDistributeLock = null;
|
||||
private DistributeLock uDistributeLock = null;
|
||||
|
||||
private volatile PauseEndThreadPool pauseThreadPool = null;
|
||||
|
||||
@@ -185,16 +182,16 @@ public class PauseDatanodeManager {
|
||||
|
||||
|
||||
public boolean clusterPauseNotic(String dataNode, int timeOut, int queueLimit) {
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
try {
|
||||
uDistributeLock = new UDistributeLock(UcorePathUtil.getPauseDataNodePath(),
|
||||
new PauseInfo(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), dataNode, PAUSE, timeOut, queueLimit).toString());
|
||||
uDistributeLock = new DistributeLock(ClusterPathUtil.getPauseDataNodePath(),
|
||||
new PauseInfo(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), dataNode, PAUSE, timeOut, queueLimit).toString());
|
||||
if (!uDistributeLock.acquire()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getPauseResultNodePath(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
ClusterHelper.setKV(ClusterPathUtil.getPauseResultNodePath(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("ucore connecction error", e);
|
||||
return false;
|
||||
@@ -206,10 +203,10 @@ public class PauseDatanodeManager {
|
||||
|
||||
public boolean waitForCluster(ManagerConnection c, long beginTime, long timeOut) throws Exception {
|
||||
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
Map<String, String> expectedMap = UcoreToXml.getOnlineMap();
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
Map<String, String> expectedMap = ClusterToXml.getOnlineMap();
|
||||
for (; ; ) {
|
||||
if (ClusterUcoreSender.checkResponseForOneTime(null, UcorePathUtil.getPauseResultNodePath(), expectedMap, null)) {
|
||||
if (ClusterHelper.checkResponseForOneTime(null, ClusterPathUtil.getPauseResultNodePath(), expectedMap, null)) {
|
||||
return true;
|
||||
} else if (System.currentTimeMillis() - beginTime > timeOut) {
|
||||
DbleServer.getInstance().getMiManager().resume();
|
||||
@@ -224,24 +221,24 @@ public class PauseDatanodeManager {
|
||||
|
||||
|
||||
public void resumeCluster() throws Exception {
|
||||
if (DbleServer.getInstance().isUseUcore()) {
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getPauseResumePath(),
|
||||
new PauseInfo(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), " ", PauseInfo.RESUME, 0, 0).toString());
|
||||
if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
ClusterHelper.setKV(ClusterPathUtil.getPauseResumePath(),
|
||||
new PauseInfo(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), " ", PauseInfo.RESUME, 0, 0).toString());
|
||||
|
||||
//send self reponse
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getPauseResumePath(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
ClusterHelper.setKV(ClusterPathUtil.getPauseResumePath(ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID));
|
||||
|
||||
ClusterUcoreSender.waitingForAllTheNode(null, UcorePathUtil.getPauseResumePath());
|
||||
ClusterHelper.waitingForAllTheNode(null, ClusterPathUtil.getPauseResumePath());
|
||||
|
||||
|
||||
DbleServer.getInstance().getMiManager().getuDistributeLock().release();
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getPauseDataNodePath());
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getPauseDataNodePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private UDistributeLock getuDistributeLock() {
|
||||
private DistributeLock getuDistributeLock() {
|
||||
return uDistributeLock;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,9 @@ import com.actiontech.dble.backend.mysql.view.FileSystemRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.KVStoreRepository;
|
||||
import com.actiontech.dble.backend.mysql.view.Repository;
|
||||
import com.actiontech.dble.btrace.provider.ClusterDelayProvider;
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.config.ErrorCode;
|
||||
import com.actiontech.dble.config.ServerConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.*;
|
||||
import com.actiontech.dble.config.loader.zkprocess.comm.ZkConfig;
|
||||
import com.actiontech.dble.config.loader.zkprocess.zookeeper.process.DDLInfo;
|
||||
import com.actiontech.dble.config.model.DBHostConfig;
|
||||
@@ -410,7 +409,7 @@ public class ProxyMetaManager {
|
||||
handler.execute();
|
||||
if (DbleServer.getInstance().isUseZK()) {
|
||||
loadViewFromKV();
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
loadViewFromCKV();
|
||||
} else {
|
||||
loadViewFromFile();
|
||||
@@ -496,19 +495,18 @@ public class ProxyMetaManager {
|
||||
String nodePath = ZKPaths.makePath(KVPathUtil.getDDLPath(), nodeName);
|
||||
zkConn.create().forPath(nodePath, ddlInfo.toString().getBytes(StandardCharsets.UTF_8));
|
||||
ClusterDelayProvider.delayAfterDdlLockMeta();
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
DDLInfo ddlInfo = new DDLInfo(schema, sql, UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), DDLInfo.DDLStatus.INIT, DDLInfo.DDLType.UNKNOWN);
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
DDLInfo ddlInfo = new DDLInfo(schema, sql, ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), DDLInfo.DDLStatus.INIT, DDLInfo.DDLType.UNKNOWN);
|
||||
String nodeName = StringUtil.getUFullName(schema, table);
|
||||
String ddlPath = UcorePathUtil.getDDLPath(nodeName);
|
||||
UDistributeLock lock = new UDistributeLock(ddlPath, ddlInfo.toString());
|
||||
//ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLPath(nodeName), ddlInfo.toString());
|
||||
String ddlPath = ClusterPathUtil.getDDLPath(nodeName);
|
||||
DistributeLock lock = new DistributeLock(ddlPath, ddlInfo.toString());
|
||||
if (!lock.acquire()) {
|
||||
String msg = "The syncMeta.lock or metaLock about " + nodeName + " in " + ddlPath + "is Exists";
|
||||
LOGGER.info(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
ClusterDelayProvider.delayAfterDdlLockMeta();
|
||||
UDistrbtLockManager.addLock(lock);
|
||||
DistrbtLockManager.addLock(lock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,7 +515,7 @@ public class ProxyMetaManager {
|
||||
ClusterDelayProvider.delayAfterDdlExecuted();
|
||||
if (DbleServer.getInstance().isUseZK()) {
|
||||
notifyResponseZKDdl(schema, table, sql, ddlStatus, ddlType, needNotifyOther);
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
notifyReponseUcoreDDL(schema, table, sql, ddlStatus, ddlType, needNotifyOther);
|
||||
}
|
||||
}
|
||||
@@ -560,15 +558,15 @@ public class ProxyMetaManager {
|
||||
*/
|
||||
public void notifyReponseUcoreDDL(String schema, String table, String sql, DDLInfo.DDLStatus ddlStatus, DDLInfo.DDLType ddlType, boolean needNotifyOther) throws Exception {
|
||||
String nodeName = StringUtil.getUFullName(schema, table);
|
||||
DDLInfo ddlInfo = new DDLInfo(schema, sql, UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus, ddlType);
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLInstancePath(nodeName), UcorePathUtil.SUCCESS);
|
||||
DDLInfo ddlInfo = new DDLInfo(schema, sql, ClusterGeneralConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), ddlStatus, ddlType);
|
||||
ClusterHelper.setKV(ClusterPathUtil.getDDLInstancePath(nodeName), ClusterPathUtil.SUCCESS);
|
||||
if (needNotifyOther) {
|
||||
try {
|
||||
ClusterDelayProvider.delayBeforeDdlNotice();
|
||||
ClusterUcoreSender.sendDataToUcore(UcorePathUtil.getDDLPath(nodeName), ddlInfo.toString());
|
||||
ClusterHelper.setKV(ClusterPathUtil.getDDLPath(nodeName), ddlInfo.toString());
|
||||
ClusterDelayProvider.delayAfterDdlNotice();
|
||||
|
||||
String errorMsg = ClusterUcoreSender.waitingForAllTheNode(UcorePathUtil.SUCCESS, UcorePathUtil.getDDLPath(nodeName));
|
||||
String errorMsg = ClusterHelper.waitingForAllTheNode(ClusterPathUtil.SUCCESS, ClusterPathUtil.getDDLPath(nodeName));
|
||||
|
||||
if (errorMsg != null) {
|
||||
throw new RuntimeException(errorMsg);
|
||||
@@ -577,10 +575,10 @@ public class ProxyMetaManager {
|
||||
throw e;
|
||||
} finally {
|
||||
ClusterDelayProvider.delayBeforeDdlNoticeDeleted();
|
||||
ClusterUcoreSender.deleteKVTree(UcorePathUtil.getDDLPath(nodeName) + "/");
|
||||
ClusterHelper.cleanPath(ClusterPathUtil.getDDLPath(nodeName) + "/");
|
||||
//release the lock
|
||||
ClusterDelayProvider.delayBeforeDdlLockRelease();
|
||||
UDistrbtLockManager.releaseLock(UcorePathUtil.getDDLPath(nodeName));
|
||||
DistrbtLockManager.releaseLock(ClusterPathUtil.getDDLPath(nodeName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ public class ServerConnection extends FrontendConnection {
|
||||
throw new Exception(msg);
|
||||
}
|
||||
DbleServer.getInstance().getTmManager().notifyClusterDDL(schema, table, rrs.getStatement());
|
||||
} else if (DbleServer.getInstance().isUseUcore()) {
|
||||
} else if (DbleServer.getInstance().isUseGeneralCluster()) {
|
||||
DbleServer.getInstance().getTmManager().notifyClusterDDL(schema, table, rrs.getStatement());
|
||||
}
|
||||
} catch (SQLNonTransientException e) {
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
|
||||
package com.actiontech.dble.server.status;
|
||||
|
||||
import com.actiontech.dble.cluster.ClusterParamCfg;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.ClusterUcoreSender;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UDistributeLock;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcoreConfig;
|
||||
import com.actiontech.dble.config.loader.ucoreprocess.UcorePathUtil;
|
||||
import com.actiontech.dble.cluster.*;
|
||||
import com.actiontech.dble.cluster.DistributeLock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -19,7 +16,7 @@ import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
public final class OnlineLockStatus {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(OnlineLockStatus.class);
|
||||
private volatile UDistributeLock onlineLock = null;
|
||||
private volatile DistributeLock onlineLock = null;
|
||||
private volatile boolean onlineInited = false;
|
||||
|
||||
private OnlineLockStatus() {
|
||||
@@ -36,12 +33,12 @@ public final class OnlineLockStatus {
|
||||
return false;
|
||||
}
|
||||
//check if the online mark is on than delete the mark and renew it
|
||||
ClusterUcoreSender.deleteKV(UcorePathUtil.getOnlinePath(UcoreConfig.getInstance().
|
||||
ClusterHelper.cleanKV(ClusterPathUtil.getOnlinePath(ClusterGeneralConfig.getInstance().
|
||||
getValue(ClusterParamCfg.CLUSTER_CFG_MYID)));
|
||||
if (onlineLock != null) {
|
||||
onlineLock.release();
|
||||
}
|
||||
onlineLock = new UDistributeLock(UcorePathUtil.getOnlinePath(UcoreConfig.getInstance().
|
||||
onlineLock = new DistributeLock(ClusterPathUtil.getOnlinePath(ClusterGeneralConfig.getInstance().
|
||||
getValue(ClusterParamCfg.CLUSTER_CFG_MYID)),
|
||||
"" + System.currentTimeMillis(), 6);
|
||||
int time = 0;
|
||||
|
||||
Reference in New Issue
Block a user