[
https://issues.apache.org/jira/browse/SCB-680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16523136#comment-16523136
]
ASF GitHub Bot commented on SCB-680:
------------------------------------
little-cui closed pull request #381: SCB-680 Fix the wrong rev in find instance
api
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/381
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/server/service/instance_test.go b/server/service/instance_test.go
index 83f1ecb6..c11866e4 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 55932480..5a2b7e9c 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, ""),
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Optimize find instance api
> --------------------------
>
> Key: SCB-680
> URL: https://issues.apache.org/jira/browse/SCB-680
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)