plugin/file: track zone mtime for reload_by_mtime (#8556)

* plugin/file: track zone mtime for reload_by_mtime

Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com>

* plugin/file: capture initial mtime before parsing

Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com>

* plugin/file: keep unloaded zones retryable after open error

Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com>

---------

Signed-off-by: git-jxj <65210887+git-jxj@users.noreply.github.com>
This commit is contained in:
jxj
2026-09-28 15:22:39 +08:00
committed by GitHub
parent 6755e6276d
commit 72160e6e20
4 changed files with 193 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ func (z *Zone) Reload(t *transfer.Transfer) error {
case <-tick.C:
zFile := z.File()
serial := z.SOASerialIfDefined()
var fileMtime time.Time
if z.ReloadByMtime {
fi, err := os.Stat(zFile)
@@ -28,9 +29,13 @@ func (z *Zone) Reload(t *transfer.Transfer) error {
log.Errorf("Failed to stat zone %q in %q: %v", z.origin, zFile, err)
continue
}
if !fi.ModTime().After(z.file_mtime) {
z.RLock()
lastMtime := z.file_mtime
z.RUnlock()
if !fi.ModTime().After(lastMtime) {
continue
}
fileMtime = fi.ModTime()
serial = 0 // force reload of the zone
}
@@ -50,6 +55,11 @@ func (z *Zone) Reload(t *transfer.Transfer) error {
}
z.setData(zone.Apex, zone.Tree)
if z.ReloadByMtime {
z.Lock()
z.file_mtime = fileMtime
z.Unlock()
}
log.Infof("Successfully reloaded zone %q in %q with %d SOA serial", z.origin, zFile, zone.SOA.Serial)
if t != nil {