Skip to content

Commit

Permalink
fixed reload bugs when add/reduce server (#73)
Browse files Browse the repository at this point in the history
* fixed reload bugs to add server or reduce server

* remove length equals condition

* bump version to 1.8.2

* add read sleep for flushing disk
  • Loading branch information
wayslog authored Jun 24, 2019
1 parent 3b67fd6 commit 7ec4340
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 27 additions & 5 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
errs "errors"
"net"
"path/filepath"
"reflect"
"sort"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -221,19 +221,41 @@ 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
}
}
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
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
const (
OverlordMajor = 1
OverlordMinor = 8
OverlordPatch = 1
OverlordPatch = 2
)

var showVersion bool
Expand Down

0 comments on commit 7ec4340

Please sign in to comment.