Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimized ]Optimized the heartbeat of the cluster #3119

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading