forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
78650: server, sql: expose closed sessions to ListSessions endpoint r=gtr a=gtr This is the second phase of cockroachdb#67888 which is to expose closed sessions to the ListSessions endpoint. Previously, the ListSessions endpoint only returned open sessions. This change builds on top of the previous PR to add the `ClosedSessionsCache` and now allows the ListSessions endpoint to also return closed sessions in its response. The `ListSessionsRequest` object was edited to include a flag `exclude_closed_sessions` which is a boolean to exclude closed sessions. If unspecified, defaults to false and closed sessions are included in the response. Additionally, the `serverpb.Session` object was updated to include new `end` and `status` fields which specify the time the session ended and the status (opened, closed) of the session, respectively. To test the changes, I made a test `TestListClosedSessions` which creates three users. For each user, we create 10 closed sessions, 5 open sessions, and 3 idle sessions. - The closed sessions are created by opening 10 DB connections and then closing them right after: ```go // Open 10 sessions for each user and then close them. for _, user := range users { for i := 0; i < 10; i++ { targetDB := getUserConn(t, user, testCluster.Server(0)) dbs = append(dbs, targetDB) sqlutils.MakeSQLRunner(targetDB).Exec(t, `SELECT version()`) } } for _, db := range dbs { err := db.Close() require.NoError(t, err) } ``` - The open sessions are created by opening up 5 DB connections and running `pg_sleep(30)` concurrently: ```go // Open 5 sessions for the user and leave them open by running pg_sleep(30). for _, user := range users { for i := 0; i < 5; i++ { wg.Add(1) go func(user string) { // Open a session for the target user. targetDB := getUserConn(t, user, testCluster.Server(0)) defer targetDB.Close() defer wg.Done() sqlutils.MakeSQLRunner(targetDB).Exec(t, `SELECT pg_sleep(30)`) }(user) } } ``` - The idle sessions are created by opening up 3 DB connections and running `SELECT version()` (which finishes executing almost instantaneously) but deferring the `db.Close()` call until the end of the test: ```go // Open 3 sessions for each user and leave them idle by running version(). for _, user := range users { for i := 0; i < 3; i++ { targetDB := getUserConn(t, user, testCluster.Server(0)) defer targetDB.Close() sqlutils.MakeSQLRunner(targetDB).Exec(t, `SELECT version()`) } } ``` These are the results for the three users: ``` username: test_user_a ------------------------------------- Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: IDLE Status: IDLE Status: IDLE username: test_user_b ------------------------------------- Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: IDLE Status: IDLE Status: IDLE username: test_user_c ------------------------------------- Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: CLOSED Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: ACTIVE Status: IDLE Status: IDLE Status: IDLE ``` Release note (api change): `ListSessions` now returns closed sessions in addition to open sessions; `ListSessionsRequest` now has a `exclude_closed_sessions` flag; `serverpb.Session` now has `end` and `status` fields. Co-authored-by: Gerardo Torres <[email protected]>
- Loading branch information
Showing
26 changed files
with
398 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.