[ 
https://issues.apache.org/jira/browse/SCB-934?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16623283#comment-16623283
 ] 

ASF GitHub Bot commented on SCB-934:
------------------------------------

little-cui closed pull request #448: SCB-934 sc  will panic when get all 
dependency rules
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/448
 
 
   

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/infra/discovery/cache_kv.go 
b/server/infra/discovery/cache_kv.go
index 97cc6e9b..ff8c6424 100644
--- a/server/infra/discovery/cache_kv.go
+++ b/server/infra/discovery/cache_kv.go
@@ -108,19 +108,18 @@ func (c *KvCache) getPrefixKey(arr *[]*KeyValue, prefix 
string) (count int) {
                return 0
        }
 
-       for key := range keysRef {
-               n := c.getPrefixKey(arr, key)
-               if n == 0 {
-                       count += len(keysRef)
-                       if arr != nil {
-                               // TODO support sort option
-                               for _, v := range keysRef {
-                                       *arr = append(*arr, v)
-                               }
-                       }
-                       break
+       tmp := make([]*KeyValue, 0, len(keysRef))
+       for key, val := range keysRef {
+               if n := c.getPrefixKey(arr, key); n > 0 {
+                       count += n
+                       continue
                }
-               count += n
+               tmp = append(tmp, val)
+               count++
+       }
+       if arr != nil {
+               // TODO support sort option
+               *arr = append(*arr, tmp...)
        }
        return count
 }
diff --git a/server/infra/discovery/cache_test.go 
b/server/infra/discovery/cache_test.go
index 8ce1cd70..741784b4 100644
--- a/server/infra/discovery/cache_test.go
+++ b/server/infra/discovery/cache_test.go
@@ -111,4 +111,22 @@ func TestKvCache_Get(t *testing.T) {
        if kv := c.Get("/a/b/c/d/e/1"); kv == nil || kv.Version != 2 {
                t.Fatalf("TestKvCache Put() failed, %v", kv)
        }
+
+       c.Put("/x//p/*", &KeyValue{Version: 1})
+       c.Put("/x//p/app/name/version1", &KeyValue{Version: 2})
+       c.Put("/x//p/app/name/version2", &KeyValue{Version: 3})
+       n := c.GetPrefix("/x//p/", nil)
+       if n != 3 {
+               t.Fatalf("TestKvCache Put() failed, %v", n)
+       }
+       kvs := make([]*KeyValue, 0, n)
+       c.GetPrefix("/x//p/", &kvs)
+       if len(kvs) != 3 {
+               t.Fatalf("TestKvCache Put() failed, %v", kvs)
+       }
+       for _, kv := range kvs {
+               if kv.Version != 1 && kv.Version != 2 && kv.Version != 3 {
+                       t.Fatalf("TestKvCache Put() failed, %v", kvs)
+               }
+       }
 }


 

----------------------------------------------------------------
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:
us...@infra.apache.org


> Get all dependency rules will panic
> -----------------------------------
>
>                 Key: SCB-934
>                 URL: https://issues.apache.org/jira/browse/SCB-934
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Service-Center
>            Reporter: little-cui
>            Assignee: little-cui
>            Priority: Major
>             Fix For: service-center-1.1.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to