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/05/19 07:02:21 UTC

[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #962: SCB-2094 Add heartbeat ws interface

tianxiaoliang commented on a change in pull request #962:
URL: https://github.com/apache/servicecomb-service-center/pull/962#discussion_r634964529



##########
File path: datasource/etcd/util/instance_util.go
##########
@@ -65,6 +65,19 @@ func GetInstance(ctx context.Context, domainProject string, serviceID string, in
 	return resp.Kvs[0].Value.(*pb.MicroServiceInstance), nil
 }
 
+func InstanceExist(ctx context.Context, domainProject string, serviceID string, instanceID string) (bool, error) {
+	key := path.GenerateInstanceKey(domainProject, serviceID, instanceID)
+	opts := append(FromContext(ctx), client.WithStrKey(key))
+	resp, err := kv.Store().Instance().Search(ctx, opts...)
+	if err != nil || resp.Count == 0 {
+		return false, err
+	}
+	if resp.Count == 0 {
+		return false, nil

Review comment:
       所以你这里都执行不到了,这个才是对的

##########
File path: datasource/etcd/util/instance_util.go
##########
@@ -65,6 +65,19 @@ func GetInstance(ctx context.Context, domainProject string, serviceID string, in
 	return resp.Kvs[0].Value.(*pb.MicroServiceInstance), nil
 }
 
+func InstanceExist(ctx context.Context, domainProject string, serviceID string, instanceID string) (bool, error) {
+	key := path.GenerateInstanceKey(domainProject, serviceID, instanceID)
+	opts := append(FromContext(ctx), client.WithStrKey(key))
+	resp, err := kv.Store().Instance().Search(ctx, opts...)
+	if err != nil || resp.Count == 0 {
+		return false, err

Review comment:
       resp的count为0时 err一定是nil,此时最好是返回自定义错误




-- 
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