Unverified Commit 22c5a172 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #108 from ipfs/chore/log-finalizer

Log error if batch not committed or canceled
parents 8a4303f9 78c54b53
...@@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) { ...@@ -409,7 +409,10 @@ func (d *Datastore) Batch() (ds.Batch, error) {
b := &batch{d, d.DB.NewWriteBatch()} b := &batch{d, d.DB.NewWriteBatch()}
// Ensure that incomplete transaction resources are cleaned up in case // Ensure that incomplete transaction resources are cleaned up in case
// batch is abandoned. // batch is abandoned.
runtime.SetFinalizer(b, func(b *batch) { b.cancel() }) runtime.SetFinalizer(b, func(b *batch) {
b.cancel()
log.Error("batch not committed or canceled")
})
return b, nil return b, nil
} }
...@@ -481,8 +484,10 @@ func (b *batch) commit() error { ...@@ -481,8 +484,10 @@ func (b *batch) commit() error {
if err != nil { if err != nil {
// Discard incomplete transaction held by b.writeBatch // Discard incomplete transaction held by b.writeBatch
b.cancel() b.cancel()
return err
} }
return err runtime.SetFinalizer(b, nil)
return nil
} }
func (b *batch) Cancel() error { func (b *batch) Cancel() error {
...@@ -498,6 +503,7 @@ func (b *batch) Cancel() error { ...@@ -498,6 +503,7 @@ func (b *batch) Cancel() error {
func (b *batch) cancel() { func (b *batch) cancel() {
b.writeBatch.Cancel() b.writeBatch.Cancel()
runtime.SetFinalizer(b, nil)
} }
var _ ds.Datastore = (*txn)(nil) var _ ds.Datastore = (*txn)(nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment