Skip to content

Commit

Permalink
Merge pull request #929 from wangqifan/feature/hetero_support
Browse files Browse the repository at this point in the history
update cluster convert limit business
  • Loading branch information
LanternLee authored Jan 23, 2025
2 parents e070256 + 2fa37df commit ae22a14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/com/ctrip/xpipe/cluster/ClusterType.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ public static boolean supportConvert(String type) {
return isSameClusterType(type, ONE_WAY) || isSameClusterType(type, HETERO);
}

public static boolean supportConvert(String oldType, String newType) {
if(StringUtil.isEmpty(oldType) || StringUtil.isEmpty(newType)) {
return false;
}
if(isSameClusterType(oldType, HETERO) &&
(isSameClusterType(newType, ONE_WAY) || isSameClusterType(newType, SINGLE_DC))) {
return true;
}
if((isSameClusterType(oldType, ONE_WAY) || isSameClusterType(oldType, SINGLE_DC)) && isSameClusterType(newType, HETERO)) {
return true;
}
return false;
}

public static ClusterType lookup(String name) {
if (StringUtil.isEmpty(name)) throw new IllegalArgumentException("no ClusterType for name " + name);
return valueOf(name.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.ctrip.xpipe.cluster.ClusterType.HETERO;
import static com.ctrip.xpipe.redis.core.protocal.RedisProtocol.APPLIER_PORT_DEFAULT;
import static com.ctrip.xpipe.redis.core.protocal.RedisProtocol.KEEPER_PORT_DEFAULT;

Expand Down Expand Up @@ -723,12 +724,17 @@ public String updateCluster(ClusterUpdateDTO clusterUpdateDTO) {
if (!StringUtil.isEmpty(clusterType)) {
String oldClusterType = clusterTbl.getClusterType();
if (!clusterType.equalsIgnoreCase(oldClusterType)) {
if (ClusterType.supportConvert(oldClusterType) && ClusterType.supportConvert(clusterType)) {
List<AzGroupClusterEntity> azGroupClusters = azGroupClusterRepository.selectByClusterId(clusterTbl.getId());
if(ClusterType.isSameClusterType (clusterType, HETERO) && (azGroupClusters == null || azGroupClusters.isEmpty())) {
throw new BadRequestException("To convert to HETERO, you need to upgrade to az group model first");
}

if (ClusterType.supportConvert(oldClusterType, clusterType)) {
needUpdate = true;
clusterTbl.setClusterType(clusterType.toUpperCase());
} else {
// 仅允许单向同步、异构集群之间互相转换
throw new BadRequestException("Only ONE_WAY/HETERO cluster can be converted to each other");
throw new BadRequestException("Only (ONE_WAY, SINGLE_DC)/HETERO cluster can be converted to each other");
}
}
}
Expand Down

0 comments on commit ae22a14

Please sign in to comment.