little-cui closed pull request #352:  SCB-393 Retry to request etcd too 
frequently when fail
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/352
 
 
   

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/integration/instances_test.go b/integration/instances_test.go
index 948c9f62..50043210 100644
--- a/integration/instances_test.go
+++ b/integration/instances_test.go
@@ -168,6 +168,7 @@ var _ = Describe("MicroService Api Test", func() {
                                        "times":    2,
                                }
                                instance := map[string]interface{}{
+                                       "instanceId":  serviceInstanceID,
                                        "endpoints":   endpoints,
                                        "hostName":    "cse",
                                        "status":      "UP",
diff --git a/pkg/util/backoff.go b/pkg/util/backoff.go
new file mode 100644
index 00000000..7f96cfd0
--- /dev/null
+++ b/pkg/util/backoff.go
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package util
+
+import (
+       "math"
+       "time"
+)
+
+var DefaultBackoff Backoff = &PowerBackoff{
+       MaxDelay:  30 * time.Second,
+       InitDelay: 1 * time.Second,
+       Factor:    1.6,
+}
+
+type Backoff interface {
+       Delay(retries int) time.Duration
+}
+
+// delay = min(MaxDelay, InitDelay * power(Factor, retries))
+type PowerBackoff struct {
+       MaxDelay  time.Duration
+       InitDelay time.Duration
+       Factor    float64
+}
+
+func (pb *PowerBackoff) Delay(retries int) time.Duration {
+       if retries <= 0 {
+               return pb.InitDelay
+       }
+
+       return time.Duration(math.Min(float64(pb.MaxDelay), 
float64(pb.InitDelay)*math.Pow(pb.Factor, float64(retries))))
+}
+
+func GetBackoff() Backoff {
+       return DefaultBackoff
+}
diff --git a/pkg/util/backoff_test.go b/pkg/util/backoff_test.go
new file mode 100644
index 00000000..301a914f
--- /dev/null
+++ b/pkg/util/backoff_test.go
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package util
+
+import (
+       "testing"
+       "time"
+)
+
+func TestPowerBackoff_Delay(t *testing.T) {
+       i, m := time.Second, 30*time.Second
+       b := &PowerBackoff{
+               MaxDelay:  30 * time.Second,
+               InitDelay: 1 * time.Second,
+               Factor:    1.6,
+       }
+       r := b.Delay(-1)
+       if r != i {
+               t.Fatalf("TestPowerBackoff_Delay -1 failed, result is %s", r)
+       }
+       r = b.Delay(0)
+       if r != i {
+               t.Fatalf("TestPowerBackoff_Delay 0 failed, result is %s", r)
+       }
+       r = b.Delay(1)
+       if r != 1600*time.Millisecond {
+               t.Fatalf("TestPowerBackoff_Delay 1 failed, result is %s", r)
+       }
+       r = b.Delay(4)
+       if r != 6553600*time.Microsecond {
+               t.Fatalf("TestPowerBackoff_Delay 4 failed, result is %s", r)
+       }
+       r = b.Delay(8)
+       if r != m {
+               t.Fatalf("TestPowerBackoff_Delay 8 failed, result is %s", r)
+       }
+}
+
+func TestGetBackoff(t *testing.T) {
+       if GetBackoff() == nil {
+               t.Fatalf("TestGetBackoff failed")
+       }
+}
diff --git a/pkg/util/util.go b/pkg/util/util.go
index d63191a6..a8ca1832 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -142,25 +142,26 @@ func LogPanic(args ...interface{}) {
                }
 
                if strings.Index(file, "service-center") > 0 || 
strings.Index(file, "servicecenter") > 0 {
-                       idx := strings.LastIndex(file, "/")
-                       if idx >= 0 {
-                               file = file[idx+1:]
-                       }
-                       Logger().Errorf(nil, "recover from %s %s():%d! %s", 
file, method, line, fmt.Sprint(args...))
+                       Logger().Errorf(nil, "recover from %s %s():%d! %s", 
FileLastName(file), method, line, fmt.Sprint(args...))
                        return
                }
        }
 
        file, method, line, _ := GetCaller(0)
-       idx := strings.LastIndex(file, "/")
-       if idx >= 0 {
-               file = file[idx+1:]
-       }
        fmt.Fprintln(os.Stderr, 
time.Now().Format("2006-01-02T15:04:05.000Z07:00"), "FATAL", "system", 
os.Getpid(),
-               fmt.Sprintf("%s %s():%d", file, method, line), 
fmt.Sprint(args...))
+               fmt.Sprintf("%s %s():%d", FileLastName(file), method, line), 
fmt.Sprint(args...))
        fmt.Fprintln(os.Stderr, BytesToStringWithNoCopy(debug.Stack()))
 }
 
+func FileLastName(file string) string {
+       if sp1 := strings.LastIndex(file, "/"); sp1 >= 0 {
+               if sp2 := strings.LastIndex(file[:sp1], "/"); sp2 >= 0 {
+                       file = file[sp2+1:]
+               }
+       }
+       return file
+}
+
 func GetCaller(skip int) (string, string, int, bool) {
        pc, file, line, ok := runtime.Caller(skip + 1)
        method := FormatFuncName(runtime.FuncForPC(pc).Name())
diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go
index 16f342f4..94e1aa33 100644
--- a/pkg/util/util_test.go
+++ b/pkg/util/util_test.go
@@ -51,3 +51,30 @@ func TestBytesToInt32(t *testing.T) {
                t.FailNow()
        }
 }
+
+func TestFileLastName(t *testing.T) {
+       n := FileLastName("")
+       if n != "" {
+               t.Fatal("TestFileLastName '' failed", n)
+       }
+       n = FileLastName("a")
+       if n != "a" {
+               t.Fatal("TestFileLastName 'a' failed", n)
+       }
+       n = FileLastName("a/b")
+       if n != "a/b" {
+               t.Fatal("TestFileLastName 'a/b' failed", n)
+       }
+       n = FileLastName("a/b/c")
+       if n != "b/c" {
+               t.Fatal("TestFileLastName 'b/c' failed", n)
+       }
+       n = FileLastName("b/")
+       if n != "b/" {
+               t.Fatal("TestFileLastName 'b' failed", n)
+       }
+       n = FileLastName("/")
+       if n != "/" {
+               t.Fatal("TestFileLastName 'b' failed", n)
+       }
+}
diff --git a/server/broker/store.go b/server/broker/store.go
index 3bfe9825..51acacaf 100644
--- a/server/broker/store.go
+++ b/server/broker/store.go
@@ -17,61 +17,61 @@
 package broker
 
 import (
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
 )
 
 var (
-       PARTICIPANT  store.StoreType
-       VERSION      store.StoreType
-       PACT         store.StoreType
-       PACT_VERSION store.StoreType
-       PACT_TAG     store.StoreType
-       VERIFICATION store.StoreType
-       PACT_LATEST  store.StoreType
+       PARTICIPANT  backend.StoreType
+       VERSION      backend.StoreType
+       PACT         backend.StoreType
+       PACT_VERSION backend.StoreType
+       PACT_TAG     backend.StoreType
+       VERIFICATION backend.StoreType
+       PACT_LATEST  backend.StoreType
 )
 
 var brokerKvStore = &BKvStore{}
 
 func init() {
-       PARTICIPANT = store.Store().MustInstall(store.NewEntity("PARTICIPANT", 
GetBrokerParticipantKey("")))
-       VERSION = store.Store().MustInstall(store.NewEntity("VERSION", 
GetBrokerVersionKey("")))
-       PACT = store.Store().MustInstall(store.NewEntity("PACT", 
GetBrokerPactKey("")))
-       PACT_VERSION = 
store.Store().MustInstall(store.NewEntity("PACT_VERSION", 
GetBrokerPactVersionKey("")))
-       PACT_TAG = store.Store().MustInstall(store.NewEntity("PACT_TAG", 
GetBrokerTagKey("")))
-       VERIFICATION = 
store.Store().MustInstall(store.NewEntity("VERIFICATION", 
GetBrokerVerificationKey("")))
-       PACT_LATEST = store.Store().MustInstall(store.NewEntity("PACT_LATEST", 
GetBrokerLatestKey("")))
+       PARTICIPANT = 
backend.Store().MustInstall(backend.NewEntity("PARTICIPANT", 
GetBrokerParticipantKey("")))
+       VERSION = backend.Store().MustInstall(backend.NewEntity("VERSION", 
GetBrokerVersionKey("")))
+       PACT = backend.Store().MustInstall(backend.NewEntity("PACT", 
GetBrokerPactKey("")))
+       PACT_VERSION = 
backend.Store().MustInstall(backend.NewEntity("PACT_VERSION", 
GetBrokerPactVersionKey("")))
+       PACT_TAG = backend.Store().MustInstall(backend.NewEntity("PACT_TAG", 
GetBrokerTagKey("")))
+       VERIFICATION = 
backend.Store().MustInstall(backend.NewEntity("VERIFICATION", 
GetBrokerVerificationKey("")))
+       PACT_LATEST = 
backend.Store().MustInstall(backend.NewEntity("PACT_LATEST", 
GetBrokerLatestKey("")))
 
 }
 
 type BKvStore struct {
 }
 
