Skip to content

Commit

Permalink
Revert "[opt] improve the tps of registerInstance interface (#1458)"
Browse files Browse the repository at this point in the history
This reverts commit a6ef87c.
  • Loading branch information
songshiyuan 00649746 committed Apr 15, 2024
1 parent 6092d31 commit 38816f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 52 deletions.
46 changes: 8 additions & 38 deletions datasource/etcd/state/kvstore/cache_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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),
}
}
14 changes: 0 additions & 14 deletions datasource/etcd/state/kvstore/cache_kv_test.go

This file was deleted.

0 comments on commit 38816f4

Please sign in to comment.