Skip to content

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
1. add magic number penaltySize for test assert the number of error host's load + penalty result
2. update comments
  • Loading branch information
nir3c authored Sep 1, 2023
1 parent e16667f commit 6fd697b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ func executeWithRetry(
if rw.StatusCode() == http.StatusBadGateway {
log.Debugf("the invalid host is: %s", s.host.addr)
s.host.penalize()
// comment s.host.dec() line to avoid double increment; issue #322
// s.host.dec()
atomic.StoreUint32(&s.host.active, uint32(0))
nextHost := s.host.replica.cluster.getHost()
// The query could be retried if it has no stickiness to a certain server
Expand All @@ -250,7 +248,7 @@ func executeWithRetry(

// decrement the current failed host counter and increment the new host
// as for the end of the requests we will close the scope and in that closed scope
// decrement the new host
// decrement the new host PR - https://github.com/ContentSquare/chproxy/pull/357
if currentHost != nextHost {
currentHost.dec()
nextHost.inc()
Expand Down
4 changes: 2 additions & 2 deletions proxyretry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ func TestQueryWithRetrySuccess(t *testing.T) {
assert.Equal(t, 1, int(s.host.load()))

assert.Equal(t, 0, int(erroredHost.counter.load()))
assert.Equal(t, 5, int(erroredHost.penalty))
assert.Equal(t, penaltySize, int(erroredHost.penalty))
// should be counter + penalty
assert.Equal(t, 5, int(erroredHost.load()))
assert.Equal(t, penaltySize, int(erroredHost.load()))

assert.Equal(t, mhs.hs, mhs.hst)
}
Expand Down

0 comments on commit 6fd697b

Please sign in to comment.