aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/driver
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-10-02 11:16:53 -0700
committerDaniel Theophanes <kardianos@gmail.com>2017-10-24 21:37:46 +0000
commit6a223b82a466540ea5de1e9f8a7bfea31d77e07d (patch)
tree23b322747082658001a7b8b4d286918ab6fac881 /src/database/sql/driver
parenta5868a47c6777de4a4592903ba8763740cde3c49 (diff)
downloadgo-6a223b82a466540ea5de1e9f8a7bfea31d77e07d.tar.xz
database/sql: add driver.ResetSessioner and add pool support
A single database connection ususally maps to a single session. A connection pool is logically also a session pool. Most sessions have a way to reset the session state which is desirable to prevent one bad query from poisoning another later query with temp table name conflicts or other persistent session resources. It also lets drivers provide users with better error messages from queryies when the underlying transport or query method fails. Internally the driver connection should now be marked as bad, but return the actual connection. When ResetSession is called on the connection it should return driver.ErrBadConn to remove it from the connection pool. Previously drivers had to choose between meaningful error messages or poisoning the connection pool. Lastly update TestPoolExhaustOnCancel from relying on a WAIT query fixing a flaky timeout issue exposed by this change. Fixes #22049 Fixes #20807 Change-Id: I2b5df6d954a38d0ad93bf1922ec16e74c827274c Reviewed-on: https://go-review.googlesource.com/73033 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/database/sql/driver')
-rw-r--r--src/database/sql/driver/driver.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go
index f5a2e7c16c..6113af79c5 100644
--- a/src/database/sql/driver/driver.go
+++ b/src/database/sql/driver/driver.go
@@ -222,6 +222,18 @@ type ConnBeginTx interface {
BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
}
+// ResetSessioner may be implemented by Conn to allow drivers to reset the
+// session state associated with the connection and to signal a bad connection.
+type ResetSessioner 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(ctx context.Context) error
+}
+
// Result is the result of a query execution.
type Result interface {
// LastInsertId returns the database's auto-generated ID