diff --git a/proxy/proxy.go b/proxy/proxy.go index d27b2b2a..66dd7be6 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -4,7 +4,6 @@ import ( errs "errors" "net" "path/filepath" - "reflect" "sort" "sync" "sync/atomic" @@ -169,6 +168,7 @@ func (p *Proxy) MonitorConfChange(ccf string) { select { case ev := <-watch.Events: if ev.Op&fsnotify.Create == fsnotify.Create || ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Rename == fsnotify.Rename { + time.Sleep(time.Second) newConfs, err := LoadClusterConf(p.ccf) if err != nil { prom.ErrIncr(p.ccf, p.ccf, "config reload", err.Error()) @@ -221,15 +221,23 @@ func (p *Proxy) updateConfig(conf *ClusterConfig) (err error) { } func parseChanged(newConfs, oldConfs []*ClusterConfig) (changed []*ClusterConfig) { + changed = make([]*ClusterConfig, 0, len(oldConfs)) + for _, cf := range newConfs { + sort.Strings(cf.Servers) + } + + for _, cf := range oldConfs { + sort.Strings(cf.Servers) + } + for _, newConf := range newConfs { for _, oldConf := range oldConfs { - if newConf.Name != oldConf.Name || len(newConf.Servers) != len(oldConf.Servers) { + if newConf.Name != oldConf.Name { continue } - sort.Strings(newConf.Servers) - sort.Strings(oldConf.Servers) - if !reflect.DeepEqual(newConf.Servers, oldConf.Servers) { + + if !deepEqualOrderedStringSlice(newConf.Servers, oldConf.Servers) { changed = append(changed, newConf) } break @@ -237,3 +245,17 @@ func parseChanged(newConfs, oldConfs []*ClusterConfig) (changed []*ClusterConfig } return } + +func deepEqualOrderedStringSlice(a, b []string) bool { + if len(a) != len(b) { + return false + } + + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + + return true +} diff --git a/version/version.go b/version/version.go index e3b3626e..42b85738 100644 --- a/version/version.go +++ b/version/version.go @@ -10,7 +10,7 @@ import ( const ( OverlordMajor = 1 OverlordMinor = 8 - OverlordPatch = 1 + OverlordPatch = 2 ) var showVersion bool