plugin/file: simplify locking (#3024)

* plugin/file: simplify locking

Simplify the locking, remove the reloadMu and just piggyback on the
other lock for accessing content, which assumes things can be move
underneath.

Copy the Apex and Zone to new vars to make sure the pointer isn't
updated from under us.

The releadMu isn't need at all, the time.Ticker firing while we're
reading means we will just miss that tick and get it on the next go.

Add rrutil subpackage and put some more generic functions in there, that
are now used from file and the tree package. This removes some
duplication.

Rename additionalProcessing that didn't actually do that to
externalLookup, because that's what being done at some point.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Update plugin/file/lookup.go

Co-Authored-By: Michael Grosser <development@stp-ip.net>
This commit is contained in:
Miek Gieben
2019-07-23 18:32:44 +00:00
committed by GitHub
parent 637bd3c7dc
commit eba020e6a1
6 changed files with 161 additions and 169 deletions

44
plugin/file/tree/glue.go Normal file
View File

@@ -0,0 +1,44 @@
package tree
import (
"github.com/coredns/coredns/plugin/file/rrutil"
"github.com/miekg/dns"
)
// Glue returns any potential glue records for nsrrs.
func (t *Tree) Glue(nsrrs []dns.RR, do bool) []dns.RR {
glue := []dns.RR{}
for _, rr := range nsrrs {
if ns, ok := rr.(*dns.NS); ok && dns.IsSubDomain(ns.Header().Name, ns.Ns) {
glue = append(glue, t.searchGlue(ns.Ns, do)...)
}
}
return glue
}
// searchGlue looks up A and AAAA for name.
func (t *Tree) searchGlue(name string, do bool) []dns.RR {
glue := []dns.RR{}
// A
if elem, found := t.Search(name); found {
glue = append(glue, elem.Type(dns.TypeA)...)
if do {
sigs := elem.Type(dns.TypeRRSIG)
sigs = rrutil.SubTypeSignature(sigs, dns.TypeA)
glue = append(glue, sigs...)
}
}
// AAAA
if elem, found := t.Search(name); found {
glue = append(glue, elem.Type(dns.TypeAAAA)...)
if do {
sigs := elem.Type(dns.TypeRRSIG)
sigs = rrutil.SubTypeSignature(sigs, dns.TypeAAAA)
glue = append(glue, sigs...)
}
}
return glue
}