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

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


The following commit(s) were added to refs/heads/dev by this push:
     new 78187873 1,support return dns name in health interface  2,revert the 
opt code of registry instance (#1469)
78187873 is described below

commit 78187873c0689d6fbe18862fefdf4179a08f01f7
Author: tornado-ssy <64736788+tornado-...@users.noreply.github.com>
AuthorDate: Mon Apr 15 23:03:20 2024 +0800

    1,support return dns name in health interface  2,revert the opt code of 
registry instance (#1469)
    
    * [feat] if the console show the dns name, then do not need port
    
    * Revert "[opt] improve the tps of registerInstance interface (#1458)"
    
    This reverts commit a6ef87c4be745653c3f68804b42e19250faa253b.
    
    ---------
    
    Co-authored-by: songshiyuan 00649746 <songshiyu...@huawei.com>
---
 datasource/etcd/state/kvstore/cache_kv.go      | 46 +++++---------------------
 datasource/etcd/state/kvstore/cache_kv_test.go | 14 --------
 server/core/microservice.go                    |  5 +--
 3 files changed, 11 insertions(+), 54 deletions(-)

diff --git a/datasource/etcd/state/kvstore/cache_kv.go 
b/datasource/etcd/state/kvstore/cache_kv.go
index 609d3a6f..dfbdaa9e 100644
--- a/datasource/etcd/state/kvstore/cache_kv.go
+++ b/datasource/etcd/state/kvstore/cache_kv.go
@@ -18,29 +18,21 @@
 package kvstore
 
 import (
-       regexp2 "regexp"
        "strings"
        "sync"
 
        "github.com/apache/servicecomb-service-center/pkg/util"
 )
 
-const InitCount = 1
-const InitLayer = 2
-const SPLIT = "/"
-const DomainProjectLayer = 6
-
 // KvCache implements Cache.
 // KvCache is dedicated to stores service discovery data,
 // e.g. service, instance, lease.
 type KvCache struct {
-       Cfg       *Options
-       name      string
-       store     map[string]map[string]*KeyValue
-       rwMux     sync.RWMutex
-       dirty     bool
-       count     map[string]int // the number of leaf node
-       keyLayers int            // the number of layers of leaf nodes
+       Cfg   *Options
+       name  string
+       store map[string]map[string]*KeyValue
+       rwMux sync.RWMutex
+       dirty bool
 }
 
 func (c *KvCache) Name() string {
@@ -71,12 +63,6 @@ func (c *KvCache) GetAll(arr *[]*KeyValue) (count int) {
        return
 }
 
-func (c *KvCache) getCacheDomainProjectKey(key string) string {
-       regexp, _ := regexp2.Compile(`/(\w)+-(\w)+/(\w)+/(\w)+/(\w)+/(\w)+/`)
-       domainProjectKey := regexp.FindString(key)
-       return domainProjectKey
-}
-
 func (c *KvCache) GetPrefix(prefix string, arr *[]*KeyValue) (count int) {
        c.rwMux.RLock()
        count = c.getPrefixKey(arr, prefix)
@@ -138,11 +124,6 @@ func (c *KvCache) getPrefixKey(arr *[]*KeyValue, prefix 
string) (count int) {
                return 0
        }
 
-       if arr == nil && strings.Count(prefix, SPLIT) == DomainProjectLayer {
-               count = c.count[prefix]
-               return
-       }
-
        // TODO support sort option
        if arr == nil {
                for key := range keysRef {
@@ -175,10 +156,6 @@ func (c *KvCache) addPrefixKey(key string, val *KeyValue) {
                return
        }
        keys, ok := c.store[prefix]
-       if strings.Count(key, SPLIT) > c.keyLayers {
-               c.count[c.getCacheDomainProjectKey(key)] = InitCount
-               c.keyLayers = strings.Count(key, SPLIT)
-       }
        if !ok {
                // build parent index key and new child nodes
                keys = make(map[string]*KeyValue)
@@ -189,8 +166,6 @@ func (c *KvCache) addPrefixKey(key string, val *KeyValue) {
                        keys[key] = val
                }
                return
-       } else if _, ok := keys[key]; !ok {
-               c.count[c.getCacheDomainProjectKey(key)]++
        }
 
        keys[key], key = val, prefix
@@ -203,9 +178,6 @@ func (c *KvCache) deletePrefixKey(key string) {
        if !ok {
                return
        }
-       if strings.Count(key, SPLIT) == c.keyLayers {
-               c.count[c.getCacheDomainProjectKey(key)]--
-       }
        delete(m, key)
 
        // remove parent which has no child
@@ -217,10 +189,8 @@ func (c *KvCache) deletePrefixKey(key string) {
 
 func NewKvCache(name string, cfg *Options) *KvCache {
        return &KvCache{
-               Cfg:       cfg,
-               name:      name,
-               store:     make(map[string]map[string]*KeyValue),
-               count:     make(map[string]int),
-               keyLayers: InitLayer,
+               Cfg:   cfg,
+               name:  name,
+               store: make(map[string]map[string]*KeyValue),
        }
 }
diff --git a/datasource/etcd/state/kvstore/cache_kv_test.go 
b/datasource/etcd/state/kvstore/cache_kv_test.go
deleted file mode 100644
index f18ff48c..00000000
--- a/datasource/etcd/state/kvstore/cache_kv_test.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package kvstore
-
-import (
-       "testing"
-
-       "github.com/stretchr/testify/assert"
-)
-
-func Test_getCacheDomainProjectKey(t *testing.T) {
-       testCache := new(KvCache)
-       str := "/cse-sr/inst/files/default/default/heheheh/xixixi/"
-       res := testCache.getCacheDomainProjectKey(str)
-       assert.Equal(t, "/cse-sr/inst/files/default/default/", res)
-}
diff --git a/server/core/microservice.go b/server/core/microservice.go
index ebb04d4f..45097a51 100644
--- a/server/core/microservice.go
+++ b/server/core/microservice.go
@@ -22,11 +22,12 @@ import (
        "fmt"
        "strings"
 
+       "github.com/go-chassis/cari/discovery"
+
        "github.com/apache/servicecomb-service-center/datasource"
        "github.com/apache/servicecomb-service-center/pkg/util"
        "github.com/apache/servicecomb-service-center/server/config"
        "github.com/apache/servicecomb-service-center/version"
-       "github.com/go-chassis/cari/discovery"
 )
 
 var (
@@ -87,7 +88,7 @@ func InitRegistration() {
 func getEndpoints() []string {
        hostPort := config.GetString("registry.instance.endpoint",
                config.GetString("server.host", "127.0.0.1", 
config.WithStandby("httpaddr")))
-       if strings.LastIndex(hostPort, ":") < 0 {
+       if strings.LastIndex(hostPort, ":") < 0 && 
config.GetString("is.dns.name", "false") == "false" {
                hostPort += ":" + config.GetString("server.port", "30100", 
config.WithStandby("httpport"))
        }
        endpoint := fmt.Sprintf("rest://%s/", hostPort)

Reply via email to