plugin/etcd: drop inflight (#1249)
Use caching, just ask etcd for every query. This also improves throughput because the single lock in inflght is bypassed.
This commit is contained in:
parent
f621870d9c
commit
9d52b5acb9
3 changed files with 5 additions and 21 deletions
|
@ -9,8 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/plugin/etcd/msg"
|
"github.com/coredns/coredns/plugin/etcd/msg"
|
||||||
"github.com/coredns/coredns/plugin/pkg/cache"
|
|
||||||
"github.com/coredns/coredns/plugin/pkg/singleflight"
|
|
||||||
"github.com/coredns/coredns/plugin/proxy"
|
"github.com/coredns/coredns/plugin/proxy"
|
||||||
"github.com/coredns/coredns/request"
|
"github.com/coredns/coredns/request"
|
||||||
|
|
||||||
|
@ -28,7 +26,6 @@ type Etcd struct {
|
||||||
Proxy proxy.Proxy // Proxy for looking up names during the resolution process
|
Proxy proxy.Proxy // Proxy for looking up names during the resolution process
|
||||||
Client etcdc.KeysAPI
|
Client etcdc.KeysAPI
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
Inflight *singleflight.Group
|
|
||||||
Stubmap *map[string]proxy.Proxy // list of proxies for stub resolving.
|
Stubmap *map[string]proxy.Proxy // list of proxies for stub resolving.
|
||||||
|
|
||||||
endpoints []string // Stored here as well, to aid in testing.
|
endpoints []string // Stored here as well, to aid in testing.
|
||||||
|
@ -84,24 +81,15 @@ func (e *Etcd) Records(state request.Request, exact bool) ([]msg.Service, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries.
|
// get is a wrapper for client.Get
|
||||||
func (e *Etcd) get(path string, recursive bool) (*etcdc.Response, error) {
|
func (e *Etcd) get(path string, recursive bool) (*etcdc.Response, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(e.Ctx, etcdTimeout)
|
||||||
hash := cache.Hash([]byte(path))
|
defer cancel()
|
||||||
|
r, err := e.Client.Get(ctx, path, &etcdc.GetOptions{Sort: false, Recursive: recursive})
|
||||||
resp, err := e.Inflight.Do(hash, func() (interface{}, error) {
|
|
||||||
ctx, cancel := context.WithTimeout(e.Ctx, etcdTimeout)
|
|
||||||
defer cancel()
|
|
||||||
r, e := e.Client.Get(ctx, path, &etcdc.GetOptions{Sort: false, Recursive: recursive})
|
|
||||||
if e != nil {
|
|
||||||
return nil, e
|
|
||||||
}
|
|
||||||
return r, e
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp.(*etcdc.Response), err
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// skydns/local/skydns/east/staging/web
|
// skydns/local/skydns/east/staging/web
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin/etcd/msg"
|
"github.com/coredns/coredns/plugin/etcd/msg"
|
||||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||||
"github.com/coredns/coredns/plugin/pkg/singleflight"
|
|
||||||
"github.com/coredns/coredns/plugin/pkg/tls"
|
"github.com/coredns/coredns/plugin/pkg/tls"
|
||||||
"github.com/coredns/coredns/plugin/proxy"
|
"github.com/coredns/coredns/plugin/proxy"
|
||||||
"github.com/coredns/coredns/plugin/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
@ -232,7 +231,6 @@ func newEtcdPlugin() *Etcd {
|
||||||
Proxy: proxy.NewLookup([]string{"8.8.8.8:53"}),
|
Proxy: proxy.NewLookup([]string{"8.8.8.8:53"}),
|
||||||
PathPrefix: "skydns",
|
PathPrefix: "skydns",
|
||||||
Ctx: context.Background(),
|
Ctx: context.Background(),
|
||||||
Inflight: &singleflight.Group{},
|
|
||||||
Zones: []string{"skydns.test.", "skydns_extra.test.", "in-addr.arpa."},
|
Zones: []string{"skydns.test.", "skydns_extra.test.", "in-addr.arpa."},
|
||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||||
"github.com/coredns/coredns/plugin/pkg/singleflight"
|
|
||||||
mwtls "github.com/coredns/coredns/plugin/pkg/tls"
|
mwtls "github.com/coredns/coredns/plugin/pkg/tls"
|
||||||
"github.com/coredns/coredns/plugin/proxy"
|
"github.com/coredns/coredns/plugin/proxy"
|
||||||
|
|
||||||
|
@ -50,7 +49,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
|
||||||
// Proxy: proxy.NewLookup([]string{"8.8.8.8:53", "8.8.4.4:53"}),
|
// Proxy: proxy.NewLookup([]string{"8.8.8.8:53", "8.8.4.4:53"}),
|
||||||
PathPrefix: "skydns",
|
PathPrefix: "skydns",
|
||||||
Ctx: context.Background(),
|
Ctx: context.Background(),
|
||||||
Inflight: &singleflight.Group{},
|
|
||||||
Stubmap: &stub,
|
Stubmap: &stub,
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Add table
Reference in a new issue