aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/reload.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2019-07-23 18:32:44 +0000
committerGravatar GitHub <noreply@github.com> 2019-07-23 18:32:44 +0000
commiteba020e6a1176c0d8fed639e936ddc2774f295dd (patch)
treeadce0be527c6a0d412d74a120b086f90a5503bbf /plugin/file/reload.go
parent637bd3c7dcb19659e3e52cd56fe8f4e6b455ac83 (diff)
downloadcoredns-eba020e6a1176c0d8fed639e936ddc2774f295dd.tar.gz
coredns-eba020e6a1176c0d8fed639e936ddc2774f295dd.tar.zst
coredns-eba020e6a1176c0d8fed639e936ddc2774f295dd.zip
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>
Diffstat (limited to 'plugin/file/reload.go')
-rw-r--r--plugin/file/reload.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/plugin/file/reload.go b/plugin/file/reload.go
index ce5c81335..eb762ac52 100644
--- a/plugin/file/reload.go
+++ b/plugin/file/reload.go
@@ -13,10 +13,8 @@ func (z *Zone) Reload() error {
tick := time.NewTicker(z.ReloadInterval)
go func() {
-
for {
select {
-
case <-tick.C:
zFile := z.File()
reader, err := os.Open(zFile)
@@ -35,10 +33,10 @@ func (z *Zone) Reload() error {
}
// copy elements we need
- z.reloadMu.Lock()
+ z.Lock()
z.Apex = zone.Apex
z.Tree = zone.Tree
- z.reloadMu.Unlock()
+ z.Unlock()
log.Infof("Successfully reloaded zone %q in %q with serial %d", z.origin, zFile, z.Apex.SOA.Serial)
z.Notify()
@@ -52,11 +50,10 @@ func (z *Zone) Reload() error {
return nil
}
-// SOASerialIfDefined returns the SOA's serial if the zone has a SOA record in the Apex, or
-// -1 otherwise.
+// SOASerialIfDefined returns the SOA's serial if the zone has a SOA record in the Apex, or -1 otherwise.
func (z *Zone) SOASerialIfDefined() int64 {
- z.reloadMu.Lock()
- defer z.reloadMu.Unlock()
+ z.RLock()
+ defer z.RUnlock()
if z.Apex.SOA != nil {
return int64(z.Apex.SOA.Serial)
}