mirror of https://github.com/perkeep/perkeep.git
sorted/mysql: remove DB from pool when closing
Otherwise when openOrCachedDB is called for the second time, it would return an actually closed DB. Change-Id: I820834e508fed1a34ab7bd19a8a91e398badff9c
This commit is contained in:
parent
77dcc0559d
commit
c88d81a2fd
|
@ -95,7 +95,8 @@ func newKeyValueFromJSONConfig(cfg jsonconfig.Obj) (sorted.KeyValue, error) {
|
|||
}
|
||||
|
||||
kv := &keyValue{
|
||||
db: db,
|
||||
dsn: dsn,
|
||||
db: db,
|
||||
KeyValue: &sqlkv.KeyValue{
|
||||
DB: db,
|
||||
TablePrefix: database + ".",
|
||||
|
@ -158,7 +159,17 @@ func openOrCachedDB(dsn string) (*sql.DB, error) {
|
|||
type keyValue struct {
|
||||
*sqlkv.KeyValue
|
||||
|
||||
db *sql.DB
|
||||
dsn string
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
// Close overrides KeyValue.Close because we need to remove the DB from the pool
|
||||
// when closing.
|
||||
func (kv *keyValue) Close() error {
|
||||
dbsmu.Lock()
|
||||
defer dbsmu.Unlock()
|
||||
delete(dbs, kv.dsn)
|
||||
return kv.DB.Close()
|
||||
}
|
||||
|
||||
func (kv *keyValue) ping() error {
|
||||
|
|
Loading…
Reference in New Issue