|
|
@ -208,7 +208,7 @@ func (c *cluster) handleWatchEvents(key string, events []*clientv3.Event) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *cluster) load(cli EtcdClient, key string) {
|
|
|
|
func (c *cluster) load(cli EtcdClient, key string) int64 {
|
|
|
|
var resp *clientv3.GetResponse
|
|
|
|
var resp *clientv3.GetResponse
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
@ -232,6 +232,8 @@ func (c *cluster) load(cli EtcdClient, key string) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c.handleChanges(key, kvs)
|
|
|
|
c.handleChanges(key, kvs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resp.Header.Revision
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *cluster) monitor(key string, l UpdateListener) error {
|
|
|
|
func (c *cluster) monitor(key string, l UpdateListener) error {
|
|
|
@ -244,9 +246,9 @@ func (c *cluster) monitor(key string, l UpdateListener) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c.load(cli, key)
|
|
|
|
rev := c.load(cli, key)
|
|
|
|
c.watchGroup.Run(func() {
|
|
|
|
c.watchGroup.Run(func() {
|
|
|
|
c.watch(cli, key)
|
|
|
|
c.watch(cli, key, rev)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -278,22 +280,28 @@ func (c *cluster) reload(cli EtcdClient) {
|
|
|
|
for _, key := range keys {
|
|
|
|
for _, key := range keys {
|
|
|
|
k := key
|
|
|
|
k := key
|
|
|
|
c.watchGroup.Run(func() {
|
|
|
|
c.watchGroup.Run(func() {
|
|
|
|
c.load(cli, k)
|
|
|
|
rev := c.load(cli, k)
|
|
|
|
c.watch(cli, k)
|
|
|
|
c.watch(cli, k, rev)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *cluster) watch(cli EtcdClient, key string) {
|
|
|
|
func (c *cluster) watch(cli EtcdClient, key string, rev int64) {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
if c.watchStream(cli, key) {
|
|
|
|
if c.watchStream(cli, key, rev) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *cluster) watchStream(cli EtcdClient, key string) bool {
|
|
|
|
func (c *cluster) watchStream(cli EtcdClient, key string, rev int64) bool {
|
|
|
|
rch := cli.Watch(clientv3.WithRequireLeader(c.context(cli)), makeKeyPrefix(key), clientv3.WithPrefix())
|
|
|
|
var rch clientv3.WatchChan
|
|
|
|
|
|
|
|
if rev != 0 {
|
|
|
|
|
|
|
|
rch = cli.Watch(clientv3.WithRequireLeader(c.context(cli)), makeKeyPrefix(key), clientv3.WithPrefix(), clientv3.WithRev(rev+1))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rch = cli.Watch(clientv3.WithRequireLeader(c.context(cli)), makeKeyPrefix(key), clientv3.WithPrefix())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case wresp, ok := <-rch:
|
|
|
|
case wresp, ok := <-rch:
|
|
|
|