Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
deardeng committed Jan 2, 2025
1 parent aeaa111 commit d0d3496
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ private void alterBackendCluster(List<HostInfo> hostInfos, String computeGroupId
throw new DdlException("unable to alter backends due to empty cloud_instance_id");
}
// Issue rpc to meta to alter node, then fe master would add this node to its frontends
Cloud.ClusterPB clusterPB = Cloud.ClusterPB.newBuilder()
ClusterPB clusterPB = ClusterPB.newBuilder()
.setClusterId(computeGroupId)
.setType(Cloud.ClusterPB.Type.COMPUTE)
.setType(ClusterPB.Type.COMPUTE)
.build();

for (HostInfo hostInfo : hostInfos) {
Expand Down Expand Up @@ -844,10 +844,10 @@ private void alterFrontendCluster(FrontendNodeType role, String host, int editLo
.setCtime(System.currentTimeMillis() / 1000)
.build();

Cloud.ClusterPB clusterPB = Cloud.ClusterPB.newBuilder()
ClusterPB clusterPB = ClusterPB.newBuilder()
.setClusterId(Config.cloud_sql_server_cluster_id)
.setClusterName(Config.cloud_sql_server_cluster_name)
.setType(Cloud.ClusterPB.Type.SQL)
.setType(ClusterPB.Type.SQL)
.addNodes(nodeInfoPB)
.build();

Expand Down Expand Up @@ -888,10 +888,10 @@ private String tryCreateComputeGroup(String clusterName, String computeGroupId)
throw new DdlException("unable to create compute group due to empty cloud_instance_id");
}

Cloud.ClusterPB clusterPB = Cloud.ClusterPB.newBuilder()
ClusterPB clusterPB = ClusterPB.newBuilder()
.setClusterId(computeGroupId)
.setClusterName(clusterName)
.setType(Cloud.ClusterPB.Type.COMPUTE)
.setType(ClusterPB.Type.COMPUTE)
.build();

Cloud.AlterClusterRequest request = Cloud.AlterClusterRequest.newBuilder()
Expand All @@ -917,7 +917,7 @@ private String tryCreateComputeGroup(String clusterName, String computeGroupId)
Cloud.GetClusterResponse clusterResponse = getCloudCluster(clusterName, "", "");
if (clusterResponse.getStatus().getCode() == Cloud.MetaServiceCode.OK) {
if (clusterResponse.getClusterCount() > 0) {
Cloud.ClusterPB cluster = clusterResponse.getCluster(0);
ClusterPB cluster = clusterResponse.getCluster(0);
return cluster.getClusterId();
} else {
throw new UserException("Cluster information not found in the response");
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public String waitForAutoStart(String clusterName) throws DdlException {
builder.setCloudUniqueId(Config.cloud_unique_id);
builder.setOp(Cloud.AlterClusterRequest.Operation.SET_CLUSTER_STATUS);

Cloud.ClusterPB.Builder clusterBuilder = Cloud.ClusterPB.newBuilder();
ClusterPB.Builder clusterBuilder = ClusterPB.newBuilder();
clusterBuilder.setClusterId(getCloudClusterIdByName(clusterName));
clusterBuilder.setClusterStatus(Cloud.ClusterStatus.TO_RESUME);
builder.setCluster(clusterBuilder);
Expand Down Expand Up @@ -1167,35 +1167,42 @@ public void renameComputeGroup(String originalName, String newGroupName) throws
String originalComputeGroupId = ((CloudSystemInfoService) Env.getCurrentSystemInfo())
.getCloudClusterIdByName(originalName);
if (Strings.isNullOrEmpty(originalComputeGroupId)) {
throw new DdlException("unable to rename compute group, "
+ "cant get compute group id by compute name " + originalName);
LOG.info("rename original compute group {} not found, unable to rename", originalName);
throw new DdlException("compute group '" + originalName + "' not found, unable to rename");
}
// check newGroupName has existed
if (((CloudSystemInfoService) Env.getCurrentSystemInfo()).getCloudClusterNames().contains(newGroupName)) {
LOG.info("rename new compute group {} has existed in instance, unable to rename", newGroupName);
throw new DdlException("compute group '" + newGroupName + "' has existed in warehouse, unable to rename");
}

Cloud.ClusterPB clusterPB = Cloud.ClusterPB.newBuilder()
ClusterPB clusterPB = ClusterPB.newBuilder()
.setClusterId(originalComputeGroupId)
.setClusterName(newGroupName)
.setType(Cloud.ClusterPB.Type.COMPUTE)
.setType(ClusterPB.Type.COMPUTE)
.build();

Cloud.AlterClusterRequest request = Cloud.AlterClusterRequest.newBuilder()
.setInstanceId(((CloudEnv) Env.getCurrentEnv()).getCloudInstanceId())
.setOp(Cloud.AlterClusterRequest.Operation.RENAME_CLUSTER)
.setDropEmptyCluster(true)
.setReplaceIfExistingEmptyTargetCluster(true)
.setCluster(clusterPB)
.build();


Cloud.AlterClusterResponse response;
Cloud.AlterClusterResponse response = null;
try {
response = MetaServiceProxy.getInstance().alterCluster(request);
LOG.info("alter rename compute group, request: {}, response: {}", request, response);
if (response.getStatus().getCode() != Cloud.MetaServiceCode.OK) {
LOG.warn("alter rename compute group not ok, response: {}", response);
throw new UserException("failed to rename compute group errorCode: " + response.getStatus().getCode()
+ " msg: " + response.getStatus().getMsg());
+ " msg: " + response.getStatus().getMsg() + " may be you can try later");
}
} catch (RpcException e) {
LOG.warn("alter rename compute group rpc exception");
throw new UserException("failed to alter rename compute group", e);
} finally {
LOG.info("alter rename compute group, request: {}, response: {}", request, response);
}
}
}
2 changes: 1 addition & 1 deletion gensrc/proto/cloud.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ message AlterClusterRequest {
optional ClusterPB cluster = 3;
optional Operation op = 4;
// for SQL mode rename cluster, rename to cluster name eq instance empty cluster name, need drop empty cluster
optional bool drop_empty_cluster = 5 [default = false];
optional bool replace_if_existing_empty_target_cluster = 5;
}

message AlterClusterResponse {
Expand Down

0 comments on commit d0d3496

Please sign in to comment.