ethdb, core: implement delete for db batch (#17101)

This commit is contained in:
gary rong
2018-07-02 16:16:30 +08:00
committed by Péter Szilágyi
parent fdfd6d3c39
commit a4a2343cdc
6 changed files with 51 additions and 14 deletions

View File

@ -110,11 +110,20 @@ func (b *memBatch) Put(key, value []byte) error {
return nil
}
func (b *memBatch) Delete(key []byte) error {
b.writes = append(b.writes, kv{common.CopyBytes(key), nil})
return nil
}
func (b *memBatch) Write() error {
b.db.lock.Lock()
defer b.db.lock.Unlock()
for _, kv := range b.writes {
if kv.v == nil {
delete(b.db.db, string(kv.k))
continue
}
b.db.db[string(kv.k)] = kv.v
}
return nil