Skip to content

Commit

Permalink
Fixed active connections underflow on backend removed and added while…
Browse files Browse the repository at this point in the history
… connections remain active #165
  • Loading branch information
illarion committed Aug 21, 2018
1 parent 21a2279 commit 42634f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This release brings some improvements and bugfixes.
### Fixed
- Fixed iphash algorithm. It was not working properly at all
- Fixed UDP 'session' tracking problems
- Fixed active connections underflow on backend removed and added back, but connections remain established

### Changed
- Removed not necessary dependency on libacl1-dev
Expand Down
1 change: 1 addition & 0 deletions src/core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Backend struct {
*/
type BackendStats struct {
Live bool `json:"live"`
Discovered bool `json:"discovered"`
TotalConnections int64 `json:"total_connections"`
ActiveConnections uint `json:"active_connections"`
RefusedConnections uint64 `json:"refused_connections"`
Expand Down
29 changes: 23 additions & 6 deletions src/server/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (this *Scheduler) Start() {
this.ops = make(chan Op)
this.elect = make(chan ElectRequest)
this.stop = make(chan bool)
this.backends = make(map[core.Target]*core.Backend)

this.Discovery.Start()
this.Healthcheck.Start()
Expand Down Expand Up @@ -221,38 +222,54 @@ func (this *Scheduler) HandleBackendLiveChange(target core.Target, live bool) {
*/
func (this *Scheduler) HandleBackendsUpdate(backends []core.Backend) {

updated := map[core.Target]*core.Backend{}
// first mark all existing backends as not discovered
for _, b := range this.backends {
b.Stats.Discovered = false
}

for _, b := range backends {
oldB, ok := this.backends[b.Target]

if ok {
// if we have this backend, update it's discovery properties
updatedB := oldB.MergeFrom(b)
updated[oldB.Target] = updatedB
oldB.MergeFrom(b)
// mark found backend as discovered
oldB.Stats.Discovered = true
continue
}

b := b // b has to be local variable in order to make unique pointers
updated[b.Target] = &b
b.Stats.Discovered = true
this.backends[b.Target] = &b
}

//remove not discovered backends without active connections
for t, b := range this.backends {
if b.Stats.Discovered || b.Stats.ActiveConnections > 0 {
continue
}
delete(this.backends, t)
}

this.backends = updated
}

/**
* Perform backend election
*/
func (this *Scheduler) HandleBackendElect(req ElectRequest) {

// Filter only live backends
// Filter only live and discovered backends
var backends []*core.Backend
for _, b := range this.backends {

if !b.Stats.Live {
continue
}

if !b.Stats.Discovered {
continue
}

backends = append(backends, b)
}

Expand Down

0 comments on commit 42634f2

Please sign in to comment.