Skip to content

Commit

Permalink
[Optimized ]Optimized the heartbeat of the cluster (#3119)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyan1998 authored Jan 31, 2024
1 parent 541abf7 commit 8fe8baf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,8 @@ public Result<List<ClusterInstance>> listSessionEnable() {
@Log(title = "Cluster Instance Heartbeat", businessType = BusinessType.UPDATE)
@ApiOperation("Cluster Instance Heartbeat")
@SaCheckPermission(value = {PermissionConstants.REGISTRATION_CLUSTER_INSTANCE_HEARTBEATS})
public Result<Void> heartbeat() {
List<ClusterInstance> clusterInstances = clusterInstanceService.list();
for (ClusterInstance clusterInstance : clusterInstances) {
clusterInstanceService.registersCluster(clusterInstance);
}
return Result.succeed(Status.CLUSTER_INSTANCE_HEARTBEAT_SUCCESS);
public Result<Long> heartbeat() {
return Result.succeed(clusterInstanceService.heartbeat(), Status.CLUSTER_INSTANCE_HEARTBEAT_SUCCESS);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ public interface ClusterInstanceService extends ISuperService<ClusterInstance> {
* @return {@link Boolean} true: has relationship, false: no relationship
*/
boolean hasRelationShip(Integer id);

/**
* heartbeat
* @return {@link Long}
*/
Long heartbeat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
Expand All @@ -57,6 +60,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -275,6 +279,17 @@ public boolean hasRelationShip(Integer id) {
.isEmpty();
}

@Override
public Long heartbeat() {
List<ClusterInstance> clusterInstances = this.list();
ExecutorService executor = ThreadUtil.newExecutor(Math.min(clusterInstances.size(), 10));
List<CompletableFuture<Integer>> futures = clusterInstances.stream()
.map(c -> CompletableFuture.supplyAsync(
() -> this.registersCluster(c).getStatus(), executor))
.collect(Collectors.toList());
return futures.stream().map(CompletableFuture::join).filter(x -> x == 1).count();
}

private boolean checkHealth(ClusterInstance clusterInstance) {
FlinkClusterInfo info = checkHeartBeat(clusterInstance.getHosts(), clusterInstance.getJobManagerHost());
if (!info.isEffective()) {
Expand Down

0 comments on commit 8fe8baf

Please sign in to comment.