mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
plugin/host: parse file without holding lock (#2270)
* plugin/host: parse file without holding lock Parse first and then swap the maps *while* holding the lock. Signed-off-by: Miek Gieben <miek@miek.nl> * add back in the parse function, but now purely for testing Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -106,13 +106,17 @@ func (h *Hostsfile) readHosts() {
|
||||
return
|
||||
}
|
||||
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
h.parseReader(file)
|
||||
newMap := h.parse(file, h.inline)
|
||||
log.Debugf("Parsed hosts file into %d entries", newMap.Len())
|
||||
|
||||
h.Lock()
|
||||
|
||||
h.hmap = newMap
|
||||
// Update the data cache.
|
||||
h.mtime = stat.ModTime()
|
||||
h.size = stat.Size()
|
||||
|
||||
h.Unlock()
|
||||
}
|
||||
|
||||
func (h *Hostsfile) initInline(inline []string) {
|
||||
@@ -125,12 +129,6 @@ func (h *Hostsfile) initInline(inline []string) {
|
||||
*h.hmap = *h.inline
|
||||
}
|
||||
|
||||
func (h *Hostsfile) parseReader(r io.Reader) {
|
||||
h.hmap = h.parse(r, h.inline)
|
||||
|
||||
log.Debugf("Parsed hosts file into %d entries", h.hmap.Len())
|
||||
}
|
||||
|
||||
// Parse reads the hostsfile and populates the byName and byAddr maps.
|
||||
func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap {
|
||||
hmap := newHostsMap()
|
||||
|
||||
Reference in New Issue
Block a user