Skip to content

Commit

Permalink
spanner: fix incorrect decreasing metrics
Browse files Browse the repository at this point in the history
This issue happens when the number of sessions is downsizing to a
smaller value during a health recyling period (10 mins). When the
session pool does not need this many sessions, the health maintainer
will adjust the number of sessions to a lower number.

The current implementation to decrease numReads and numWrites is
incorrect because `p.idleList.Remove` and `p.idleWriteList.Remove`
always return a non-nil value. This leads to a decrease for both
metrics at the same time.

Change-Id: Ie21c30200559ebbe95ec09c65e7e54040fcf0cfc
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/54830
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Knut Olav Løite <koloite@gmail.com>
  • Loading branch information
hengfengli committed Apr 17, 2020
1 parent 6c4815c commit 6c924e2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions spanner/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,12 @@ func (p *sessionPool) remove(s *session, isExpire bool) bool {
// If the session is in the idlelist, remove it.
if ol != nil {
// Remove from whichever list it is in.
var elem interface{}
elem = p.idleList.Remove(ol)
if elem != nil {
p.decNumReadsLocked(ctx)
}
elem = p.idleWriteList.Remove(ol)
if elem != nil {
p.idleList.Remove(ol)
p.idleWriteList.Remove(ol)
if s.isWritePrepared() {
p.decNumWritesLocked(ctx)
} else {
p.decNumReadsLocked(ctx)
}
}
if s.invalidate() {
Expand Down

0 comments on commit 6c924e2

Please sign in to comment.