Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14173)

Issue 7803043: code review 7803043: database/sql: associate a mutex with each driver interface (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by bradfitz
Modified:
11 years, 1 month ago
Reviewers:
CC:
golang-dev, adg
Visibility:
Public.

Description

database/sql: associate a mutex with each driver interface The database/sql/driver docs make this promise: "Conn is a connection to a database. It is not used concurrently by multiple goroutines." That promises exists as part of database/sql's overall goal of making drivers relatively easy to write. So far this promise has been kept without the use of locks by being careful in the database/sql package, but sometimes too careful. (cf. golang.org/issue/3857) The CL associates a Mutex with each driver.Conn, and with the interface value progeny thereof. (e.g. each driver.Tx, driver.Stmt, driver.Rows, driver.Result, etc) Then whenever those interface values are used, the Locker is locked. This CL should be a no-op (aside from some new Lock/Unlock pairs) and doesn't attempt to fix Issue 3857 or Issue 4459, but should make it much easier in a subsequent CL. Update issue 3857

Patch Set 1 #

Patch Set 2 : diff -r 28dbe614d61c https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 28dbe614d61c https://go.googlecode.com/hg/ #

Total comments: 4

Patch Set 4 : diff -r 28dbe614d61c https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 5 : diff -r 74da57c3abfe https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 18df6358619a https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+219 lines, -113 lines) Patch
M src/pkg/database/sql/convert.go View 1 2 chunks +8 lines, -2 lines 0 comments Download
M src/pkg/database/sql/sql.go View 1 2 3 4 5 37 chunks +207 lines, -106 lines 0 comments Download
M src/pkg/database/sql/sql_test.go View 1 4 chunks +4 lines, -5 lines 0 comments Download

Messages

Total messages: 12
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 1 month ago (2013-03-13 22:52:39 UTC) #1
bradfitz
This CL probably looks scarier than it is, due to some variable renaming. For example. ...
11 years, 1 month ago (2013-03-13 22:55:44 UTC) #2
adg
I'm wondering whether you should be using defer to unlock before calling into driver-implemented functions. ...
11 years, 1 month ago (2013-03-14 00:53:43 UTC) #3
bradfitz
https://codereview.appspot.com/7803043/diff/6/src/pkg/database/sql/sql.go File src/pkg/database/sql/sql.go (right): https://codereview.appspot.com/7803043/diff/6/src/pkg/database/sql/sql.go#newcode602 src/pkg/database/sql/sql.go:602: withLock(dc, func() { si.Close() }) On 2013/03/14 00:53:43, adg ...
11 years, 1 month ago (2013-03-14 00:55:30 UTC) #4
bradfitz
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 1 month ago (2013-03-14 01:17:14 UTC) #5
adg
https://codereview.appspot.com/7803043/diff/11001/src/pkg/database/sql/sql.go File src/pkg/database/sql/sql.go (right): https://codereview.appspot.com/7803043/diff/11001/src/pkg/database/sql/sql.go#newcode1330 src/pkg/database/sql/sql.go:1330: func withLock(lk sync.Locker, fn func()) { I don't think ...
11 years, 1 month ago (2013-03-14 02:13:27 UTC) #6
bradfitz
I added withLock just for brevity of the defers where it's shorter. Then I thought ...
11 years, 1 month ago (2013-03-14 03:15:48 UTC) #7
adg
On 14 March 2013 14:15, Brad Fitzpatrick <bradfitz@golang.org> wrote: > I added withLock just for ...
11 years, 1 month ago (2013-03-14 03:31:04 UTC) #8
bradfitz
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 1 month ago (2013-03-14 16:55:54 UTC) #9
bradfitz
Okay, re-uploaded only using withLock for defers. On Wed, Mar 13, 2013 at 8:30 PM, ...
11 years, 1 month ago (2013-03-14 16:56:09 UTC) #10
adg
LGTM
11 years, 1 month ago (2013-03-14 21:52:01 UTC) #11
bradfitz
11 years, 1 month ago (2013-03-14 22:01:48 UTC) #12
*** Submitted as https://code.google.com/p/go/source/detail?r=0c029965805f ***

database/sql: associate a mutex with each driver interface

The database/sql/driver docs make this promise:

   "Conn is a connection to a database. It is not used
   concurrently by multiple goroutines."

That promises exists as part of database/sql's overall
goal of making drivers relatively easy to write.

So far this promise has been kept without the use of locks by
being careful in the database/sql package, but sometimes too
careful. (cf. golang.org/issue/3857)

The CL associates a Mutex with each driver.Conn, and with the
interface value progeny thereof. (e.g. each driver.Tx,
driver.Stmt, driver.Rows, driver.Result, etc) Then whenever
those interface values are used, the Locker is locked.

This CL should be a no-op (aside from some new Lock/Unlock
pairs) and doesn't attempt to fix Issue 3857 or Issue 4459,
but should make it much easier in a subsequent CL.

Update issue 3857

R=golang-dev, adg
CC=golang-dev
https://codereview.appspot.com/7803043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b