Merge pull request #3629 from leoluk/fix-boltdb-batch

libs/db: fix boltdb batching
This commit is contained in:
Ismail Khoffi 2019-05-07 09:03:49 +02:00 committed by GitHub
commit 2bb1a87d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,11 +161,11 @@ func (bdb *BoltDB) NewBatch() Batch {
} }
func (bdb *boltDBBatch) Set(key, value []byte) { func (bdb *boltDBBatch) Set(key, value []byte) {
bdb.buffer.Store(key, value) bdb.buffer.Store(string(key), value)
} }
func (bdb *boltDBBatch) Delete(key []byte) { func (bdb *boltDBBatch) Delete(key []byte) {
bdb.buffer.Delete(key) bdb.buffer.Delete(string(key))
} }
// NOTE: the operation is synchronous (see BoltDB for reasons) // NOTE: the operation is synchronous (see BoltDB for reasons)
@ -174,7 +174,7 @@ func (bdb *boltDBBatch) Write() {
b := tx.Bucket(bucket) b := tx.Bucket(bucket)
var putErr error var putErr error
bdb.buffer.Range(func(key, value interface{}) bool { bdb.buffer.Range(func(key, value interface{}) bool {
putErr = b.Put(key.([]byte), value.([]byte)) putErr = b.Put([]byte(key.(string)), value.([]byte))
return putErr == nil // stop if putErr is not nil return putErr == nil // stop if putErr is not nil
}) })
return putErr return putErr