You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/06/26 03:38:30 UTC

[incubator-servicecomb-service-center] branch master updated: SCB-680 Fix the wrong rev in find instance api (#381)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 877075f  SCB-680 Fix the wrong rev in find instance api (#381)
877075f is described below

commit 877075f36c1cc359b63811d7a8c1502d3062af57
Author: little-cui <su...@qq.com>
AuthorDate: Tue Jun 26 11:38:29 2018 +0800

    SCB-680 Fix the wrong rev in find instance api (#381)
    
    * SCB-680 Fix the wrong rev in find instance api
    
    * SCB-680 Fix the wrong rev in find instance api
    
    * SCB-680 Fix the wrong rev in find instance api
---
 server/service/instance_test.go      |  7 ++++---
 server/service/util/instance_util.go | 11 +++++++----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/server/service/instance_test.go b/server/service/instance_test.go
index 83f1ecb..c11866e 100644
--- a/server/service/instance_test.go
+++ b/server/service/instance_test.go
@@ -17,6 +17,7 @@
 package service_test
 
 import (
+	"fmt"
 	"github.com/apache/incubator-servicecomb-service-center/pkg/util"
 	"github.com/apache/incubator-servicecomb-service-center/server/core"
 	pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
@@ -1173,7 +1174,7 @@ var _ = Describe("'Instance' service", func() {
 				Expect(respFind.Instances[0].InstanceId).To(Equal(instanceId4))
 
 				By("find with rev")
-				ctx := util.SetContext(getContext(), serviceUtil.CTX_NOCACHE, 0)
+				ctx := util.SetContext(getContext(), serviceUtil.CTX_NOCACHE, "")
 				respFind, err = instanceResource.Find(ctx, &pb.FindInstancesRequest{
 					ConsumerServiceId: serviceId8,
 					AppId:             "query_instance",
@@ -1188,7 +1189,7 @@ var _ = Describe("'Instance' service", func() {
 				Expect(respFind.Instances[0].InstanceId).To(Equal(instanceId8))
 				Expect(reqRev).NotTo(Equal(0))
 
-				util.SetContext(ctx, serviceUtil.CTX_REQUEST_REVISION, reqRev-1)
+				util.SetContext(ctx, serviceUtil.CTX_REQUEST_REVISION, fmt.Sprint(reqRev-1))
 				respFind, err = instanceResource.Find(ctx, &pb.FindInstancesRequest{
 					ConsumerServiceId: serviceId8,
 					AppId:             "query_instance",
@@ -1201,7 +1202,7 @@ var _ = Describe("'Instance' service", func() {
 				Expect(respFind.Instances[0].InstanceId).To(Equal(instanceId8))
 				Expect(ctx.Value(serviceUtil.CTX_RESPONSE_REVISION)).To(Equal(rev))
 
-				util.SetContext(ctx, serviceUtil.CTX_REQUEST_REVISION, reqRev+1)
+				util.SetContext(ctx, serviceUtil.CTX_REQUEST_REVISION, fmt.Sprint(reqRev+1))
 				respFind, err = instanceResource.Find(ctx, &pb.FindInstancesRequest{
 					ConsumerServiceId: serviceId8,
 					AppId:             "query_instance",
diff --git a/server/service/util/instance_util.go b/server/service/util/instance_util.go
index 5593248..5a2b7e9 100644
--- a/server/service/util/instance_util.go
+++ b/server/service/util/instance_util.go
@@ -87,7 +87,7 @@ func GetAllInstancesOfServices(ctx context.Context, domainProject string, ids []
 
 	rawRev, _ := cloneCtx.Value(CTX_REQUEST_REVISION).(string)
 	reqRev, reqCount := ParseRevision(rawRev)
-	if !noCache && !cacheOnly && reqRev > 0 {
+	if !noCache && !cacheOnly && len(rawRev) > 0 {
 		// force to find in cache at first time when rev is not empty
 		util.SetContext(cloneCtx, CTX_CACHEONLY, "1")
 	}
@@ -98,6 +98,9 @@ func GetAllInstancesOfServices(ctx context.Context, domainProject string, ids []
 		kvs       []*mvccpb.KeyValue
 	)
 	for i := 0; i < 2; i++ {
+		maxRev = 0
+		kvs = kvs[:0]
+
 		for _, serviceId := range ids {
 			key := apt.GenerateInstanceKey(domainProject, serviceId, "")
 			opts := append(FromContext(cloneCtx), registry.WithStrKey(key), registry.WithPrefix())
@@ -113,11 +116,12 @@ func GetAllInstancesOfServices(ctx context.Context, domainProject string, ids []
 			if cmax := resp.MaxModRevision(); maxRev < cmax {
 				maxRev = cmax
 			}
-			instCount += int64(len(resp.Kvs))
 			kvs = append(kvs, resp.Kvs...)
 		}
 
-		if noCache || cacheOnly || len(rev) == 0 {
+		instCount = int64(len(kvs))
+
+		if noCache || cacheOnly || len(rawRev) == 0 {
 			break
 		}
 
@@ -131,7 +135,6 @@ func GetAllInstancesOfServices(ctx context.Context, domainProject string, ids []
 			break
 		}
 
-		kvs = kvs[:0]
 		// find from remote server at second time
 		util.SetContext(util.SetContext(cloneCtx,
 			CTX_CACHEONLY, ""),