diff options
| author | Daniel Theophanes <kardianos@gmail.com> | 2019-04-26 14:45:46 -0700 |
|---|---|---|
| committer | Daniel Theophanes <kardianos@gmail.com> | 2020-03-17 23:02:30 +0000 |
| commit | 971f8a2f9a5beb0473f82d7299613c86d2b4a5b9 (patch) | |
| tree | 3e9675583d65cce4c6c0e60e155564af55cf952f /src/database/sql/driver/driver.go | |
| parent | 0eeec4f25dc6eccc4e76ab91053e2b4823c72714 (diff) | |
| download | go-971f8a2f9a5beb0473f82d7299613c86d2b4a5b9.tar.xz | |
database/sql: process all Session Resets synchronously
Adds a new interface, driver.ConnectionValidator, to allow
drivers to signal they should not be used again,
separatly from the session resetter interface.
This is done now that the session reset is done
after the connection is put into the connection pool.
Previous behavior attempted to run Session Resets
in a background worker. This implementation had two
problems: untested performance gains for additional
complexity, and failures when the pool size
exceeded the connection reset channel buffer size.
Fixes #31480
Change-Id: I7d483b883c24a362c292471e87a88db5b204d1d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/174122
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/driver/driver.go')
| -rw-r--r-- | src/database/sql/driver/driver.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go index 316e7cea37..a2b844d71f 100644 --- a/src/database/sql/driver/driver.go +++ b/src/database/sql/driver/driver.go @@ -255,15 +255,23 @@ type ConnBeginTx interface { // SessionResetter may be implemented by Conn to allow drivers to reset the // session state associated with the connection and to signal a bad connection. type SessionResetter interface { - // ResetSession is called while a connection is in the connection - // pool. No queries will run on this connection until this method returns. - // - // If the connection is bad this should return driver.ErrBadConn to prevent - // the connection from being returned to the connection pool. Any other - // error will be discarded. + // ResetSession is called prior to executing a query on the connection + // if the connection has been used before. If the driver returns ErrBadConn + // the connection is discarded. ResetSession(ctx context.Context) error } +// ConnectionValidator may be implemented by Conn to allow drivers to +// signal if a connection is valid or if it should be discarded. +// +// If implemented, drivers may return the underlying error from queries, +// even if the connection should be discarded by the connection pool. +type ConnectionValidator interface { + // ValidConnection is called prior to placing the connection into the + // connection pool. The connection will be discarded if false is returned. + ValidConnection() bool +} + // Result is the result of a query execution. type Result interface { // LastInsertId returns the database's auto-generated ID |
