From d1a66f977e25ac928a482d538c216c1ecdcab136 Mon Sep 17 00:00:00 2001 From: shlomi-noach Date: Tue, 24 Nov 2015 14:53:13 +0100 Subject: [PATCH] Fixed resolve.go error where hostname_resolve would load into cache even on "none" configuration --- build.sh | 2 +- go/inst/resolve.go | 19 +++++++++++++++---- go/logic/orchestrator.go | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/build.sh b/build.sh index 7f3bfb3e..3283518d 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ # set -e -RELEASE_VERSION="1.4.543" +RELEASE_VERSION="1.4.544" TOPDIR=/tmp/orchestrator-release export RELEASE_VERSION TOPDIR diff --git a/go/inst/resolve.go b/go/inst/resolve.go index 22b27599..444f9526 100644 --- a/go/inst/resolve.go +++ b/go/inst/resolve.go @@ -42,6 +42,10 @@ func init() { var hostnameResolvesLightweightCache = cache.New(time.Duration(config.Config.ExpiryHostnameResolvesMinutes)*time.Minute, time.Minute) var hostnameResolvesLightweightCacheLoadedOnceFromDB bool = false +func HostnameResolveMethodIsNone() bool { + return strings.ToLower(config.Config.HostnameResolveMethod) == "none" +} + // GetCNAME resolves an IP or hostname into a normalized valid CNAME func GetCNAME(hostname string) (string, error) { res, err := net.LookupCNAME(hostname) @@ -88,7 +92,7 @@ func ResolveHostname(hostname string) (string, error) { // However cli does not do so. // Anyway, it seems like the cache was not loaded from DB. Before doing real resolves, // let's try and get the resolved hostname from database. - if strings.ToLower(config.Config.HostnameResolveMethod) != "none" { + if !HostnameResolveMethodIsNone() { if resolvedHostname, err := ReadResolvedHostname(hostname); err == nil && resolvedHostname != "" { hostnameResolvesLightweightCache.Set(hostname, resolvedHostname, 0) return resolvedHostname, nil @@ -130,13 +134,20 @@ func UpdateResolvedHostname(hostname string, resolvedHostname string) bool { return false } hostnameResolvesLightweightCache.Set(hostname, resolvedHostname, 0) - if strings.ToLower(config.Config.HostnameResolveMethod) != "none" { + if !HostnameResolveMethodIsNone() { WriteResolvedHostname(hostname, resolvedHostname) } return true } -func LoadHostnameResolveCacheFromDatabase() error { +func LoadHostnameResolveCache() error { + if !HostnameResolveMethodIsNone() { + return loadHostnameResolveCacheFromDatabase() + } + return nil +} + +func loadHostnameResolveCacheFromDatabase() error { allHostnamesResolves, err := readAllHostnameResolves() if err != nil { return err @@ -149,7 +160,7 @@ func LoadHostnameResolveCacheFromDatabase() error { } func FlushNontrivialResolveCacheToDatabase() error { - if strings.ToLower(config.Config.HostnameResolveMethod) == "none" { + if !HostnameResolveMethodIsNone() { return log.Errorf("FlushNontrivialResolveCacheToDatabase() called, but HostnameResolveMethod is %+v", config.Config.HostnameResolveMethod) } items, _ := HostnameResolveCache() diff --git a/go/logic/orchestrator.go b/go/logic/orchestrator.go index 181a1078..3a9d5c5e 100644 --- a/go/logic/orchestrator.go +++ b/go/logic/orchestrator.go @@ -152,7 +152,7 @@ func ContinuousDiscovery() { } log.Infof("Starting continuous discovery") - inst.LoadHostnameResolveCacheFromDatabase() + inst.LoadHostnameResolveCache() go handleDiscoveryRequests() discoveryTick := time.Tick(time.Duration(config.Config.DiscoveryPollSeconds) * time.Second) @@ -213,7 +213,7 @@ func ContinuousDiscovery() { } if !isElectedNode { // Take this opportunity to refresh yourself - go inst.LoadHostnameResolveCacheFromDatabase() + go inst.LoadHostnameResolveCache() } go inst.ReadClusterAliases() }()