-func (s *BKvStore) Participant() *store.Indexer {
-       return store.Store().Entity(PARTICIPANT)
+func (s *BKvStore) Participant() *backend.Indexer {
+       return backend.Store().Entity(PARTICIPANT)
 }
 
-func (s *BKvStore) Version() *store.Indexer {
-       return store.Store().Entity(VERSION)
+func (s *BKvStore) Version() *backend.Indexer {
+       return backend.Store().Entity(VERSION)
 }
 
-func (s *BKvStore) Pact() *store.Indexer {
-       return store.Store().Entity(PACT)
+func (s *BKvStore) Pact() *backend.Indexer {
+       return backend.Store().Entity(PACT)
 }
 
-func (s *BKvStore) PactVersion() *store.Indexer {
-       return store.Store().Entity(PACT_VERSION)
+func (s *BKvStore) PactVersion() *backend.Indexer {
+       return backend.Store().Entity(PACT_VERSION)
 }
 
-func (s *BKvStore) PactTag() *store.Indexer {
-       return store.Store().Entity(PACT_TAG)
+func (s *BKvStore) PactTag() *backend.Indexer {
+       return backend.Store().Entity(PACT_TAG)
 }
 
-func (s *BKvStore) Verification() *store.Indexer {
-       return store.Store().Entity(VERIFICATION)
+func (s *BKvStore) Verification() *backend.Indexer {
+       return backend.Store().Entity(VERIFICATION)
 }
 
-func (s *BKvStore) PactLatest() *store.Indexer {
-       return store.Store().Entity(PACT_LATEST)
+func (s *BKvStore) PactLatest() *backend.Indexer {
+       return backend.Store().Entity(PACT_LATEST)
 }
 
 func Store() *BKvStore {
diff --git a/server/core/backend/backend.go b/server/core/backend/backend.go
index 9711e44c..8fe096d9 100644
--- a/server/core/backend/backend.go
+++ b/server/core/backend/backend.go
@@ -29,7 +29,6 @@ import (
 var (
        registryInstance registry.Registry
        singletonLock    sync.Mutex
-       wait_delay       = []int{1, 1, 5, 10, 20, 30, 60}
 )
 
 const (
@@ -65,10 +64,7 @@ func Registry() registry.Registry {
                                return registryInstance
                        }
 
-                       if i >= len(wait_delay) {
-                               i = len(wait_delay) - 1
-                       }
-                       t := time.Duration(wait_delay[i]) * time.Second
+                       t := util.GetBackoff().Delay(i)
                        util.Logger().Errorf(nil, "initialize service center 
failed, retry after %s", t)
                        <-time.After(t)
                }
diff --git a/server/core/backend/store/cache_kv.go 
b/server/core/backend/cache_kv.go
similarity index 97%
rename from server/core/backend/store/cache_kv.go
rename to server/core/backend/cache_kv.go
index 9fb347eb..2b46fe6c 100644
--- a/server/core/backend/store/cache_kv.go
+++ b/server/core/backend/cache_kv.go
@@ -14,11 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        "github.com/coreos/etcd/mvcc/mvccpb"
        "golang.org/x/net/context"
@@ -212,21 +211,23 @@ func (c *KvCacher) needDeferHandle(evts []KvEvent) bool {
 
 func (c *KvCacher) refresh(ctx context.Context) {
        util.Logger().Debugf("start to list and watch %s", c.Cfg)
+       retries := 0
        for {
-               start := time.Now()
-               c.ListAndWatch(ctx)
-               watchDuration := time.Since(start)
                nextPeriod := minWaitInterval
-               if watchDuration > 0 && c.Cfg.Period > watchDuration {
-                       nextPeriod = c.Cfg.Period - watchDuration
+               if err := c.ListAndWatch(ctx); err != nil {
+                       nextPeriod = util.GetBackoff().Delay(retries)
+                       retries++
+               } else {
+                       retries = 0
+
+                       ReportCacheMetrics(c.Name(), "raw", c.cache.RLock())
+                       c.cache.RUnlock()
                }
                select {
                case <-ctx.Done():
                        util.Logger().Debugf("stop to list and watch %s", c.Cfg)
                        return
                case <-time.After(nextPeriod):
-                       ReportCacheMetrics(c.Name(), "raw", c.cache.RLock())
-                       c.cache.RUnlock()
                }
        }
 }
@@ -503,7 +504,7 @@ func NewKvCacher(name string, opts ...ConfigOption) 
*KvCacher {
                Cfg:   cfg,
                ready: make(chan struct{}),
                lw: ListWatcher{
-                       Client: backend.Registry(),
+                       Client: Registry(),
                        Prefix: cfg.Prefix,
                },
                goroutine: util.NewGo(context.Background()),
diff --git a/server/core/backend/store/cache_null.go 
b/server/core/backend/cache_null.go
similarity index 98%
rename from server/core/backend/store/cache_null.go
rename to server/core/backend/cache_null.go
index 2025bffc..d6681aa5 100644
--- a/server/core/backend/store/cache_null.go
+++ b/server/core/backend/cache_null.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 var (
        NullCache  = &nullCache{}
diff --git a/server/core/backend/store/cacher.go b/server/core/backend/cacher.go
similarity index 98%
rename from server/core/backend/store/cacher.go
rename to server/core/backend/cacher.go
index 898964c8..410ef508 100644
--- a/server/core/backend/store/cacher.go
+++ b/server/core/backend/cacher.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 type Cache interface {
        Version() int64
diff --git a/server/core/backend/store/cacher_test.go 
b/server/core/backend/cacher_test.go
similarity index 99%
rename from server/core/backend/store/cacher_test.go
rename to server/core/backend/cacher_test.go
index 3225757e..9e06f6dd 100644
--- a/server/core/backend/store/cacher_test.go
+++ b/server/core/backend/cacher_test.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "encoding/json"
diff --git a/server/core/backend/store/common.go b/server/core/backend/common.go
similarity index 98%
rename from server/core/backend/store/common.go
rename to server/core/backend/common.go
index c9d92726..ed0727f3 100644
--- a/server/core/backend/store/common.go
+++ b/server/core/backend/common.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
@@ -124,7 +124,7 @@ const (
 const (
        DEFAULT_COMPACT_TIMES   = 3
        DEFAULT_COMPACT_TIMEOUT = 5 * time.Minute
-       minWaitInterval         = 100 * time.Millisecond
+       minWaitInterval         = 1 * time.Second
        eventBlockSize          = 1000
 )
 
diff --git a/server/core/backend/store/config.go b/server/core/backend/config.go
similarity index 99%
rename from server/core/backend/store/config.go
rename to server/core/backend/config.go
index 9f0b2dde..13e162d1 100644
--- a/server/core/backend/store/config.go
+++ b/server/core/backend/config.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "fmt"
diff --git a/server/core/backend/store/defer.go b/server/core/backend/defer.go
similarity index 98%
rename from server/core/backend/store/defer.go
rename to server/core/backend/defer.go
index da75b211..03edbe6f 100644
--- a/server/core/backend/store/defer.go
+++ b/server/core/backend/defer.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 type DeferHandler interface {
        OnCondition(Cache, []KvEvent) bool
diff --git a/server/core/backend/store/defer_instance.go 
b/server/core/backend/defer_instance.go
similarity index 99%
rename from server/core/backend/store/defer_instance.go
rename to server/core/backend/defer_instance.go
index 177d8aaa..d62afaee 100644
--- a/server/core/backend/store/defer_instance.go
+++ b/server/core/backend/defer_instance.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "encoding/json"
diff --git a/server/core/backend/store/defer_test.go 
b/server/core/backend/defer_test.go
similarity index 99%
rename from server/core/backend/store/defer_test.go
rename to server/core/backend/defer_test.go
index 4a034a6e..93acd971 100644
--- a/server/core/backend/store/defer_test.go
+++ b/server/core/backend/defer_test.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "encoding/json"
diff --git a/server/core/backend/store/event.go b/server/core/backend/event.go
similarity index 98%
rename from server/core/backend/store/event.go
rename to server/core/backend/event.go
index 67714a04..839dc7a6 100644
--- a/server/core/backend/store/event.go
+++ b/server/core/backend/event.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
diff --git a/server/core/backend/store/event_proxy.go 
b/server/core/backend/event_proxy.go
similarity index 98%
rename from server/core/backend/store/event_proxy.go
rename to server/core/backend/event_proxy.go
index e66583d9..592c70a7 100644
--- a/server/core/backend/store/event_proxy.go
+++ b/server/core/backend/event_proxy.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import "sync"
 
diff --git a/server/core/backend/store/extend.go b/server/core/backend/extend.go
similarity index 99%
rename from server/core/backend/store/extend.go
rename to server/core/backend/extend.go
index 90b053f5..200d45e5 100644
--- a/server/core/backend/store/extend.go
+++ b/server/core/backend/extend.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "errors"
diff --git a/server/core/backend/store/extend_test.go 
b/server/core/backend/extend_test.go
similarity index 98%
rename from server/core/backend/store/extend_test.go
rename to server/core/backend/extend_test.go
index 8359dd2e..6a37ce5c 100644
--- a/server/core/backend/store/extend_test.go
+++ b/server/core/backend/extend_test.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import "testing"
 
diff --git a/server/core/backend/store/indexer.go 
b/server/core/backend/indexer.go
similarity index 90%
rename from server/core/backend/store/indexer.go
rename to server/core/backend/indexer.go
index 2b35a976..48889e8b 100644
--- a/server/core/backend/store/indexer.go
+++ b/server/core/backend/indexer.go
@@ -14,11 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+       "github.com/apache/incubator-servicecomb-service-center/server/core"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "github.com/coreos/etcd/mvcc/mvccpb"
@@ -35,6 +35,7 @@ type Indexer struct {
        cacher           Cacher
        goroutine        *util.GoRoutine
        ready            chan struct{}
+       lastMaxSize      int
        prefixIndex      map[string]map[string]struct{}
        prefixBuildQueue chan KvEvent
        prefixLock       sync.RWMutex
@@ -46,12 +47,13 @@ func (i *Indexer) Search(ctx context.Context, opts 
...registry.PluginOpOption) (
 
        key := util.BytesToStringWithNoCopy(op.Key)
 
-       if op.Mode == registry.MODE_NO_CACHE ||
+       if !core.ServerInfo.Config.EnableCache ||
+               op.Mode == registry.MODE_NO_CACHE ||
                op.Revision > 0 ||
                (op.Offset >= 0 && op.Limit > 0) {
                util.Logger().Debugf("search %s match special options, request 
etcd server, opts: %s",
                        i.cacher.Name(), op)
-               return backend.Registry().Do(ctx, opts...)
+               return Registry().Do(ctx, opts...)
        }
 
        if op.Prefix {
@@ -66,7 +68,7 @@ func (i *Indexer) Search(ctx context.Context, opts 
...registry.PluginOpOption) (
 
                util.Logger().Debugf("can not find any key from %s cache with 
prefix, request etcd server, key: %s",
                        i.cacher.Name(), key)
-               return backend.Registry().Do(ctx, opts...)
+               return Registry().Do(ctx, opts...)
        }
 
        resp := &registry.PluginResponse{
@@ -86,7 +88,7 @@ func (i *Indexer) Search(ctx context.Context, opts 
...registry.PluginOpOption) (
                }
 
                util.Logger().Debugf("%s cache does not store this key, request 
etcd server, key: %s", i.cacher.Name(), key)
-               return backend.Registry().Do(ctx, opts...)
+               return Registry().Do(ctx, opts...)
        }
 
        cacheData := i.Cache().Data(key)
@@ -97,7 +99,7 @@ func (i *Indexer) Search(ctx context.Context, opts 
...registry.PluginOpOption) (
 
                util.Logger().Debugf("do not match any key in %s cache store, 
request etcd server, key: %s",
                        i.cacher.Name(), key)
-               return backend.Registry().Do(ctx, opts...)
+               return Registry().Do(ctx, opts...)
        }
 
        resp.Count = 1
@@ -195,18 +197,27 @@ func (i *Indexer) buildIndex() {
                                default:
                                        i.addPrefixKey(prefix, key)
                                }
-                               i.prefixLock.Unlock()
 
-                               util.LogNilOrWarnf(t, "too long to 
rebuild(action: %s) index[%d], key is %s",
-                                       evt.Type, key, len(i.prefixIndex))
-                       case <-time.After(10 * time.Second):
-                               i.prefixLock.Lock()
-                               if time.Now().Sub(lastCompactTime) >= 
DEFAULT_COMPACT_TIMEOUT {
+                               // compact
+                               initSize, l := DEFAULT_CACHE_INIT_SIZE, 
len(i.prefixIndex)
+                               if i.lastMaxSize < l {
+                                       i.lastMaxSize = l
+                               }
+                               if initSize >= l &&
+                                       i.lastMaxSize >= 
initSize*DEFAULT_COMPACT_TIMES &&
+                                       time.Now().Sub(lastCompactTime) >= 
DEFAULT_COMPACT_TIMEOUT {
                                        i.compact()
+                                       i.lastMaxSize = l
                                        lastCompactTime = time.Now()
                                }
+
+                               // report metrics
                                ReportCacheMetrics(i.cacher.Name(), "index", 
i.prefixIndex)
+
                                i.prefixLock.Unlock()
+
+                               util.LogNilOrWarnf(t, "too long to 
rebuild(action: %s) index[%d], key is %s",
+                                       evt.Type, key, len(i.prefixIndex))
                        }
                }
                util.Logger().Debugf("the goroutine building index %s is 
stopped", i.cacher.Name())
@@ -215,11 +226,7 @@ func (i *Indexer) buildIndex() {
 }
 
 func (i *Indexer) compact() {
-       l := len(i.prefixIndex)
-       if l < DEFAULT_CACHE_INIT_SIZE {
-               l = DEFAULT_CACHE_INIT_SIZE
-       }
-       n := make(map[string]map[string]struct{}, l)
+       n := make(map[string]map[string]struct{}, DEFAULT_CACHE_INIT_SIZE)
        for k, v := range i.prefixIndex {
                c, ok := n[k]
                if !ok {
@@ -232,8 +239,8 @@ func (i *Indexer) compact() {
        }
        i.prefixIndex = n
 
-       util.Logger().Infof("index %s(%s): compact root capacity to size %d",
-               i.cacher.Name(), DEFAULT_COMPACT_TIMEOUT, l)
+       util.Logger().Infof("index %s: compact root capacity to size %d",
+               i.cacher.Name(), DEFAULT_CACHE_INIT_SIZE)
 }
 
 func (i *Indexer) getPrefixKey(arr *[]string, prefix string) (count int) {
@@ -301,7 +308,7 @@ func (i *Indexer) Run() {
        i.isClose = false
        i.prefixLock.Unlock()
 
-       if _, ok := i.cacher.(*nullCacher); ok {
+       if !core.ServerInfo.Config.EnableCache {
                util.SafeCloseChan(i.ready)
                return
        }
diff --git a/server/core/backend/store/lease.go b/server/core/backend/lease.go
similarity index 93%
rename from server/core/backend/store/lease.go
rename to server/core/backend/lease.go
index d6ea7029..d52511c0 100644
--- a/server/core/backend/store/lease.go
+++ b/server/core/backend/lease.go
@@ -14,12 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        errorsEx 
"github.com/apache/incubator-servicecomb-service-center/pkg/errors"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "golang.org/x/net/context"
        "time"
@@ -41,7 +40,7 @@ func (lat *LeaseTask) Key() string {
 
 func (lat *LeaseTask) Do(ctx context.Context) (err error) {
        lat.StartTime = time.Now()
-       lat.TTL, err = backend.Registry().LeaseRenew(ctx, lat.LeaseID)
+       lat.TTL, err = Registry().LeaseRenew(ctx, lat.LeaseID)
        lat.EndTime = time.Now()
        if err != nil {
                util.Logger().Errorf(err, "[%s]renew lease %d failed(rev: %s, 
run: %s), key %s",
diff --git a/server/core/backend/store/listwatch.go 
b/server/core/backend/listwatch.go
similarity index 97%
rename from server/core/backend/store/listwatch.go
rename to server/core/backend/listwatch.go
index 42fbde52..43f31e4c 100644
--- a/server/core/backend/store/listwatch.go
+++ b/server/core/backend/listwatch.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "fmt"
@@ -71,7 +71,7 @@ func (lw *ListWatcher) doWatch(ctx context.Context, f 
func(evt []KvEvent)) error
                                        return fmt.Errorf("unknown event %s", 
resp)
                                }
 
-                               util.Logger().Infof("watch prefix %s, start rev 
%d+1, event: %s", lw.Prefix, rev, resp)
+                               util.Logger().Infof("caught event %s, watch 
prefix %s, start rev %d+1,", resp, lw.Prefix, rev)
 
                                lw.setRevision(resp.Revision)
 
diff --git a/server/core/backend/store/metric.go b/server/core/backend/metric.go
similarity index 93%
rename from server/core/backend/store/metric.go
rename to server/core/backend/metric.go
index 889e4dc0..79958cc8 100644
--- a/server/core/backend/store/metric.go
+++ b/server/core/backend/metric.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
@@ -43,6 +43,11 @@ func init() {
 }
 
 func ReportCacheMetrics(resource, t string, obj interface{}) {
+       if len(core.Instance.Endpoints) == 0 {
+               // endpoints list will be empty when initializing
+               return
+       }
+
        once.Do(func() {
                instance, _ = util.ParseEndpoint(core.Instance.Endpoints[0])
        })
diff --git a/server/core/backend/store/store.go b/server/core/backend/store.go
similarity index 99%
rename from server/core/backend/store/store.go
rename to server/core/backend/store.go
index 66849464..cecc1d12 100644
--- a/server/core/backend/store/store.go
+++ b/server/core/backend/store.go
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package store
+package backend
 
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/async"
diff --git a/server/core/info.go b/server/core/info.go
index 4a20dcc1..1d52697e 100644
--- a/server/core/info.go
+++ b/server/core/info.go
@@ -17,14 +17,8 @@
 package core
 
 import (
-       "encoding/json"
-       "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
-       
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
-       "github.com/apache/incubator-servicecomb-service-center/version"
        "github.com/astaxie/beego"
-       "golang.org/x/net/context"
 )
 
 var ServerInfo *pb.ServerInformation = newInfo()
@@ -78,36 +72,3 @@ func newInfo() *pb.ServerInformation {
                },
        }
 }
-
-func LoadServerInformation() error {
-       resp, err := backend.Registry().Do(context.Background(),
-               registry.GET, registry.WithStrKey(GetSystemKey()))
-       if err != nil {
-               return err
-       }
-       if len(resp.Kvs) == 0 {
-               return nil
-       }
-
-       err = json.Unmarshal(resp.Kvs[0].Value, ServerInfo)
-       if err != nil {
-               util.Logger().Errorf(err, "load system config failed, maybe 
incompatible")
-               return nil
-       }
-       return nil
-}
-
-func UpgradeServerVersion() error {
-       ServerInfo.Version = version.Ver().Version
-
-       bytes, err := json.Marshal(ServerInfo)
-       if err != nil {
-               return err
-       }
-       _, err = backend.Registry().Do(context.Background(),
-               registry.PUT, registry.WithStrKey(GetSystemKey()), 
registry.WithValue(bytes))
-       if err != nil {
-               return err
-       }
-       return nil
-}
diff --git a/server/core/key_generator.go b/server/core/key_generator.go
index 67119f1a..8f2f6d7f 100644
--- a/server/core/key_generator.go
+++ b/server/core/key_generator.go
@@ -328,7 +328,7 @@ func GenerateDomainKey(domain string) string {
        }, "/")
 }
 
-func GetSystemKey() string {
+func GetServerInfoKey() string {
        return util.StringJoin([]string{
                GetRootKey(),
                REGISTRY_SYS_KEY,
diff --git a/server/govern/service.go b/server/govern/service.go
index 7209948c..bdaabc8d 100644
--- a/server/govern/service.go
+++ b/server/govern/service.go
@@ -19,7 +19,7 @@ package govern
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -187,7 +187,7 @@ func (governService *GovernService) GetApplications(ctx 
context.Context, in *pb.
                registry.WithPrefix(),
                registry.WithKeyOnly())
 
-       resp, err := store.Store().ServiceIndex().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceIndex().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -223,7 +223,7 @@ func getServiceAllVersions(ctx context.Context, serviceKey 
*pb.MicroServiceKey)
                registry.WithStrKey(key),
                registry.WithPrefix())
 
-       resp, err := store.Store().ServiceIndex().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceIndex().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -244,7 +244,7 @@ func getSchemaInfoUtil(ctx context.Context, domainProject 
string, serviceId stri
                registry.WithStrKey(key),
                registry.WithPrefix())
 
-       resp, err := store.Store().Schema().Search(ctx, opts...)
+       resp, err := backend.Store().Schema().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "Get schema failed")
                return make([]*pb.Schema, 0), err
@@ -355,7 +355,7 @@ func statistics(ctx context.Context) (*pb.Statistics, 
error) {
        svcOpts := append(opts,
                registry.WithStrKey(key),
                registry.WithPrefix())
-       respSvc, err := store.Store().ServiceIndex().Search(ctx, svcOpts...)
+       respSvc, err := backend.Store().ServiceIndex().Search(ctx, svcOpts...)
        if err != nil {
                return nil, err
        }
@@ -391,7 +391,7 @@ func statistics(ctx context.Context) (*pb.Statistics, 
error) {
                registry.WithStrKey(key),
                registry.WithPrefix(),
                registry.WithKeyOnly())
-       respIns, err := store.Store().Instance().Search(ctx, instOpts...)
+       respIns, err := backend.Store().Instance().Search(ctx, instOpts...)
        if err != nil {
                return nil, err
        }
@@ -432,7 +432,7 @@ func getInstanceCountByDomain(ctx context.Context, resp 
chan GetInstanceCountByD
                registry.WithPrefix(),
                registry.WithKeyOnly(),
                registry.WithCountOnly())
-       respIns, err := store.Store().Instance().Search(ctx, instOpts...)
+       respIns, err := backend.Store().Instance().Search(ctx, instOpts...)
        if err != nil {
                util.Logger().Errorf(err, "get instance count under same 
domainId %s", domainId)
        }
diff --git a/server/handler/cache/cache.go b/server/handler/cache/cache.go
index f6674f31..8b119926 100644
--- a/server/handler/cache/cache.go
+++ b/server/handler/cache/cache.go
@@ -20,7 +20,7 @@ import (
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/chain"
        "github.com/apache/incubator-servicecomb-service-center/pkg/rest"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        "net/http"
        "strconv"
 )
@@ -32,7 +32,7 @@ func (l *CacheResponse) Handle(i *chain.Invocation) {
        r := i.Context().Value(rest.CTX_REQUEST).(*http.Request)
        w := i.Context().Value(rest.CTX_RESPONSE).(http.ResponseWriter)
 
-       scRev := store.Revision()
+       scRev := backend.Revision()
        w.Header().Set("X-Resource-Revision", fmt.Sprint(scRev))
 
        rev, _ := strconv.ParseInt(r.URL.Query().Get("rev"), 10, 64)
diff --git a/server/plugin/infra/quota/buildin/buildin.go 
b/server/plugin/infra/quota/buildin/buildin.go
index d7082916..0f947a13 100644
--- a/server/plugin/infra/quota/buildin/buildin.go
+++ b/server/plugin/infra/quota/buildin/buildin.go
@@ -20,7 +20,7 @@ import (
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -85,7 +85,7 @@ func (q *BuildInQuota) RemandQuotas(ctx context.Context, 
quotaType quota.Resourc
 func ResourceLimitHandler(ctx context.Context, res *quota.ApplyQuotaResource) 
*quota.ApplyQuotaResult {
        var key string
        var max int64 = 0
-       var indexer *store.Indexer
+       var indexer *backend.Indexer
 
        domainProject := res.DomainProject
        serviceId := res.ServiceId
@@ -93,11 +93,11 @@ func ResourceLimitHandler(ctx context.Context, res 
*quota.ApplyQuotaResource) *q
        case quota.RuleQuotaType:
                key = core.GenerateServiceRuleKey(domainProject, serviceId, "")
                max = RULE_NUM_MAX_LIMIT_PER_SERVICE
-               indexer = store.Store().Rule()
+               indexer = backend.Store().Rule()
        case quota.SchemaQuotaType:
                key = core.GenerateServiceSchemaKey(domainProject, serviceId, 
"")
                max = SCHEMA_NUM_MAX_LIMIT_PER_SERVICE
-               indexer = store.Store().Schema()
+               indexer = backend.Store().Schema()
        case quota.TagQuotaType:
                applyNum := res.QuotaSize
                max = TAG_NUM_MAX_LIMIT_PER_SERVICE
@@ -193,7 +193,7 @@ func getInstanceMaxLimit() int64 {
 }
 
 func getInstancesNum(ctx context.Context, key string) (int64, error) {
-       resp, err := store.Store().Instance().Search(ctx,
+       resp, err := backend.Store().Instance().Search(ctx,
                registry.WithStrKey(key),
                registry.WithPrefix(),
                registry.WithCountOnly())
@@ -229,7 +229,7 @@ func getServiceMaxLimit() int64 {
 }
 
 func getServicesNum(ctx context.Context, key string) (int64, error) {
-       resp, err := store.Store().Service().Search(ctx,
+       resp, err := backend.Store().Service().Search(ctx,
                registry.WithStrKey(key),
                registry.WithPrefix(),
                registry.WithCountOnly())
diff --git a/server/plugin/infra/registry/embededetcd/embededetcd.go 
b/server/plugin/infra/registry/embededetcd/embededetcd.go
index 3bb71401..e9be1f33 100644
--- a/server/plugin/infra/registry/embededetcd/embededetcd.go
+++ b/server/plugin/infra/registry/embededetcd/embededetcd.go
@@ -41,7 +41,7 @@ import (
 
 var embedTLSConfig *tls.Config
 
-const START_MANAGER_SERVER_TIMEOUT = 10
+const START_MANAGER_SERVER_TIMEOUT = 10 * time.Second
 
 func init() {
        mgr.RegisterPlugin(mgr.Plugin{mgr.REGISTRY, "embeded_etcd", 
getEmbedInstance})
@@ -458,7 +458,7 @@ func (s *EtcdEmbed) Watch(ctx context.Context, opts 
...registry.PluginOpOption)
 }
 
 func (s *EtcdEmbed) ReadyNotify() {
-       timeout := START_MANAGER_SERVER_TIMEOUT * time.Second
+       timeout := START_MANAGER_SERVER_TIMEOUT
        select {
        case <-s.Embed.Server.ReadyNotify():
                close(s.ready)
diff --git a/server/plugin/infra/registry/etcd/logger.go 
b/server/plugin/infra/registry/etcd/logger.go
index 952834bc..c0e35ba1 100644
--- a/server/plugin/infra/registry/etcd/logger.go
+++ b/server/plugin/infra/registry/etcd/logger.go
@@ -21,7 +21,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "github.com/coreos/pkg/capnslog"
        "runtime"
-       "strings"
 )
 
 // clientLogger implement from grcplog.LoggerV2s and capnslog.Formatter
@@ -45,13 +44,7 @@ func (l *clientLogger) getCaller(depth int) string {
        if !ok {
                return "???"
        }
-
-       if sp1 := strings.LastIndex(file, "/"); sp1 >= 0 {
-               if sp2 := strings.LastIndex(file[:sp1], "/"); sp2 >= 0 {
-                       file = file[sp2+1:]
-               }
-       }
-       return fmt.Sprintf("%s:%d", file, line)
+       return fmt.Sprintf("%s:%d", util.FileLastName(file), line)
 }
 
 func (l *clientLogger) Flush() {
diff --git a/server/plugin/infra/tracing/buildin/common.go 
b/server/plugin/infra/tracing/buildin/common.go
index 16535373..ad9fff76 100644
--- a/server/plugin/infra/tracing/buildin/common.go
+++ b/server/plugin/infra/tracing/buildin/common.go
@@ -30,7 +30,7 @@ import (
 func initTracer() {
        collector, err := newCollector()
        if err != nil {
-               util.Logger().Errorf(err, "new tracing collector failed, use 
the noop tracer")
+               util.Logger().Warnf(err, "new tracing collector failed, use the 
noop tracer")
                return
        }
        ipPort, _ := util.ParseEndpoint(core.Instance.Endpoints[0])
diff --git a/server/server.go b/server/server.go
index 611b83c8..7e98b6a1 100644
--- a/server/server.go
+++ b/server/server.go
@@ -18,11 +18,12 @@ package server
 
 import _ 
"github.com/apache/incubator-servicecomb-service-center/server/service/event"
 import (
+       "encoding/json"
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       st 
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "github.com/apache/incubator-servicecomb-service-center/server/mux"
        nf 
"github.com/apache/incubator-servicecomb-service-center/server/service/notification"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
@@ -42,7 +43,7 @@ var (
 
 func init() {
        server = &ServiceCenterServer{
-               store:         st.Store(),
+               store:         backend.Store(),
                notifyService: nf.GetNotifyService(),
                apiServer:     GetAPIServer(),
                goroutine:     util.NewGo(context.Background()),
@@ -52,7 +53,7 @@ func init() {
 type ServiceCenterServer struct {
        apiServer     *APIServer
        notifyService *nf.NotifyService
-       store         *st.KvStore
+       store         *backend.KvStore
        goroutine     *util.GoRoutine
 }
 
@@ -81,9 +82,42 @@ func (s *ServiceCenterServer) waitForQuit() {
        util.Logger().Debugf("service center stopped")
 }
 
+func LoadServerInformation() error {
+       resp, err := backend.Registry().Do(context.Background(),
+               registry.GET, registry.WithStrKey(core.GetServerInfoKey()))
+       if err != nil {
+               return err
+       }
+       if len(resp.Kvs) == 0 {
+               return nil
+       }
+
+       err = json.Unmarshal(resp.Kvs[0].Value, core.ServerInfo)
+       if err != nil {
+               util.Logger().Errorf(err, "load system config failed, maybe 
incompatible")
+               return nil
+       }
+       return nil
+}
+
+func UpgradeServerVersion() error {
+       core.ServerInfo.Version = version.Ver().Version
+
+       bytes, err := json.Marshal(core.ServerInfo)
+       if err != nil {
+               return err
+       }
+       _, err = backend.Registry().Do(context.Background(),
+               registry.PUT, registry.WithStrKey(core.GetServerInfoKey()), 
registry.WithValue(bytes))
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
 func (s *ServiceCenterServer) needUpgrade() bool {
        if core.ServerInfo.Version == "0" {
-               err := core.LoadServerInformation()
+               err := LoadServerInformation()
                if err != nil {
                        util.Logger().Errorf(err, "check version failed, can 
not load the system config")
                        return false
@@ -102,7 +136,7 @@ func (s *ServiceCenterServer) initialize() {
                os.Exit(1)
        }
        if s.needUpgrade() {
-               core.UpgradeServerVersion()
+               UpgradeServerVersion()
        }
 
        // cache mechanism
diff --git a/server/service/event/dependency_event_handler.go 
b/server/service/event/dependency_event_handler.go
index 836008ba..66677208 100644
--- a/server/service/event/dependency_event_handler.go
+++ b/server/service/event/dependency_event_handler.go
@@ -22,7 +22,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "github.com/apache/incubator-servicecomb-service-center/server/mux"
@@ -36,11 +35,11 @@ type DependencyEventHandler struct {
        signals *util.UniQueue
 }
 
-func (h *DependencyEventHandler) Type() store.StoreType {
-       return store.DEPENDENCY_QUEUE
+func (h *DependencyEventHandler) Type() backend.StoreType {
+       return backend.DEPENDENCY_QUEUE
 }
 
-func (h *DependencyEventHandler) OnEvent(evt store.KvEvent) {
+func (h *DependencyEventHandler) OnEvent(evt backend.KvEvent) {
        action := evt.Type
        if action != pb.EVT_CREATE && action != pb.EVT_UPDATE && action != 
pb.EVT_INIT {
                return
@@ -51,14 +50,10 @@ func (h *DependencyEventHandler) OnEvent(evt store.KvEvent) 
{
 
 func (h *DependencyEventHandler) loop() {
        util.Go(func(ctx context.Context) {
-               waitDelayIndex := 0
-               waitDelay := []int{1, 1, 5, 10, 20, 30, 60}
-               retry := func() {
-                       if waitDelayIndex >= len(waitDelay) {
-                               waitDelayIndex = 0
-                       }
-                       <-time.After(time.Duration(waitDelay[waitDelayIndex]) * 
time.Second)
-                       waitDelayIndex++
+               retries := 0
+               delay := func() {
+                       <-time.After(util.GetBackoff().Delay(retries))
+                       retries++
 
                        h.signals.Put(context.Background(), struct{}{})
                }
@@ -70,11 +65,12 @@ func (h *DependencyEventHandler) loop() {
                                lock, err := mux.Try(mux.DEP_QUEUE_LOCK)
                                if err != nil {
                                        util.Logger().Errorf(err, "try to lock 
%s failed", mux.DEP_QUEUE_LOCK)
-                                       retry()
+                                       delay()
                                        continue
                                }
 
                                if lock == nil {
+                                       retries = 0
                                        continue
                                }
 
@@ -82,9 +78,11 @@ func (h *DependencyEventHandler) loop() {
                                lock.Unlock()
                                if err != nil {
                                        util.Logger().Errorf(err, "handle 
dependency event failed")
-                                       retry()
+                                       delay()
                                        continue
                                }
+
+                               retries = 0
                        }
                }
        })
@@ -115,7 +113,7 @@ func isAddToLeft(centerNode *util.Node, addRes interface{}) 
bool {
 
 func (h *DependencyEventHandler) Handle() error {
        key := core.GetServiceDependencyQueueRootKey("")
-       resp, err := 
store.Store().DependencyQueue().Search(context.Background(),
+       resp, err := 
backend.Store().DependencyQueue().Search(context.Background(),
                registry.WithStrKey(key),
                registry.WithPrefix())
        if err != nil {
diff --git a/server/service/event/event.go b/server/service/event/event.go
index 53fe882b..271d50be 100644
--- a/server/service/event/event.go
+++ b/server/service/event/event.go
@@ -17,13 +17,13 @@
 package event
 
 import (
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
 )
 
 func init() {
-       store.AddEventHandler(NewServiceEventHandler())
-       store.AddEventHandler(NewInstanceEventHandler())
-       store.AddEventHandler(NewRuleEventHandler())
-       store.AddEventHandler(NewTagEventHandler())
-       store.AddEventHandler(NewDependencyEventHandler())
+       backend.AddEventHandler(NewServiceEventHandler())
+       backend.AddEventHandler(NewInstanceEventHandler())
+       backend.AddEventHandler(NewRuleEventHandler())
+       backend.AddEventHandler(NewTagEventHandler())
+       backend.AddEventHandler(NewDependencyEventHandler())
 }
diff --git a/server/service/event/instance_event_handler.go 
b/server/service/event/instance_event_handler.go
index e9ee8b7b..e52e4572 100644
--- a/server/service/event/instance_event_handler.go
+++ b/server/service/event/instance_event_handler.go
@@ -20,7 +20,7 @@ import (
        "encoding/json"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        nf 
"github.com/apache/incubator-servicecomb-service-center/server/service/notification"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
@@ -32,11 +32,11 @@ import (
 type InstanceEventHandler struct {
 }
 
-func (h *InstanceEventHandler) Type() store.StoreType {
-       return store.INSTANCE
+func (h *InstanceEventHandler) Type() backend.StoreType {
+       return backend.INSTANCE
 }
 
-func (h *InstanceEventHandler) OnEvent(evt store.KvEvent) {
+func (h *InstanceEventHandler) OnEvent(evt backend.KvEvent) {
        action := evt.Type
        if action == pb.EVT_INIT {
                return
diff --git a/server/service/event/rule_event_handler.go 
b/server/service/event/rule_event_handler.go
index 07cc316f..42e131fd 100644
--- a/server/service/event/rule_event_handler.go
+++ b/server/service/event/rule_event_handler.go
@@ -21,7 +21,7 @@ import (
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/async"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        nf 
"github.com/apache/incubator-servicecomb-service-center/server/service/notification"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
@@ -77,11 +77,11 @@ func (apt *RulesChangedTask) publish(ctx context.Context, 
domainProject, provide
 type RuleEventHandler struct {
 }
 
-func (h *RuleEventHandler) Type() store.StoreType {
-       return store.RULE
+func (h *RuleEventHandler) Type() backend.StoreType {
+       return backend.RULE
 }
 
-func (h *RuleEventHandler) OnEvent(evt store.KvEvent) {
+func (h *RuleEventHandler) OnEvent(evt backend.KvEvent) {
        action := evt.Type
        if action == pb.EVT_INIT {
                return
diff --git a/server/service/event/service_event_handler.go 
b/server/service/event/service_event_handler.go
index 8ffd805e..45392f17 100644
--- a/server/service/event/service_event_handler.go
+++ b/server/service/event/service_event_handler.go
@@ -18,7 +18,7 @@ package event
 
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
        "github.com/coreos/etcd/mvcc/mvccpb"
@@ -29,11 +29,11 @@ import (
 type ServiceEventHandler struct {
 }
 
-func (h *ServiceEventHandler) Type() store.StoreType {
-       return store.SERVICE
+func (h *ServiceEventHandler) Type() backend.StoreType {
+       return backend.SERVICE
 }
 
-func (h *ServiceEventHandler) OnEvent(evt store.KvEvent) {
+func (h *ServiceEventHandler) OnEvent(evt backend.KvEvent) {
        action := evt.Type
        if action != pb.EVT_CREATE && action != pb.EVT_INIT {
                return
diff --git a/server/service/event/tag_event_handler.go 
b/server/service/event/tag_event_handler.go
index cf2afa70..ef2968a0 100644
--- a/server/service/event/tag_event_handler.go
+++ b/server/service/event/tag_event_handler.go
@@ -21,7 +21,7 @@ import (
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/async"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        nf 
"github.com/apache/incubator-servicecomb-service-center/server/service/notification"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
@@ -88,11 +88,11 @@ func (apt *TagsChangedTask) publish(ctx context.Context, 
domainProject, consumer
 type TagEventHandler struct {
 }
 
-func (h *TagEventHandler) Type() store.StoreType {
-       return store.SERVICE_TAG
+func (h *TagEventHandler) Type() backend.StoreType {
+       return backend.SERVICE_TAG
 }
 
-func (h *TagEventHandler) OnEvent(evt store.KvEvent) {
+func (h *TagEventHandler) OnEvent(evt backend.KvEvent) {
        action := evt.Type
        if action == pb.EVT_INIT {
                return
diff --git a/server/service/instances.go b/server/service/instances.go
index ffb40765..33d64e20 100644
--- a/server/service/instances.go
+++ b/server/service/instances.go
@@ -180,15 +180,12 @@ func (s *InstanceService) Register(ctx context.Context, 
in *pb.RegisterInstanceR
        // build the request options
        key := apt.GenerateInstanceKey(domainProject, instance.ServiceId, 
instanceId)
        hbKey := apt.GenerateInstanceLeaseKey(domainProject, 
instance.ServiceId, instanceId)
-       epKey := 
util.StringToBytesWithNoCopy(apt.GenerateEndpointsIndexKey(domainProject, 
instance))
 
        opts := []registry.PluginOp{
                registry.OpPut(registry.WithStrKey(key), 
registry.WithValue(data),
                        registry.WithLease(leaseID)),
                registry.OpPut(registry.WithStrKey(hbKey), 
registry.WithStrValue(fmt.Sprintf("%d", leaseID)),
                        registry.WithLease(leaseID)),
-               registry.OpPut(registry.WithKey(epKey), 
registry.WithStrValue(instance.ServiceId+"/"+instanceId),
-                       registry.WithLease(leaseID)),
        }
 
        _, err = backend.Registry().Txn(ctx, opts)
diff --git a/server/service/instances_test.go b/server/service/instances_test.go
index 9c91841b..e4723d7d 100644
--- a/server/service/instances_test.go
+++ b/server/service/instances_test.go
@@ -115,15 +115,6 @@ var _ = Describe("'Instance' service", func() {
                                })
                                Expect(err).To(BeNil())
                                
Expect(resp.Response.Code).To(Equal(pb.Response_SUCCESS))
-
-                               instance.InstanceId = ""
-                               instance.ServiceId = serviceId2
-                               resp, err = 
instanceResource.Register(getContext(), &pb.RegisterInstanceRequest{
-                                       Instance: instance,
-                               })
-                               Expect(err).To(BeNil())
-                               
Expect(resp.Response.Code).To(Equal(scerr.ErrEndpointAlreadyExists))
-
                        })
                })
 
diff --git a/server/service/microservices.go b/server/service/microservices.go
index 6663ab99..2b83b7b8 100644
--- a/server/service/microservices.go
+++ b/server/service/microservices.go
@@ -24,7 +24,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/server/core"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
@@ -237,7 +236,7 @@ func (s *MicroServiceService) DeleteServicePri(ctx 
context.Context, serviceId st
                }
 
                instancesKey := apt.GenerateInstanceKey(domainProject, 
serviceId, "")
-               rsp, err := store.Store().Instance().Search(ctx,
+               rsp, err := backend.Store().Instance().Search(ctx,
                        registry.WithStrKey(instancesKey),
                        registry.WithPrefix(),
                        registry.WithCountOnly())
diff --git a/server/service/schema.go b/server/service/schema.go
index dd9c4d9c..df66d155 100644
--- a/server/service/schema.go
+++ b/server/service/schema.go
@@ -21,7 +21,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
@@ -59,7 +58,7 @@ func (s *MicroServiceService) GetSchemaInfo(ctx 
context.Context, in *pb.GetSchem
 
        key := apt.GenerateServiceSchemaKey(domainProject, in.ServiceId, 
in.SchemaId)
        opts := append(serviceUtil.FromContext(ctx), registry.WithStrKey(key))
-       resp, errDo := store.Store().Schema().Search(ctx, opts...)
+       resp, errDo := backend.Store().Schema().Search(ctx, opts...)
        if errDo != nil {
                util.Logger().Errorf(errDo, "get schema failed, serviceId %s, 
schemaId %s: get schema info failed.", in.ServiceId, in.SchemaId)
                return &pb.GetSchemaResponse{
@@ -130,7 +129,7 @@ func (s *MicroServiceService) GetAllSchemaInfo(ctx 
context.Context, in *pb.GetAl
 
        key := apt.GenerateServiceSchemaSummaryKey(domainProject, in.ServiceId, 
"")
        opts := append(serviceUtil.FromContext(ctx), registry.WithStrKey(key), 
registry.WithPrefix())
-       resp, errDo := store.Store().SchemaSummary().Search(ctx, opts...)
+       resp, errDo := backend.Store().SchemaSummary().Search(ctx, opts...)
        if errDo != nil {
                util.Logger().Errorf(errDo, "get schema failed, serviceId %s: 
get schema info failed.", in.ServiceId)
                return &pb.GetAllSchemaResponse{
@@ -142,7 +141,7 @@ func (s *MicroServiceService) GetAllSchemaInfo(ctx 
context.Context, in *pb.GetAl
        if in.WithSchema {
                key := apt.GenerateServiceSchemaKey(domainProject, 
in.ServiceId, "")
                opts := append(serviceUtil.FromContext(ctx), 
registry.WithStrKey(key), registry.WithPrefix())
-               respWithSchema, errDo = store.Store().Schema().Search(ctx, 
opts...)
+               respWithSchema, errDo = backend.Store().Schema().Search(ctx, 
opts...)
                if errDo != nil {
                        util.Logger().Errorf(errDo, "get schema failed, 
serviceId %s: get schema info failed.", in.ServiceId)
                        return &pb.GetAllSchemaResponse{
@@ -565,7 +564,7 @@ func (s *MicroServiceService) modifySchema(ctx 
context.Context, serviceId string
                }
 
                key := apt.GenerateServiceSchemaKey(domainProject, serviceId, 
schemaId)
-               respSchema, err := store.Store().Schema().Search(ctx, 
registry.WithStrKey(key), registry.WithCountOnly())
+               respSchema, err := backend.Store().Schema().Search(ctx, 
registry.WithStrKey(key), registry.WithCountOnly())
                if err != nil {
                        util.Logger().Errorf(err, "modify schema failed, get 
schema summary failed, %s %s", serviceId, schemaId)
                        return scerr.NewError(scerr.ErrInternal, "get schema 
summary failed")
@@ -622,7 +621,7 @@ func (s *MicroServiceService) modifySchema(ctx 
context.Context, serviceId string
 
 func isExistSchemaSummary(ctx context.Context, domainProject, serviceId, 
schemaId string) (bool, error) {
        key := apt.GenerateServiceSchemaSummaryKey(domainProject, serviceId, 
schemaId)
-       resp, err := store.Store().SchemaSummary().Search(ctx, 
registry.WithStrKey(key), registry.WithCountOnly())
+       resp, err := backend.Store().SchemaSummary().Search(ctx, 
registry.WithStrKey(key), registry.WithCountOnly())
        if err != nil {
                return true, err
        }
@@ -656,7 +655,7 @@ func containsValueInSlice(in []string, value string) bool {
 
 func getSchemaSummary(ctx context.Context, domainProject string, serviceId 
string, schemaId string) (string, error) {
        key := apt.GenerateServiceSchemaSummaryKey(domainProject, serviceId, 
schemaId)
-       resp, err := store.Store().SchemaSummary().Search(ctx,
+       resp, err := backend.Store().SchemaSummary().Search(ctx,
                registry.WithStrKey(key),
        )
        if err != nil {
diff --git a/server/service/util/dependency.go 
b/server/service/util/dependency.go
index 0803901c..330473ae 100644
--- a/server/service/util/dependency.go
+++ b/server/service/util/dependency.go
@@ -23,7 +23,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -219,7 +218,7 @@ func TransferToMicroServiceDependency(ctx context.Context, 
key string) (*pb.Micr
        }
 
        opts := append(FromContext(ctx), registry.WithStrKey(key))
-       res, err := store.Store().DependencyRule().Search(ctx, opts...)
+       res, err := backend.Store().DependencyRule().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(nil, "Get dependency rule failed.")
                return nil, err
@@ -802,7 +801,7 @@ func (dr *DependencyRelation) 
parseDependencyRule(dependencyRule *pb.MicroServic
                sopts := append(opts,
                        registry.WithStrKey(allServiceKey),
                        registry.WithPrefix())
-               resp, err := store.Store().Service().Search(dr.ctx, sopts...)
+               resp, err := backend.Store().Service().Search(dr.ctx, sopts...)
                if err != nil {
                        return nil, err
                }
@@ -908,7 +907,7 @@ func (dr *DependencyRelation) 
getConsumerOfDependAllServices() ([]*pb.MicroServi
        providerService.ServiceName = "*"
        relyAllKey := apt.GenerateProviderDependencyRuleKey(dr.domainProject, 
providerService)
        opts := append(FromContext(dr.ctx), registry.WithStrKey(relyAllKey))
-       rsp, err := store.Store().DependencyRule().Search(dr.ctx, opts...)
+       rsp, err := backend.Store().DependencyRule().Search(dr.ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "get consumer that rely all service 
failed.")
                return nil, err
@@ -934,7 +933,7 @@ func (dr *DependencyRelation) 
getConsumerOfSameServiceNameAndAppId(provider *pb.
        opts := append(FromContext(dr.ctx),
                registry.WithStrKey(prefix),
                registry.WithPrefix())
-       rsp, err := store.Store().DependencyRule().Search(dr.ctx, opts...)
+       rsp, err := backend.Store().DependencyRule().Search(dr.ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "get all dependency rule failed: 
provider rule key %v.", provider)
                return nil, err
diff --git a/server/service/util/domain_util.go 
b/server/service/util/domain_util.go
index caadc787..acd49a5d 100644
--- a/server/service/util/domain_util.go
+++ b/server/service/util/domain_util.go
@@ -20,7 +20,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "github.com/coreos/etcd/mvcc/mvccpb"
        "golang.org/x/net/context"
@@ -31,7 +30,7 @@ func GetAllDomainRawData(ctx context.Context) 
([]*mvccpb.KeyValue, error) {
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateDomainKey("")),
                registry.WithPrefix())
-       rsp, err := store.Store().Domain().Search(ctx, opts...)
+       rsp, err := backend.Store().Domain().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -66,7 +65,7 @@ func DomainExist(ctx context.Context, domain string) (bool, 
error) {
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateDomainKey(domain)),
                registry.WithCountOnly())
-       rsp, err := store.Store().Domain().Search(ctx, opts...)
+       rsp, err := backend.Store().Domain().Search(ctx, opts...)
        if err != nil {
                return false, err
        }
@@ -77,7 +76,7 @@ func ProjectExist(ctx context.Context, domain, project 
string) (bool, error) {
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateProjectKey(domain, project)),
                registry.WithCountOnly())
-       rsp, err := store.Store().Project().Search(ctx, opts...)
+       rsp, err := backend.Store().Project().Search(ctx, opts...)
        if err != nil {
                return false, err
        }
diff --git a/server/service/util/heartbeat_util.go 
b/server/service/util/heartbeat_util.go
index 6ea83280..7f8a675d 100644
--- a/server/service/util/heartbeat_util.go
+++ b/server/service/util/heartbeat_util.go
@@ -19,7 +19,7 @@ package util
 import (
        "errors"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "golang.org/x/net/context"
 )
@@ -37,7 +37,7 @@ func KeepAliveLease(ctx context.Context, domainProject, 
serviceId, instanceId st
        if leaseID == -1 {
                return ttl, errors.New("leaseId not exist, instance not exist.")
        }
-       ttl, err = store.Store().KeepAlive(ctx,
+       ttl, err = backend.Store().KeepAlive(ctx,
                registry.WithStrKey(apt.GenerateInstanceLeaseKey(domainProject, 
serviceId, instanceId)),
                registry.WithLease(leaseID))
        if err != nil {
diff --git a/server/service/util/instance_util.go 
b/server/service/util/instance_util.go
index a6a0b8b8..4e7b8cf2 100644
--- a/server/service/util/instance_util.go
+++ b/server/service/util/instance_util.go
@@ -18,11 +18,9 @@ package util
 
 import (
        "encoding/json"
-       "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -36,7 +34,7 @@ import (
 func GetLeaseId(ctx context.Context, domainProject string, serviceId string, 
instanceId string) (int64, error) {
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateInstanceLeaseKey(domainProject, 
serviceId, instanceId)))
-       resp, err := store.Store().Lease().Search(ctx, opts...)
+       resp, err := backend.Store().Lease().Search(ctx, opts...)
        if err != nil {
                return -1, err
        }
@@ -51,7 +49,7 @@ func GetInstance(ctx context.Context, domainProject string, 
serviceId string, in
        key := apt.GenerateInstanceKey(domainProject, serviceId, instanceId)
        opts := append(FromContext(ctx), registry.WithStrKey(key))
 
-       resp, err := store.Store().Instance().Search(ctx, opts...)
+       resp, err := backend.Store().Instance().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -70,7 +68,7 @@ func GetInstance(ctx context.Context, domainProject string, 
serviceId string, in
 func GetAllInstancesOfOneService(ctx context.Context, domainProject string, 
serviceId string) ([]*pb.MicroServiceInstance, error) {
        key := apt.GenerateInstanceKey(domainProject, serviceId, "")
        opts := append(FromContext(ctx), registry.WithStrKey(key), 
registry.WithPrefix())
-       resp, err := store.Store().Instance().Search(ctx, opts...)
+       resp, err := backend.Store().Instance().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "Get instance of service %s from etcd 
failed.", serviceId)
                return nil, err
@@ -95,7 +93,7 @@ func GetInstanceCountOfOneService(ctx context.Context, 
domainProject string, ser
                registry.WithStrKey(key),
                registry.WithPrefix(),
                registry.WithCountOnly())
-       resp, err := store.Store().Instance().Search(ctx, opts...)
+       resp, err := backend.Store().Instance().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "Get instance count of service %s 
from etcd failed.", serviceId)
                return 0, err
@@ -107,7 +105,7 @@ func InstanceExistById(ctx context.Context, domainProject 
string, serviceId stri
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateInstanceKey(domainProject, 
serviceId, instanceId)),
                registry.WithCountOnly())
-       resp, err := store.Store().Instance().Search(ctx, opts...)
+       resp, err := backend.Store().Instance().Search(ctx, opts...)
        if err != nil {
                return false, err
        }
@@ -129,23 +127,7 @@ func InstanceExist(ctx context.Context, instance 
*pb.MicroServiceInstance) (stri
                        return instance.InstanceId, nil
                }
        }
-
-       // check endpoint index
-       resp, err := store.Store().Endpoints().Search(ctx,
-               
registry.WithStrKey(apt.GenerateEndpointsIndexKey(domainProject, instance)))
-       if err != nil {
-               return "", scerr.NewError(scerr.ErrInternal, err.Error())
-       }
-       if resp.Count == 0 {
-               return "", nil
-       }
-       endpointValue := ParseEndpointIndexValue(resp.Kvs[0].Value)
-       if instance.ServiceId != endpointValue.serviceId {
-               return endpointValue.instanceId,
-                       scerr.NewError(scerr.ErrEndpointAlreadyExists,
-                               fmt.Sprintf("Find the same endpoints in service 
%s", endpointValue.serviceId))
-       }
-       return endpointValue.instanceId, nil
+       return "", nil
 }
 
 type EndpointIndexValue struct {
@@ -166,7 +148,7 @@ func DeleteServiceAllInstances(ctx context.Context, 
serviceId string) error {
        domainProject := util.ParseDomainProject(ctx)
 
        instanceLeaseKey := apt.GenerateInstanceLeaseKey(domainProject, 
serviceId, "")
-       resp, err := store.Store().Lease().Search(ctx,
+       resp, err := backend.Store().Lease().Search(ctx,
                registry.WithStrKey(instanceLeaseKey),
                registry.WithPrefix(),
                registry.WithNoCache())
@@ -205,7 +187,7 @@ func QueryAllProvidersInstances(ctx context.Context, 
selfServiceId string) (resu
                return
        }
 
-       rev = store.Revision()
+       rev = backend.Revision()
 
        for _, providerId := range providerIds {
                service, err := GetServiceWithRev(ctx, domainProject, 
providerId, rev)
@@ -254,7 +236,7 @@ func QueryAllProvidersInstances(ctx context.Context, 
selfServiceId string) (resu
 func queryServiceInstancesKvs(ctx context.Context, serviceId string, rev 
int64) ([]*mvccpb.KeyValue, error) {
        domainProject := util.ParseDomainProject(ctx)
        key := apt.GenerateInstanceKey(domainProject, serviceId, "")
-       resp, err := store.Store().Instance().Search(ctx,
+       resp, err := backend.Store().Instance().Search(ctx,
                registry.WithStrKey(key),
                registry.WithPrefix(),
                registry.WithRev(rev))
diff --git a/server/service/util/instance_util_test.go 
b/server/service/util/instance_util_test.go
index 3e30ea67..fa275501 100644
--- a/server/service/util/instance_util_test.go
+++ b/server/service/util/instance_util_test.go
@@ -81,7 +81,7 @@ func TestInstanceExist(t *testing.T) {
        _, err := InstanceExist(context.Background(), 
&proto.MicroServiceInstance{
                ServiceId: "a",
        })
-       if err == nil {
+       if err != nil {
                t.Fatalf(`InstanceExist endpoint failed`)
        }
        _, err = InstanceExist(context.Background(), 
&proto.MicroServiceInstance{
diff --git a/server/service/util/microservice_util.go 
b/server/service/util/microservice_util.go
index c7406682..e8f8e7de 100644
--- a/server/service/util/microservice_util.go
+++ b/server/service/util/microservice_util.go
@@ -20,7 +20,7 @@ import (
        "encoding/json"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -34,7 +34,7 @@ import (
 */
 func GetServiceWithRev(ctx context.Context, domain string, id string, rev 
int64) (*pb.MicroService, error) {
        key := apt.GenerateServiceKey(domain, id)
-       serviceResp, err := store.Store().Service().Search(ctx,
+       serviceResp, err := backend.Store().Service().Search(ctx,
                registry.WithStrKey(key),
                registry.WithRev(rev))
        if err != nil {
@@ -58,7 +58,7 @@ func GetServiceInCache(ctx context.Context, domain string, id 
string) (*pb.Micro
 func GetService(ctx context.Context, domainProject string, serviceId string) 
(*pb.MicroService, error) {
        key := apt.GenerateServiceKey(domainProject, serviceId)
        opts := append(FromContext(ctx), registry.WithStrKey(key))
-       serviceResp, err := store.Store().Service().Search(ctx, opts...)
+       serviceResp, err := backend.Store().Service().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -78,7 +78,7 @@ func GetServicesRawData(ctx context.Context, domainProject 
string) ([]*mvccpb.Ke
        opts := append(FromContext(ctx),
                registry.WithStrKey(key),
                registry.WithPrefix())
-       resp, err := store.Store().Service().Search(ctx, opts...)
+       resp, err := backend.Store().Service().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -118,7 +118,7 @@ func GetServiceId(ctx context.Context, key 
*pb.MicroServiceKey) (serviceId strin
 
 func searchServiceId(ctx context.Context, key *pb.MicroServiceKey) (string, 
error) {
        opts := append(FromContext(ctx), 
registry.WithStrKey(apt.GenerateServiceIndexKey(key)))
-       resp, err := store.Store().ServiceIndex().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceIndex().Search(ctx, opts...)
        if err != nil {
                return "", err
        }
@@ -130,7 +130,7 @@ func searchServiceId(ctx context.Context, key 
*pb.MicroServiceKey) (string, erro
 
 func searchServiceIdFromAlias(ctx context.Context, key *pb.MicroServiceKey) 
(string, error) {
        opts := append(FromContext(ctx), 
registry.WithStrKey(apt.GenerateServiceAliasKey(key)))
-       resp, err := store.Store().ServiceAlias().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceAlias().Search(ctx, opts...)
        if err != nil {
                return "", err
        }
@@ -152,7 +152,7 @@ func GetServiceAllVersions(ctx context.Context, key 
*pb.MicroServiceKey, alias b
                registry.WithStrKey(prefix),
                registry.WithPrefix(),
                registry.WithDescendOrder())
-       resp, err := store.Store().ServiceIndex().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceIndex().Search(ctx, opts...)
        return resp, err
 }
 
@@ -195,7 +195,7 @@ func ServiceExist(ctx context.Context, domainProject 
string, serviceId string) b
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateServiceKey(domainProject, 
serviceId)),
                registry.WithCountOnly())
-       resp, err := store.Store().Service().Search(ctx, opts...)
+       resp, err := backend.Store().Service().Search(ctx, opts...)
        if err != nil || resp.Count == 0 {
                return false
        }
@@ -237,7 +237,7 @@ func GetOneDomainProjectServiceCount(ctx context.Context, 
domainProject string)
                registry.WithStrKey(key),
                registry.WithCountOnly(),
                registry.WithPrefix())
-       resp, err := store.Store().Service().Search(ctx, opts...)
+       resp, err := backend.Store().Service().Search(ctx, opts...)
        if err != nil {
                return 0, err
        }
@@ -250,7 +250,7 @@ func GetOneDomainProjectInstanceCount(ctx context.Context, 
domainProject string)
                registry.WithStrKey(key),
                registry.WithCountOnly(),
                registry.WithPrefix())
-       resp, err := store.Store().Instance().Search(ctx, opts...)
+       resp, err := backend.Store().Instance().Search(ctx, opts...)
        if err != nil {
                return 0, err
        }
diff --git a/server/service/util/rule_util.go b/server/service/util/rule_util.go
index c9bb01cd..660c2e8f 100644
--- a/server/service/util/rule_util.go
+++ b/server/service/util/rule_util.go
@@ -21,7 +21,7 @@ import (
        "fmt"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
@@ -66,7 +66,7 @@ func GetRulesUtil(ctx context.Context, domainProject string, 
serviceId string) (
        }, "/")
 
        opts := append(FromContext(ctx), registry.WithStrKey(key), 
registry.WithPrefix())
-       resp, err := store.Store().Rule().Search(ctx, opts...)
+       resp, err := backend.Store().Rule().Search(ctx, opts...)
        if err != nil {
                return nil, err
        }
@@ -87,7 +87,7 @@ func RuleExist(ctx context.Context, domainProject string, 
serviceId string, attr
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateRuleIndexKey(domainProject, 
serviceId, attr, pattern)),
                registry.WithCountOnly())
-       resp, err := store.Store().RuleIndex().Search(ctx, opts...)
+       resp, err := backend.Store().RuleIndex().Search(ctx, opts...)
        if err != nil || resp.Count == 0 {
                return false
        }
@@ -99,7 +99,7 @@ func GetServiceRuleType(ctx context.Context, domainProject 
string, serviceId str
        opts := append(FromContext(ctx),
                registry.WithStrKey(key),
                registry.WithPrefix())
-       resp, err := store.Store().Rule().Search(ctx, opts...)
+       resp, err := backend.Store().Rule().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "Get rule failed.%s", err.Error())
                return "", 0, err
@@ -118,7 +118,7 @@ func GetServiceRuleType(ctx context.Context, domainProject 
string, serviceId str
 func GetOneRule(ctx context.Context, domainProject, serviceId, ruleId string) 
(*pb.ServiceRule, error) {
        opts := append(FromContext(ctx),
                registry.WithStrKey(apt.GenerateServiceRuleKey(domainProject, 
serviceId, ruleId)))
-       resp, err := store.Store().Rule().Search(ctx, opts...)
+       resp, err := backend.Store().Rule().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(nil, "Get rule for service failed for 
%s.", err.Error())
                return nil, err
diff --git a/server/service/util/schema_util.go 
b/server/service/util/schema_util.go
index daa4dce6..5a0bd0f8 100644
--- a/server/service/util/schema_util.go
+++ b/server/service/util/schema_util.go
@@ -17,14 +17,14 @@
 package util
 
 import (
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
+       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "golang.org/x/net/context"
 )
 
 func CheckSchemaInfoExist(ctx context.Context, key string) (bool, error) {
        opts := append(FromContext(ctx), registry.WithStrKey(key), 
registry.WithCountOnly())
-       resp, errDo := store.Store().Schema().Search(ctx, opts...)
+       resp, errDo := backend.Store().Schema().Search(ctx, opts...)
        if errDo != nil {
                return false, errDo
        }
diff --git a/server/service/util/tag_util.go b/server/service/util/tag_util.go
index dc7fe6be..b416b76c 100644
--- a/server/service/util/tag_util.go
+++ b/server/service/util/tag_util.go
@@ -21,7 +21,6 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        apt "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
-       
"github.com/apache/incubator-servicecomb-service-center/server/core/backend/store"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
        "golang.org/x/net/context"
 )
@@ -48,7 +47,7 @@ func AddTagIntoETCD(ctx context.Context, domainProject 
string, serviceId string,
 func GetTagsUtils(ctx context.Context, domainProject, serviceId string) (tags 
map[string]string, err error) {
        key := apt.GenerateServiceTagKey(domainProject, serviceId)
        opts := append(FromContext(ctx), registry.WithStrKey(key))
-       resp, err := store.Store().ServiceTag().Search(ctx, opts...)
+       resp, err := backend.Store().ServiceTag().Search(ctx, opts...)
        if err != nil {
                util.Logger().Errorf(err, "get service %s tags file failed", 
key)
                return tags, err


 

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to