mirror of https://github.com/ledisdb/ledisdb.git
remove BatchWrite Close
leveled and rocksdb use runtime SetFinalizer instead
This commit is contained in:
parent
39521c29e9
commit
a712a95d0d
|
@ -27,7 +27,7 @@ func newTx(l *Ledis) *tx {
|
|||
}
|
||||
|
||||
func (t *tx) Close() {
|
||||
t.wb.Close()
|
||||
t.wb = nil
|
||||
}
|
||||
|
||||
func (t *tx) Put(key []byte, value []byte) {
|
||||
|
|
|
@ -40,8 +40,6 @@ type IIterator interface {
|
|||
}
|
||||
|
||||
type IWriteBatch interface {
|
||||
Close() error
|
||||
|
||||
Put(key []byte, value []byte)
|
||||
Delete(key []byte)
|
||||
Commit() error
|
||||
|
|
|
@ -9,10 +9,6 @@ type WriteBatch struct {
|
|||
wbatch *leveldb.Batch
|
||||
}
|
||||
|
||||
func (w *WriteBatch) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WriteBatch) Put(key, value []byte) {
|
||||
w.wbatch.Put(key, value)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ type WriteBatch struct {
|
|||
|
||||
func (w *WriteBatch) Close() error {
|
||||
C.leveldb_writebatch_destroy(w.wbatch)
|
||||
w.wbatch = nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import "C"
|
|||
import (
|
||||
"github.com/siddontang/ledisdb/store/driver"
|
||||
"os"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -187,6 +188,10 @@ func (db *DB) NewWriteBatch() driver.IWriteBatch {
|
|||
db: db,
|
||||
wbatch: C.leveldb_writebatch_create(),
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(wb, func(w *WriteBatch) {
|
||||
w.Close()
|
||||
})
|
||||
return wb
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,6 @@ type WriteBatch struct {
|
|||
wb []Write
|
||||
}
|
||||
|
||||
func (w *WriteBatch) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WriteBatch) Put(key, value []byte) {
|
||||
w.wb = append(w.wb, Write{key, value})
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ type WriteBatch struct {
|
|||
|
||||
func (w *WriteBatch) Close() error {
|
||||
C.rocksdb_writebatch_destroy(w.wbatch)
|
||||
w.wbatch = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -207,6 +207,11 @@ func (db *DB) NewWriteBatch() driver.IWriteBatch {
|
|||
db: db,
|
||||
wbatch: C.rocksdb_writebatch_create(),
|
||||
}
|
||||
|
||||
runtime.SetFinalizer(wb, func(w *WriteBatch) {
|
||||
w.Close()
|
||||
})
|
||||
|
||||
return wb
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ func testBatch(db *DB, t *testing.T) {
|
|||
db.Put(key2, value)
|
||||
|
||||
wb := db.NewWriteBatch()
|
||||
defer wb.Close()
|
||||
|
||||
wb.Delete(key2)
|
||||
wb.Put(key1, []byte("hello world2"))
|
||||
|
|
Loading…
Reference in New Issue