-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(spanner): fix negative values for max_in_use_sessions metrics #10449
Changes from 2 commits
6ad748f
837ea3b
78e81d5
0d4cbca
82b7b78
2b12dd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1022,6 +1022,57 @@ func TestMinOpenedSessions(t *testing.T) { | |
} | ||
} | ||
|
||
// TestPositiveNumInUseSessions tests that num_in_use session should always be greater than 0. | ||
func TestPositiveNumInUseSessions(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
_, client, teardown := setupMockedTestServerWithConfig(t, | ||
ClientConfig{ | ||
SessionPoolConfig: SessionPoolConfig{ | ||
MinOpened: 1, | ||
healthCheckSampleInterval: time.Millisecond, | ||
}, | ||
}) | ||
defer teardown() | ||
sp := client.idleSessions | ||
defer sp.close(ctx) | ||
// Take ten sessions from session pool and recycle them. | ||
var shs []*sessionHandle | ||
for i := 0; i < 10; i++ { | ||
sh, err := sp.take(ctx) | ||
if err != nil { | ||
t.Fatalf("failed to get session(%v): %v", i, err) | ||
} | ||
shs = append(shs, sh) | ||
} | ||
for _, sh := range shs { | ||
sh.recycle() | ||
} | ||
|
||
for true { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can we add an escape hatch to the loop (e.g. stop after X time)? Now a future bug could cause this to loop for ever, which is harder to debug than a test failure after for example 2 seconds. |
||
sp.mu.Lock() | ||
if sp.idleList.Len() == 1 { | ||
sp.mu.Unlock() | ||
break | ||
} | ||
sp.mu.Unlock() | ||
continue | ||
} | ||
sp.mu.Lock() | ||
defer sp.mu.Unlock() | ||
if int64(sp.numInUse) < 0 { | ||
t.Fatal("numInUse must be >= 0") | ||
} | ||
// There should be still one session left in either the idle list or in one | ||
// of the other opened states due to the min open sessions constraint. | ||
if (sp.idleList.Len() + | ||
int(sp.createReqs)) != 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can this be on one line (I found it hard to read in the current form) |
||
t.Fatalf( | ||
"got %v sessions in idle lists, want 1. Opened: %d, Creation: %d", | ||
sp.idleList.Len(), sp.numOpened, sp.createReqs) | ||
} | ||
} | ||
|
||
// TestMaxBurst tests max burst constraint. | ||
func TestMaxBurst(t *testing.T) { | ||
t.Parallel() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be better to add an additional argument to the
remove(..)
method that explicitly says whether the session was in use or not. So something like this:In theory, it could be that this method is called in the future to remove sessions that have not expired, but that also were not in use at the time that they were being removed, and then we could re-introduce a similar bug as the one here. That is less likely with an explicit argument that clearly says what it is for.