You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/04/15 04:11:24 UTC

[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #943: SCB-2094 BugFix: join the heartbeat cache

little-cui commented on a change in pull request #943:
URL: https://github.com/apache/servicecomb-service-center/pull/943#discussion_r613742089



##########
File path: datasource/mongo/heartbeat/cache/heartbeat.go
##########
@@ -52,51 +60,54 @@ type instanceHeartbeatInfo struct {
 	lastRefresh time.Time
 }
 
-var (
+type cacheConfig struct {

Review comment:
       应独立一个go文件

##########
File path: datasource/mongo/heartbeat/healthcheck.go
##########
@@ -25,4 +25,5 @@ import (
 
 type HealthCheck interface {
 	Heartbeat(ctx context.Context, request *pb.HeartbeatRequest) (*pb.HeartbeatResponse, error)
+	CheckTask(instance *pb.MicroServiceInstance) error

Review comment:
       这两个接口写上注释,做什么事情,什么阶段会被调用等

##########
File path: datasource/mongo/heartbeat/healthcheck.go
##########
@@ -25,4 +25,5 @@ import (
 
 type HealthCheck interface {
 	Heartbeat(ctx context.Context, request *pb.HeartbeatRequest) (*pb.HeartbeatResponse, error)
+	CheckTask(instance *pb.MicroServiceInstance) error

Review comment:
       1. 应该增加参数ctx,方便后续有的实现内部有远程IO行为,可终止
   2. 方法名改成checkInstance更合适

##########
File path: datasource/mongo/heartbeat/cache/heartbeatcache.go
##########
@@ -44,20 +44,25 @@ func init() {
 }
 
 type HeartBeatCache struct {
+	cfg *cacheConfig
 }
 
 func NewHeartBeatCache(opts heartbeat.Options) (heartbeat.HealthCheck, error) {
-	return &HeartBeatCache{}, nil
+	return &HeartBeatCache{cfg: configuration()}, nil
 }
 
 func (h *HeartBeatCache) Heartbeat(ctx context.Context, request *pb.HeartbeatRequest) (*pb.HeartbeatResponse, error) {
-	if ins, ok := instanceHeartbeatStore.Get(request.InstanceId); ok {
-		return inCacheStrategy(ctx, request, ins)
+	if ins, ok := h.cfg.instanceHeartbeatStore.Get(request.InstanceId); ok {
+		return h.inCacheStrategy(ctx, request, ins)
 	}
-	return notInCacheStrategy(ctx, request)
+	return h.notInCacheStrategy(ctx, request)
 }
 
-func inCacheStrategy(ctx context.Context, request *pb.HeartbeatRequest, insHeartbeatInfo interface{}) (*pb.HeartbeatResponse, error) {
+func (h *HeartBeatCache) CheckTask(instance *pb.MicroServiceInstance) error {
+	return h.cfg.AddHeartbeatTask(instance.ServiceId, instance.InstanceId, instance.HealthCheck.Interval*(instance.HealthCheck.Times+1))

Review comment:
       写上注释,为什么要做这个事情




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org