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 b828669  SCB-339 The wrong statistics in micro-service (#280)
b828669 is described below

commit b8286694238e3e49e0d0c740d6fcd75d07cb3f23
Author: aseTo2016 <[email protected]>
AuthorDate: Wed Feb 28 14:18:56 2018 +0800

    SCB-339 The wrong statistics in micro-service (#280)
    
    * SCB-339 The wrong statistics in micro-service
    2.get appId bug fix
    
    * SCB-339 The wrong statistics in micro-service
    2.get appId bug fix
    3.create micro-service, add service key compare
---
 server/core/key_generator.go              |  8 ++++++++
 server/govern/service.go                  |  8 +-------
 server/plugin/infra/registry/etcd/etcd.go | 17 ++++++++++-------
 server/service/microservices.go           | 10 ++++------
 4 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/server/core/key_generator.go b/server/core/key_generator.go
index cdd0e80..cb01236 100644
--- a/server/core/key_generator.go
+++ b/server/core/key_generator.go
@@ -78,6 +78,14 @@ func GetServiceAliasRootKey(domainProject string) string {
        }, "/")
 }
 
+func GetServiceAppKey(domainProject, env, appId string) string {
+       return util.StringJoin([]string{
+               GetServiceIndexRootKey(domainProject),
+               env,
+               appId,
+       }, "/")
+}
+
 func GetServiceRuleRootKey(domainProject string) string {
        return util.StringJoin([]string{
                GetRootKey(),
diff --git a/server/govern/service.go b/server/govern/service.go
index 4a0abe8..b2d74eb 100644
--- a/server/govern/service.go
+++ b/server/govern/service.go
@@ -180,13 +180,7 @@ func (governService *GovernService) GetApplications(ctx 
context.Context, in *pb.
        }
 
        domainProject := util.ParseDomainProject(ctx)
-       key := util.StringJoin([]string{
-               apt.GetServiceIndexRootKey(domainProject),
-               in.Environment,
-       }, "/")
-       if key[len(key)-1:] != "/" {
-               key += "/"
-       }
+       key := apt.GetServiceAppKey(domainProject, in.Environment, "")
 
        opts := append(serviceUtil.FromContext(ctx),
                registry.WithStrKey(key),
diff --git a/server/plugin/infra/registry/etcd/etcd.go 
b/server/plugin/infra/registry/etcd/etcd.go
index 941aa7c..6cd984a 100644
--- a/server/plugin/infra/registry/etcd/etcd.go
+++ b/server/plugin/infra/registry/etcd/etcd.go
@@ -250,12 +250,12 @@ func (c *EtcdClient) paging(ctx context.Context, op 
registry.PluginOp) (*clientv
        start := time.Now()
        tempOp := op
        tempOp.CountOnly = true
-       coutResp, err := c.Client.Get(ctx, key, c.toGetRequest(tempOp)...)
+       countResp, err := c.Client.Get(ctx, key, c.toGetRequest(tempOp)...)
        if err != nil {
                return nil, err
        }
 
-       recordCount := coutResp.Count
+       recordCount := countResp.Count
        if op.Offset == -1 && recordCount < op.Limit {
                return nil, nil // no paging
        }
@@ -268,9 +268,9 @@ func (c *EtcdClient) paging(ctx context.Context, op 
registry.PluginOp) (*clientv
        if len(op.EndKey) > 0 {
                tempOp.EndKey = op.EndKey
        }
-       tempOp.Revision = coutResp.Header.Revision
+       tempOp.Revision = countResp.Header.Revision
 
-       etcdResp = coutResp
+       etcdResp = countResp
        etcdResp.Kvs = make([]*mvccpb.KeyValue, 0, etcdResp.Count)
 
        pageCount := recordCount / op.Limit
@@ -344,6 +344,9 @@ func (c *EtcdClient) Do(ctx context.Context, opts 
...registry.PluginOpOption) (*
        switch op.Action {
        case registry.Get:
                var etcdResp *clientv3.GetResponse
+               if op.Prefix && op.Key[len(op.Key)-1] != '/' {
+                       op.Key = append(op.Key, '/')
+               }
                key := util.BytesToStringWithNoCopy(op.Key)
 
                if (op.Prefix || len(op.EndKey) > 0) && !op.CountOnly {
@@ -517,10 +520,10 @@ func (c *EtcdClient) Watch(ctx context.Context, opts 
...registry.PluginOpOption)
                client := clientv3.NewWatcher(c.Client)
                defer client.Close()
 
-               key := util.BytesToStringWithNoCopy(op.Key)
-               if op.Prefix && key[len(key)-1] != '/' {
-                       key += "/"
+               if op.Prefix && op.Key[len(op.Key)-1] != '/' {
+                       op.Key = append(op.Key, '/')
                }
+               key := util.BytesToStringWithNoCopy(op.Key)
 
                // 不能设置超时context,内部判断了连接超时和watch超时
                ws := client.Watch(context.Background(), key, 
c.toGetRequest(op)...)
diff --git a/server/service/microservices.go b/server/service/microservices.go
index 0e3e444..d3265e5 100644
--- a/server/service/microservices.go
+++ b/server/service/microservices.go
@@ -127,16 +127,18 @@ func (s *MicroServiceService) CreateServicePri(ctx 
context.Context, in *pb.Creat
                }, err
        }
        key := apt.GenerateServiceKey(domainProject, serviceId)
+       keyBytes := util.StringToBytesWithNoCopy(key)
        index := apt.GenerateServiceIndexKey(serviceKey)
        indexBytes := util.StringToBytesWithNoCopy(index)
        aliasBytes := 
util.StringToBytesWithNoCopy(apt.GenerateServiceAliasKey(serviceKey))
 
        opts := []registry.PluginOp{
-               registry.OpPut(registry.WithStrKey(key), 
registry.WithValue(data)),
+               registry.OpPut(registry.WithKey(keyBytes), 
registry.WithValue(data)),
                registry.OpPut(registry.WithKey(indexBytes), 
registry.WithStrValue(serviceId)),
        }
        uniqueCmpOpts := []registry.CompareOp{
                registry.OpCmp(registry.CmpVer(indexBytes), registry.CMP_EQUAL, 
0),
+               registry.OpCmp(registry.CmpVer(keyBytes), registry.CMP_EQUAL, 
0),
        }
 
        if len(serviceKey.Alias) > 0 {
@@ -204,11 +206,7 @@ func (s *MicroServiceService) DeleteServicePri(ctx 
context.Context, serviceId st
                title = "force delete"
        }
 
-       isServiceCenter := func(serviceId string) bool {
-               return serviceId == apt.Service.ServiceId
-       }
-
-       if isServiceCenter(serviceId) {
+       if serviceId == apt.Service.ServiceId {
                err := errors.New("not allow to delete service center")
                util.Logger().Errorf(err, "%s micro-service failed, serviceId 
is %s", title, serviceId)
                return pb.CreateResponse(scerr.ErrInvalidParams, err.Error()), 
nil

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to