Skip to content

Commit 41c5d8d

Browse files
tadglinesbradfitz
authored andcommitted
database/sql: add SetMaxOpenConns
Update #4805 Add the ability to set an open connection limit. Fixed case where the Conn finalCloser was being called with db.mu locked. Added separate benchmarks for each path for Exec and Query. Replaced slice based idle pool with list based idle pool. R=bradfitz CC=golang-dev https://golang.org/cl/10726044
1 parent 87404c9 commit 41c5d8d

File tree

4 files changed

+826
-76
lines changed

4 files changed

+826
-76
lines changed

src/pkg/database/sql/fakedb_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ func (c *fakeConn) Prepare(query string) (driver.Stmt, error) {
447447
return c.prepareCreate(stmt, parts)
448448
case "INSERT":
449449
return c.prepareInsert(stmt, parts)
450+
case "NOSERT":
451+
// Do all the prep-work like for an INSERT but don't actually insert the row.
452+
// Used for some of the concurrent tests.
453+
return c.prepareInsert(stmt, parts)
450454
default:
451455
stmt.Close()
452456
return nil, errf("unsupported command type %q", cmd)
@@ -497,13 +501,20 @@ func (s *fakeStmt) Exec(args []driver.Value) (driver.Result, error) {
497501
}
498502
return driver.ResultNoRows, nil
499503
case "INSERT":
500-
return s.execInsert(args)
504+
return s.execInsert(args, true)
505+
case "NOSERT":
506+
// Do all the prep-work like for an INSERT but don't actually insert the row.
507+
// Used for some of the concurrent tests.
508+
return s.execInsert(args, false)
501509
}
502510
fmt.Printf("EXEC statement, cmd=%q: %#v\n", s.cmd, s)
503511
return nil, fmt.Errorf("unimplemented statement Exec command type of %q", s.cmd)
504512
}
505513

506-
func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
514+
// When doInsert is true, add the row to the table.
515+
// When doInsert is false do prep-work and error checking, but don't
516+
// actually add the row to the table.
517+
func (s *fakeStmt) execInsert(args []driver.Value, doInsert bool) (driver.Result, error) {
507518
db := s.c.db
508519
if len(args) != s.placeholders {
509520
panic("error in pkg db; should only get here if size is correct")
@@ -518,7 +529,10 @@ func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
518529
t.mu.Lock()
519530
defer t.mu.Unlock()
520531

521-
cols := make([]interface{}, len(t.colname))
532+
var cols []interface{}
533+
if doInsert {
534+
cols = make([]interface{}, len(t.colname))
535+
}
522536
argPos := 0
523537
for n, colname := range s.colName {
524538
colidx := t.columnIndex(colname)
@@ -532,10 +546,14 @@ func (s *fakeStmt) execInsert(args []driver.Value) (driver.Result, error) {
532546
} else {
533547
val = s.colValue[n]
534548
}
535-
cols[colidx] = val
549+
if doInsert {
550+
cols[colidx] = val
551+
}
536552
}
537553

538-
t.rows = append(t.rows, &row{cols: cols})
554+
if doInsert {
555+
t.rows = append(t.rows, &row{cols: cols})
556+
}
539557
return driver.RowsAffected(1), nil
540558
}
541559

0 commit comments

Comments
 (0)