mirror of https://github.com/perkeep/perkeep.git
pkg/sorted/sqlkv: don't release gate until iterator is closed
Change-Id: I4c3f5406b89294c09fb1d64aaeffc3c581664acd
This commit is contained in:
parent
b3ba9aa7cd
commit
8cf4f297eb
|
@ -204,12 +204,10 @@ func (kv *KeyValue) Wipe() error {
|
|||
func (kv *KeyValue) Close() error { return kv.DB.Close() }
|
||||
|
||||
func (kv *KeyValue) Find(start, end string) sorted.Iterator {
|
||||
var releaseGate func() // nil if unused
|
||||
if kv.Gate != nil {
|
||||
kv.Gate.Start()
|
||||
// TODO(mpl): looks like sqlite considers the db locked until we've closed
|
||||
// the iterator, so we can't do anything else until then. We should probably
|
||||
// move that Unlock to the closing of the iterator. Investigating.
|
||||
defer kv.Gate.Done()
|
||||
releaseGate = kv.Gate.Done
|
||||
}
|
||||
var rows *sql.Rows
|
||||
var err error
|
||||
|
@ -227,6 +225,7 @@ func (kv *KeyValue) Find(start, end string) sorted.Iterator {
|
|||
kv: kv,
|
||||
rows: rows,
|
||||
closeCheck: leak.NewChecker(),
|
||||
releaseGate: releaseGate,
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
@ -240,6 +239,7 @@ type iter struct {
|
|||
err error // accumulated error, returned at Close
|
||||
|
||||
closeCheck *leak.Checker
|
||||
releaseGate func() // if non-nil, called on Close
|
||||
|
||||
rows *sql.Rows // if non-nil, the rows we're reading from
|
||||
|
||||
|
@ -276,6 +276,9 @@ func (t *iter) Close() error {
|
|||
t.rows.Close()
|
||||
t.rows = nil
|
||||
}
|
||||
if t.releaseGate != nil {
|
||||
t.releaseGate()
|
||||
}
|
||||
err := t.err
|
||||
t.err = errClosed
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue