aboutsummaryrefslogtreecommitdiff
path: root/src/database
AgeCommit message (Collapse)Author
2022-09-28database: use bytes.Clonecuiweixie
Change-Id: I66aad199884cffd51946f53f01580a3a353f5c97 Reviewed-on: https://go-review.googlesource.com/c/go/+/435280 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org>
2022-09-15database: convert DB.{waitDuration,numClosed} to atomic typecuiweixie
Change-Id: I4a67a5e51a98938c07b3c38442f8d852db97cb2a Reviewed-on: https://go-review.googlesource.com/c/go/+/426085 Run-TryBot: Jenny Rakoczy <jenny@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jenny Rakoczy <jenny@golang.org> Run-TryBot: xie cui <523516579@qq.com> Auto-Submit: Jenny Rakoczy <jenny@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2022-09-08database: convert Tx.done to atomic typecuiweixie
Change-Id: I9ec725009376f5865adedca6c159b14140dde097 Reviewed-on: https://go-review.googlesource.com/c/go/+/426086 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
2022-09-07database/sql: simplify retry logic when the connection is badJinzhu
Simplify retry logic when got bad connection Change-Id: I92494c6c020576ec01bc4868334ee920ded7aa57 GitHub-Last-Rev: 7499b0c9419a31c9adce6d5096a1924aa3612f1d GitHub-Pull-Request: golang/go#54043 Reviewed-on: https://go-review.googlesource.com/c/go/+/419182 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> Run-TryBot: hopehook <hopehook@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-07-11database/sql: make TestTxContextWaitNoDiscard test more robustDmitri Goutnik
Similar to CL 385934, rely on waiter trigger instead of the WAIT query prefix and factor out the common test code. Fixes #53222 Change-Id: I46efc85ca102b350bb4dbe8e514921e016870ffb Reviewed-on: https://go-review.googlesource.com/c/go/+/416655 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-06-04database/sql/driver: fix typo in driver.gomstmdev
ExecerContext -> ExecContext QueryerContext -> QueryContext Change-Id: Id3b1f44de5aa47372d59696523b4379e1fbfc11c GitHub-Last-Rev: 571d01f8052cef27bd5f91a5e95c0735ddf2e327 GitHub-Pull-Request: golang/go#53235 Reviewed-on: https://go-review.googlesource.com/c/go/+/410415 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-19database/sql: fix close rows error ignored in NextJinzhu
Change-Id: I19f0d764e2a6122307f3f26a6dd3be7b1155c73b GitHub-Last-Rev: 9f1f883c452201679a2d2af2cc29de0f09a43f28 GitHub-Pull-Request: golang/go#52756 Reviewed-on: https://go-review.googlesource.com/c/go/+/404794 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17all: fix spellingJohn Bampton
Change-Id: Iee18987c495d1d4bde9da888d454eea8079d3ebc GitHub-Last-Rev: ff5e01599ddf7deb3ab6ce190ba92eb02ae2cb15 GitHub-Pull-Request: golang/go#52949 Reviewed-on: https://go-review.googlesource.com/c/go/+/406915 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-17all: fix spellingJohn Bampton
Change-Id: I68538a50c22b02cdb5aa2a889f9440fed7b94c54 GitHub-Last-Rev: aaac9e78340ac482e9cd1b506a035f271c29648c GitHub-Pull-Request: golang/go#52944 Reviewed-on: https://go-review.googlesource.com/c/go/+/406835 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-05-14database/sql: follow convention for field namingJinzhu
Change-Id: I161072698dad8f184b46c6e627bbfbcb18a1b5c6 GitHub-Last-Rev: 7c8d2412806e6017e7129a5535adace396e6be30 GitHub-Pull-Request: golang/go#52770 Reviewed-on: https://go-review.googlesource.com/c/go/+/404934 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-08all: fix some lint issuesRyan Leung
Make some code more simple. Change-Id: I801adf0dba5f6c515681345c732dbb907f945419 GitHub-Last-Rev: a505146baca00a1b3268d11d10510afa8cea6f1d GitHub-Pull-Request: golang/go#49626 Reviewed-on: https://go-review.googlesource.com/c/go/+/364634 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-01all: fix various doc comment formatting nitsRuss Cox
A run of lines that are indented with any number of spaces or tabs format as a <pre> block. This commit fixes various doc comments that format badly according to that (standard) rule. For example, consider: // - List item. // Second line. // - Another item. Because the - lines are unindented, this is actually two paragraphs separated by a one-line <pre> block. This CL rewrites it to: // - List item. // Second line. // - Another item. Today, that will format as a single <pre> block. In a future release, we hope to format it as a bulleted list. Various other minor fixes as well, all in preparation for reformatting. For #51082. Change-Id: I95cf06040d4186830e571cd50148be3bf8daf189 Reviewed-on: https://go-review.googlesource.com/c/go/+/384257 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-16database/sql: make WAIT tests more robust, rely on waiter triggerDaniel Theophanes
Replace the WAIT query prefix with a function callback. This fixes timing issues when the testing on loaded servers. Fixes #51208 Change-Id: I5151b397b7066c27ce6bc02c160dde0b584934bc Reviewed-on: https://go-review.googlesource.com/c/go/+/385934 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Trust: Daniel Theophanes <kardianos@gmail.com>
2022-01-13database/sql: consolidate test polling loopsBryan C. Mills
Also eliminate some arbitrary deadlines and sleeps. Fixes #49958 Change-Id: I999b39a896e430e3bb93aa8b8c9444f28bbaa9d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/378395 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-11database/sql: prevent closes slices from assigning to free connPavel
In function connectionCleanerRunLocked append to closing slice affects db.freeConns and vise versa. Sometimes valid connections are closed and some invalid not. Change-Id: I5282f15be3e549533b7d994b17b2060db3c0e7da GitHub-Last-Rev: b3eb3ab6f49c036519f777fc7189e9507010c166 GitHub-Pull-Request: golang/go#49429 Reviewed-on: https://go-review.googlesource.com/c/go/+/362214 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-03database/sql: fix tx.Prepare documentationMostafa Solati
Fixes: #45978 Change-Id: I3d5ccd621d670f97bb1a642b4e84b6629347a315 Reviewed-on: https://go-review.googlesource.com/c/go/+/339291 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Mui <cherryyz@google.com>
2021-11-03database/sql: use errors.Is when checking ErrBadConnDaniel Theophanes
When drivers return driver.ErrBadConn, no meaningful information about what the cause of the problem is returned. Ideally the driver.ErrBadConn would be always caught with the retry loop, but this is not always the case. Drivers today must choose between returning a useful error and use the rety logic. This allows supporting both. Fixes #47142 Change-Id: I454573028f041dfdf874eed6c254fb194ccf6d96 Reviewed-on: https://go-review.googlesource.com/c/go/+/333949 Run-TryBot: Ian Lance Taylor <iant@golang.org> Trust: Ian Lance Taylor <iant@golang.org> Trust: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-11-03database/sql: Fix idle connection reuseSteven Hartland
Fix idle connection reuse so that ConnMaxIdleTime clears down excessive idle connections. This now ensures that db.freeConn is ordered by returnedAt and that connections that have been idle for the shortest period are reused first. In addition connectionCleanerRunLocked updates the next check deadline based on idle and maximum life time information so that we avoid waiting up to double MaxIdleTime to close connections. Corrected the calling timer of connectionCleaner. Fixes #39471 Change-Id: I6d26b3542179ef35aa13e5265a89bc0f08ba7fa1 Reviewed-on: https://go-review.googlesource.com/c/go/+/237337 Reviewed-by: Tamás Gulácsi <tgulacsi78@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Ian Lance Taylor <iant@golang.org>
2021-10-26all: use reflect.{Pointer,PointerTo}Cuong Manh Le
Updates #47651 Updates #48665 Change-Id: I69a87b45a5cad7a07fbd855040cd9935cf874554 Reviewed-on: https://go-review.googlesource.com/c/go/+/358454 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-09-14all: remove some unused codeAlexander Melentyev
Change-Id: I519b8021fa79dccc5c0ee79134547491116fc4cc GitHub-Last-Rev: 48869f5434c1255d33c3a14714747509235c94df GitHub-Pull-Request: golang/go#48071 Reviewed-on: https://go-review.googlesource.com/c/go/+/346231 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Keith Randall <khr@golang.org>
2021-09-04database/sql: improve the documentation of Conn.Rawkorzhao
Fixes #47500 Change-Id: Ibd44e4db15ea45bb53a6651a6567edfe6104d3d6 GitHub-Last-Rev: 61b8abbc28908fc807af7188e19089ac454b4817 GitHub-Pull-Request: golang/go#47503 Reviewed-on: https://go-review.googlesource.com/c/go/+/338970 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Mui <cherryyz@google.com>
2021-06-21database/sql: fix deadlock test in prepare statementDaniel Theophanes
The issue go#46783 correctly diagnosed the context timeout caused an intermittent failure when the context was canceled prior to the BeginTx call. However due to the asynchronous nature of canceling a Tx through a context on fast systems, the tx.Prepare also succeeded. On slower systems or if a time.Sleep was inserted between the BeginTx and Prepare, the Prepare would fail. Resolve this by moving the context cancel after the Prepare. This will still trigger the deadlock which I tested locally. In addition, I interspersed multiple time.Sleep calls and the test still functioned. Fixes #46852 Change-Id: I9cbf90d3c12b2555493a37799738772b615ae39d Reviewed-on: https://go-review.googlesource.com/c/go/+/329830 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Bryan C. Mills <bcmills@google.com>
2021-06-19database/sql: do not rely on timeout for deadlock testDaniel Theophanes
Fixes #46783 Change-Id: I8a8d1716279a041a7411c0c47a440a7997b39c80 Reviewed-on: https://go-review.googlesource.com/c/go/+/328649 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Carlos Amedee <carlos@golang.org>
2021-05-04database/sql: add NullInt16 and NullByteAriel Mashraki
Fixes #40082 Change-Id: I01cd4d0e23c0376a6ee6e0b196c9f840cd662325 Reviewed-on: https://go-review.googlesource.com/c/go/+/311572 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-04-10all: fix spellingsNaman Gera
This follows the spelling choices that the Go project has made for English words. https://github.com/golang/go/wiki/Spelling Change-Id: Ie7c586d2cf23020cb492cfff58c0831d2d8d3a78 GitHub-Last-Rev: e16a32cd225a275f73d236bcb33703986d110ded GitHub-Pull-Request: golang/go#45442 Reviewed-on: https://go-review.googlesource.com/c/go/+/308291 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-25database/sql: remove unnecessary types in composite literalsElias506
Change-Id: I30c576f826c82cbc62ce28ea7f4886702bd6605d GitHub-Last-Rev: 2fead200dba13ec74d81e842d8bae97d1e67fcc4 GitHub-Pull-Request: golang/go#42618 Reviewed-on: https://go-review.googlesource.com/c/go/+/270000 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Cherry Zhang <cherryyz@google.com>
2021-03-11docs: clarify when APIs use context.Background.Matt T. Proud
The Go standard library retrofitted context support onto existing APIs using context.Background and later offered variants that directly supported user-defined context value specification. This commit makes that behavior clear in documentation and suggests context-aware alternatives if the user is looking for one. An example motivation is supporting code for use in systems that expect APIs to be cancelable for lifecycle correctness or load shedding/management reasons, as alluded to in https://blog.golang.org/context-and-structs. Updates #44143 Change-Id: I2d7f954ddf9b48264d5ebc8d0007058ff9bddf14 Reviewed-on: https://go-review.googlesource.com/c/go/+/296152 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Jean de Klerk <deklerk@google.com> Trust: Jean de Klerk <deklerk@google.com> Run-TryBot: Jean de Klerk <deklerk@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-02-25database/sql: close driver.Connector if it implements io.CloserIvan Trubach
This change allows driver implementations to manage resources in driver.Connector, e.g. to share the same underlying database handle between multiple connections. That is, it allows embedded databases with in-memory backends like SQLite and Genji to safely release the resources once the sql.DB is closed. This makes it possible to address oddities with in-memory stores in SQLite and Genji drivers without introducing too much complexity in the driver implementations. See also: - https://github.com/mattn/go-sqlite3/issues/204 - https://github.com/mattn/go-sqlite3/issues/511 - https://github.com/genjidb/genji/issues/210 Fixes #41790 Change-Id: Idbd19763134438ed38288b9d44f16608e4e97fd7 GitHub-Last-Rev: 962c785dfb3bb6ad98b2216bcedd84ba383fe872 GitHub-Pull-Request: golang/go#41710 Reviewed-on: https://go-review.googlesource.com/c/go/+/258360 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-02-24database: remove race in TestTxContextWaitJosh Bleecher Snyder
This test contained a data race. On line 437, db.BeginTx starts a goroutine that runs tx.awaitDone, which reads tx.keepConnOnRollback. On line 445, the test writes to tx.keepConnOnRollback. tx.awaitDone waits on ctx, but because ctx is timeout-based, there's no ordering guarantee between the write and the read. The race detector never caught this before because the context package implementation of Done contained enough synchronization to make it safe. That synchronization is not package of the context API or guarantees, and the first several releases it was not present. Another commit soon will remove that synchronization, exposing the latent data race. To fix the race, emulate a time-based context using an explicit cancellation-based context. This gives us enough control to avoid the race. Change-Id: I103fe9b987b1d4c02e7a20ac3c22a682652128b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/288493 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-12-10database/sql: fix typo in commentHein Khant Zaw
Fixes #43116 Change-Id: Ib04fab6ae03f322aa1508ec00523f628d891247a GitHub-Last-Rev: 0a86e665b2c320e0b2aef75ee53bd7281b19b013 GitHub-Pull-Request: golang/go#43122 Reviewed-on: https://go-review.googlesource.com/c/go/+/276992 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-10-31database/sql, runtime: correct *.Fatal inside goroutines in testsEmmanuel T Odeke
Found by go vet pass "testinggoroutines". Change-Id: I6360af2079617b7aa62dcb9bd7254578ca5d1c1d Reviewed-on: https://go-review.googlesource.com/c/go/+/235527 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-29database/sql: fix TestTxStmtDeadlock testTzu-Chiao Yeh
Drop error check because errors can be not only ErrTxDone for tx stmt executions, and the purpose of the test is just reproducing deadlock. Fixes #42259 Change-Id: I9e7105ada1403ec7064dcc1c3385b36893a1c195 Reviewed-on: https://go-review.googlesource.com/c/go/+/266097 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
2020-10-28database/sql: fix tx stmt deadlock when rollbackTzu-Chiao Yeh
Tx acquires tx.closemu W-lock and then acquires stmt.closemu.W-lock to fully close the transaction and associated prepared statement. Stmt query and execution run in reverse ways - acquires stmt.closemu.R-lock and then acquires tx.closemu.R-lock to grab tx connection, which may cause deadlock. Prevent the lock is held around tx.closePrepared to ensure no deadlock happens. Fixes #40985 Change-Id: If53909822b87bce11861a6e3035ecb9476d2cd17 Reviewed-on: https://go-review.googlesource.com/c/go/+/250178 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-10-27database/sql: fix comment on DB.stop()Ayzat Sadykov
Previously, 2 goroutines were created in OpenDB and a comment in the DB.close() field indicated that they were canceled. Later, session Resetter () was removed, but the comment remained the same. This commit just fixes this message Change-Id: Ie81026f51d7770e9cf8004818154021f626fb2e8 GitHub-Last-Rev: 38b338a0d1cd713d71fa547aa842d395e6d75484 GitHub-Pull-Request: golang/go#42191 Reviewed-on: https://go-review.googlesource.com/c/go/+/264838 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Trust: Brad Fitzpatrick <bradfitz@golang.org>
2020-08-29database/sql: shortestIdleTimeLocked correct min comparisonShinnosuke Sawada
When zero or less, maxIdleTime and maxLifetime means unlimited. Helper function shortestIdleTimeLocked must not return the minimum of the two until both are verified to be greater then zero. Fixes #40841 Change-Id: I1130332baf4ad259cd90c10f4221f5def8510655 Reviewed-on: https://go-review.googlesource.com/c/go/+/248817 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-08-14database/sql: make Rows.Scan properly wrap underlying errorsTim Möhlmann
The prior implementation used the format verb %v which unfortunately improperly wrapped any underlying scanner errors, and we couldn't use errors.Is nor errors.As. This change fixes that by using the %w verb. Added a unit to ensure that both error sub string matching works, but also that errors.Is works as expected. Fixes #38099 Change-Id: Iea667041dd8081d961246f77f2542330417292dc Reviewed-on: https://go-review.googlesource.com/c/go/+/248337 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-30database/sql/driver: use correct method name "Connect" in DriverContext docsBrad Erickson
Change-Id: I755fedebb1f8f4d3f27b2b3f8626bca03bd36c88 GitHub-Last-Rev: 4a123572d55ad3b0104d3e6501eef5b2f37af4cd GitHub-Pull-Request: golang/go#39305 Reviewed-on: https://go-review.googlesource.com/c/go/+/235518 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-05-08database/sql: form a complete sentence in code commentKevin Burke
Change-Id: Ib6d0f81b5f64473f9ee6be26a08d5102e8edadc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/229477 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-04-28database/sql: document Connect and Close may need a timeoutDaniel Theophanes
Opening a connection with Connect should still create a derived context with a timeout because some clients will not use a timeout and the connection pool may open a connection asynchronously. Likewise, if a connection close makes a network operation it should provide some type of sane timeout for the operation. Fixes #38185 Change-Id: I9b7ce2996c81c486170dcc84b12672a99610fa27 Reviewed-on: https://go-review.googlesource.com/c/go/+/230438 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-28database/sql: fix incorrect function name in example_testVivian Liang
fixes incorrect function name prefix in `example_test.go` Change-Id: I0cce8afc89f6ee6dab3e5152246d28deb597fe53 GitHub-Last-Rev: 4e9a6067c8307e049ace2e35414a838bf6c8a8a4 GitHub-Pull-Request: golang/go#38715 Reviewed-on: https://go-review.googlesource.com/c/go/+/230381 Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-04-27database/sql/driver: enhance driver package documentationDaniel Theophanes
Change-Id: I455acdb71354f14e0bc4104cbd7abd5c89958dd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/230214 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-22database/sql: de-flake TestTxCannotCommitAfterRollbackDaniel Theophanes
Do not cancel rows during test. Only cancel the Tx. Correct the referenced issue number on the test. Fixes #38597 Change-Id: I0e8ba1bf2a8ba638d121c9c6938501fec1d5e961 Reviewed-on: https://go-review.googlesource.com/c/go/+/229478 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-22database/sql: count connections expired in foreground with MaxLifetimeClosedColin
Previously the connection pool would only count connections expired in the background connectionCleaner goroutine towards the MaxLifetimeClosed stat. This change increments the stat correctly when checking for expiry in when acquiring and releasing a connection. Fixes #38058 Change-Id: Id707ddd40a42a4c38658d5f2931da131647d6c29 GitHub-Last-Rev: 0f205ede439efa355a628b6112450f2ca9ced005 GitHub-Pull-Request: golang/go#38263 Reviewed-on: https://go-review.googlesource.com/c/go/+/227278 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
2020-04-20database/sql: on Tx rollback, retain connection if driver can reset sessionDaniel Theophanes
Previously the Tx would drop the connection after rolling back from a context cancel. Now if the driver can reset the session, keep the connection. Change-Id: Ie6a3124275632787629844d91a06bb2e70cc060b Reviewed-on: https://go-review.googlesource.com/c/go/+/216241 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-20database/sql: prevent Tx statement from committing after rollbackDaniel Theophanes
It was possible for a Tx that was aborted for rollback asynchronously to execute a query after the rollback had completed on the database, which often would auto commit the query outside of the transaction. By W-locking the tx.closemu prior to issuing the rollback connection it ensures any Tx query either fails or finishes on the Tx, and never after the Tx has rolled back. Fixes #34775 Fixes #32942 Change-Id: I017b7932082f2f4ead70bae08b61ed9068ac1d01 Reviewed-on: https://go-review.googlesource.com/c/go/+/216240 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-20database/sql: check conn expiry when returning to pool, not when handing it outDaniel Theophanes
With the original connection reuse strategy, it was possible that when a new connection was requested, the pool would wait for an an existing connection to return for re-use in a full connection pool, and then it would check if the returned connection was expired. If the returned connection expired while awaiting re-use, it would return an error to the location requestiong the new connection. The existing call sites requesting a new connection was often the last attempt at returning a connection for a query. This would then result in a failed query. This change ensures that we perform the expiry check right before a connection is inserted back in to the connection pool for while requesting a new connection. If requesting a new connection it will no longer fail due to the connection expiring. Fixes #32530 Change-Id: If16379befe0e14d90160219c0c9396243fe062f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/216197 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-29database/sql: add test for Conn.Validator interfaceDaniel Theophanes
This addresses comments made by Russ after https://golang.org/cl/174122 was merged. It addes a test for the connection validator and renames the interface to just "Validator". Change-Id: Iea53e9b250c9be2e86e9b75906e7353e26437c5c Reviewed-on: https://go-review.googlesource.com/c/go/+/223963 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>