From 70105477cf7b0de148c7909798ad39aa920beb4d Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Thu, 7 Jan 2016 17:54:21 -0800 Subject: [PATCH] added Close() method to KVBatch interface --- index/store/batch.go | 4 ++++ index/store/goleveldb/batch.go | 7 +++++++ index/store/kvstore.go | 3 +++ index/store/metrics/batch.go | 6 ++++++ index/store/null/null.go | 1 + 5 files changed, 21 insertions(+) diff --git a/index/store/batch.go b/index/store/batch.go index 07a22ddd..231dc0ba 100644 --- a/index/store/batch.go +++ b/index/store/batch.go @@ -51,3 +51,7 @@ func (b *EmulatedBatch) Merge(key, val []byte) { func (b *EmulatedBatch) Reset() { b.Ops = b.Ops[:0] } + +func (b *EmulatedBatch) Close() error { + return nil +} diff --git a/index/store/goleveldb/batch.go b/index/store/goleveldb/batch.go index 91b2598e..b909f822 100644 --- a/index/store/goleveldb/batch.go +++ b/index/store/goleveldb/batch.go @@ -36,3 +36,10 @@ func (b *Batch) Reset() { b.batch.Reset() b.merge = store.NewEmulatedMerge(b.store.mo) } + +func (b *Batch) Close() error { + b.batch.Reset() + b.batch = nil + b.merge = nil + return nil +} diff --git a/index/store/kvstore.go b/index/store/kvstore.go index e1e04d73..d1ecea3e 100644 --- a/index/store/kvstore.go +++ b/index/store/kvstore.go @@ -118,4 +118,7 @@ type KVBatch interface { // Reset frees resources for this batch and allows reuse Reset() + + // Close frees resources + Close() error } diff --git a/index/store/metrics/batch.go b/index/store/metrics/batch.go index 8c30448f..146cb4b3 100644 --- a/index/store/metrics/batch.go +++ b/index/store/metrics/batch.go @@ -24,3 +24,9 @@ func (b *Batch) Merge(key, val []byte) { func (b *Batch) Reset() { b.o.Reset() } + +func (b *Batch) Close() error { + err := b.o.Close() + b.o = nil + return err +} diff --git a/index/store/null/null.go b/index/store/null/null.go index 53ebbca8..92be3330 100644 --- a/index/store/null/null.go +++ b/index/store/null/null.go @@ -84,6 +84,7 @@ func (i *batch) Set(key, val []byte) {} func (i *batch) Delete(key []byte) {} func (i *batch) Merge(key, val []byte) {} func (i *batch) Reset() {} +func (i *batch) Close() error { return nil } type writer struct{}