Skip to content

Commit

Permalink
Fixed resolve.go error where hostname_resolve would load into cache even
Browse files Browse the repository at this point in the history
on "none" configuration
  • Loading branch information
shlomi-noach committed Nov 24, 2015
1 parent 3703cf6 commit d1a66f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
set -e

RELEASE_VERSION="1.4.543"
RELEASE_VERSION="1.4.544"
TOPDIR=/tmp/orchestrator-release
export RELEASE_VERSION TOPDIR

Expand Down
19 changes: 15 additions & 4 deletions go/inst/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions go/logic/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -213,7 +213,7 @@ func ContinuousDiscovery() {
}
if !isElectedNode {
// Take this opportunity to refresh yourself
go inst.LoadHostnameResolveCacheFromDatabase()
go inst.LoadHostnameResolveCache()
}
go inst.ReadClusterAliases()
}()
Expand Down

0 comments on commit d1a66f9

Please sign in to comment.