You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/02/25 07:25:53 UTC
[servicecomb-service-center] branch master updated: [SCB-2094]
cache heartbeat mode in mongo (#872)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new e583c4b [SCB-2094] cache heartbeat mode in mongo (#872)
e583c4b is described below
commit e583c4b5e68c4cb56d96248c0af6926aae39f6c4
Author: robotLJW <79...@qq.com>
AuthorDate: Thu Feb 25 15:25:47 2021 +0800
[SCB-2094] cache heartbeat mode in mongo (#872)
1. [Bugfix] the heartbeat interface is called after the registration instance is successful
---
datasource/mongo/ms.go | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/datasource/mongo/ms.go b/datasource/mongo/ms.go
index eb9cad3..a2732ac 100644
--- a/datasource/mongo/ms.go
+++ b/datasource/mongo/ms.go
@@ -1546,6 +1546,13 @@ func (ds *DataSource) RegisterInstance(ctx context.Context, request *discovery.R
}, nil
case discovery.ErrInstanceNotExists:
// register a new one
+ if request.Instance.HealthCheck == nil {
+ request.Instance.HealthCheck = &discovery.HealthCheck{
+ Mode: discovery.CHECK_BY_HEARTBEAT,
+ Interval: apt.RegistryDefaultLeaseRenewalinterval,
+ Times: apt.RegistryDefaultLeaseRetrytimes,
+ }
+ }
return registryInstance(ctx, request)
default:
log.Error(fmt.Sprintf("register instance failed, reuse instance %s %s, operator %s",
@@ -2082,6 +2089,17 @@ func registryInstance(ctx context.Context, request *discovery.RegisterInstanceRe
log.Info(fmt.Sprintf("register instance %s, instanceID %s, operator %s",
instanceFlag, insertRes.InsertedID, remoteIP))
+ heartbeatRequest := discovery.HeartbeatRequest{
+ ServiceId: instance.ServiceId,
+ InstanceId: instance.InstanceId,
+ }
+ aliveErr := KeepAliveLease(ctx, &heartbeatRequest)
+ if aliveErr != nil {
+ log.Error(fmt.Sprintf("failed to send heartbeat after registering instance, instance %s operator %s", instanceFlag, remoteIP), err)
+ return &discovery.RegisterInstanceResponse{
+ Response: discovery.CreateResponseWithSCErr(aliveErr),
+ }, err
+ }
return &discovery.RegisterInstanceResponse{
Response: discovery.CreateResponse(discovery.ResponseSuccess, "Register service instance successfully."),
InstanceId: instanceID,