perf: reducing the lock strength of the soa cache entry (#2285)
Co-authored-by: icpd <35096485+icpd@users.noreply.github.com> Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
d81507c126
commit
a83482cac4
1 changed files with 10 additions and 13 deletions
|
@ -16,10 +16,7 @@ import (
|
||||||
|
|
||||||
const defaultResolvConf = "/etc/resolv.conf"
|
const defaultResolvConf = "/etc/resolv.conf"
|
||||||
|
|
||||||
var (
|
var fqdnSoaCache = &sync.Map{}
|
||||||
fqdnSoaCache = map[string]*soaCacheEntry{}
|
|
||||||
muFqdnSoaCache sync.Mutex
|
|
||||||
)
|
|
||||||
|
|
||||||
var defaultNameservers = []string{
|
var defaultNameservers = []string{
|
||||||
"google-public-dns-a.google.com:53",
|
"google-public-dns-a.google.com:53",
|
||||||
|
@ -51,9 +48,7 @@ func (cache *soaCacheEntry) isExpired() bool {
|
||||||
|
|
||||||
// ClearFqdnCache clears the cache of fqdn to zone mappings. Primarily used in testing.
|
// ClearFqdnCache clears the cache of fqdn to zone mappings. Primarily used in testing.
|
||||||
func ClearFqdnCache() {
|
func ClearFqdnCache() {
|
||||||
muFqdnSoaCache.Lock()
|
fqdnSoaCache.Clear()
|
||||||
fqdnSoaCache = map[string]*soaCacheEntry{}
|
|
||||||
muFqdnSoaCache.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddDNSTimeout(timeout time.Duration) ChallengeOption {
|
func AddDNSTimeout(timeout time.Duration) ChallengeOption {
|
||||||
|
@ -153,20 +148,22 @@ func FindZoneByFqdnCustom(fqdn string, nameservers []string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupSoaByFqdn(fqdn string, nameservers []string) (*soaCacheEntry, error) {
|
func lookupSoaByFqdn(fqdn string, nameservers []string) (*soaCacheEntry, error) {
|
||||||
muFqdnSoaCache.Lock()
|
|
||||||
defer muFqdnSoaCache.Unlock()
|
|
||||||
|
|
||||||
// Do we have it cached and is it still fresh?
|
// Do we have it cached and is it still fresh?
|
||||||
if ent := fqdnSoaCache[fqdn]; ent != nil && !ent.isExpired() {
|
entAny, ok := fqdnSoaCache.Load(fqdn)
|
||||||
|
if ok && entAny != nil {
|
||||||
|
ent, ok1 := entAny.(*soaCacheEntry)
|
||||||
|
if ok1 && !ent.isExpired() {
|
||||||
return ent, nil
|
return ent, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ent, err := fetchSoaByFqdn(fqdn, nameservers)
|
ent, err := fetchSoaByFqdn(fqdn, nameservers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdnSoaCache[fqdn] = ent
|
fqdnSoaCache.Store(fqdn, ent)
|
||||||
|
|
||||||
return ent, nil
|
return ent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue