[
https://issues.apache.org/jira/browse/SCB-1059?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16707312#comment-16707312
]
ASF GitHub Bot commented on SCB-1059:
-------------------------------------
little-cui closed pull request #505: SCB-1059 unexpected events publish if
error occurs in previous list-watch loop
URL: https://github.com/apache/servicecomb-service-center/pull/505
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/server/plugin/pkg/discovery/etcd/cacher_kv.go
b/server/plugin/pkg/discovery/etcd/cacher_kv.go
index 2302c6a3..eb352fdf 100644
--- a/server/plugin/pkg/discovery/etcd/cacher_kv.go
+++ b/server/plugin/pkg/discovery/etcd/cacher_kv.go
@@ -36,8 +36,7 @@ import (
type KvCacher struct {
Cfg *discovery.Config
- latestListRev int64
- reListCount int
+ reListCount int
ready chan struct{}
lw ListWatch
@@ -53,7 +52,6 @@ func (c *KvCacher) Config() *discovery.Config {
func (c *KvCacher) needList() bool {
rev := c.lw.Revision()
- // init stage or there is a backend error
if rev == 0 {
c.reListCount = 0
return true
@@ -71,7 +69,6 @@ func (c *KvCacher) doList(cfg ListWatchConfig) error {
if err != nil {
return err
}
- c.latestListRev = c.lw.Revision()
kvs := resp.Kvs
start := time.Now()
@@ -103,11 +100,19 @@ func (c *KvCacher) ListAndWatch(ctx context.Context)
error {
Timeout: c.Cfg.Timeout,
Context: ctx,
}
+
+ // the scenario need to list etcd:
+ // 1. Initial: cache is building, the lister's revision is 0.
+ // 2. Runtime: error occurs in previous watch operation, the lister's
revision is set to 0.
+ // 3. Runtime: no event comes in watch operation over
DEFAULT_FORCE_LIST_INTERVAL times.
if c.needList() {
- if err := c.doList(cfg); err != nil && !c.IsReady() {
- // cacher is not ready, so it need to retry util the
cache is created
- return err
+ if err := c.doList(cfg); err != nil && (!c.IsReady() ||
c.lw.Revision() == 0) {
+ return err // do retry to list etcd
}
+ // keep going to next step:
+ // 1. doList return OK.
+ // 2. some traps in etcd client, like the limitation of max
response body(4MB),
+ // doList always return error. So call doWatch to compensate
it if cacher is ready.
}
util.SafeCloseChan(c.ready)
diff --git a/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
b/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
index efd59b7b..61f52375 100644
--- a/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
+++ b/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
@@ -87,7 +87,7 @@ func TestNewKvCacher(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
- // case: cause list internal error
+ // case: cause list internal error before initialized
cr.refresh(ctx)
if cr.IsReady() {
t.Fatalf("TestNewKvCacher failed")
@@ -336,6 +336,7 @@ func TestNewKvCacher(t *testing.T) {
evts[string(evt.KV.Key)] = evt
})
cr.refresh(ctx)
+ *cr.Cfg = old
// check all events
for i := 0; i < eventBlockSize+1; i++ {
s := strconv.Itoa(i)
@@ -349,6 +350,21 @@ func TestNewKvCacher(t *testing.T) {
t.Fatalf("TestNewKvCacher failed, %v %v", evts, evt)
}
delete(evts, string(data.Key))
+
+ // case: cacher is ready and the next list failed, prevent to watch
with rev = 0
+ if !cr.IsReady() {
+ t.Fatalf("TestNewKvCacher failed")
+ }
+ lw.Rev = 0 // watch failed
+ lw.ListResponse = nil // the next list
+ lw.Bus <- test
+ old = *cr.Cfg
+ cr.Cfg.WithEventFunc(func(evt discovery.KvEvent) {
+ t.Fatalf("TestNewKvCacher failed, %v", evt)
+ })
+ cr.refresh(ctx)
+ *cr.Cfg = old
+ <-lw.Bus
}
func BenchmarkFilter(b *testing.B) {
diff --git a/server/plugin/pkg/discovery/etcd/common.go
b/server/plugin/pkg/discovery/etcd/common.go
index bfbc193f..bf4bf014 100644
--- a/server/plugin/pkg/discovery/etcd/common.go
+++ b/server/plugin/pkg/discovery/etcd/common.go
@@ -26,8 +26,6 @@ const (
// force re-list
DEFAULT_FORCE_LIST_INTERVAL = 4
DEFAULT_METRICS_INTERVAL = 30 * time.Second
- DEFAULT_COMPACT_TIMES = 2
- DEFAULT_COMPACT_TIMEOUT = 5 * time.Minute
minWaitInterval = 1 * time.Second
eventBlockSize = 1000
----------------------------------------------------------------
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:
[email protected]
> Bug fixes for v1.1.0
> --------------------
>
> Key: SCB-1059
> URL: https://issues.apache.org/jira/browse/SCB-1059
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
> Fix For: service-center-1.2.0
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)