Skip to content

Commit

Permalink
feat:filter empty etcd watch message,issue: TencentBlueKing#136
Browse files Browse the repository at this point in the history
  • Loading branch information
tbs60 committed Nov 3, 2023
1 parent 8ed021f commit 80ac45e
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/backend/booster/server/pkg/rd/rd.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,28 @@ func (erd *etcdRegisterDiscover) watch() {
for {
select {
case resp := <-watchChan:
blog.Infof("rd: watch resp [%+v]", resp)
for _, ev := range resp.Events {
blog.Infof("rd: watch event [%s %q : %q]", ev.Type, ev.Kv.Key, ev.Kv.Value)
if ev.Type == etcdClient.EventTypePut {
if string(ev.Kv.Value) == string(erd.serverInfo) {
blog.Infof("rd: watch resp [found self succeed put]")
erd.selfServerKey = string(ev.Kv.Key)
blog.Infof("rd: watch resp erd.selfServerKey is[%s]", erd.selfServerKey)
}
} else if ev.Type == etcdClient.EventTypeDelete {
if string(ev.Kv.Key) == erd.selfServerKey {
blog.Infof("rd: watch resp [found self succeed delete]")
erd.selfServerKey = ""
// 通知manager重置
erd.reset()
if len(resp.Events) > 0 {
blog.Infof("rd: watch resp [%+v]", resp)
for _, ev := range resp.Events {
blog.Infof("rd: watch event [%s %q : %q]", ev.Type, ev.Kv.Key, ev.Kv.Value)
if ev.Type == etcdClient.EventTypePut {
if string(ev.Kv.Value) == string(erd.serverInfo) {
blog.Infof("rd: watch resp [found self succeed put]")
erd.selfServerKey = string(ev.Kv.Key)
blog.Infof("rd: watch resp erd.selfServerKey is[%s]", erd.selfServerKey)
}
} else if ev.Type == etcdClient.EventTypeDelete {
if string(ev.Kv.Key) == erd.selfServerKey {
blog.Infof("rd: watch resp [found self succeed delete]")
erd.selfServerKey = ""
// 通知manager重置
erd.reset()
}
}
}
}

erd.updateServerInfo()
erd.updateServerInfo()
}
}
}
}
Expand Down

0 comments on commit 80ac45e

Please sign in to comment.