diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-10-13 17:04:25 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-10-21 21:49:55 +0800 |
commit | 5b0ee8ec304663898073b7a4c659e1def23716df (patch) | |
tree | 8f2f49a8d26dc1c29e1d360fb787ab420d90a2ae /ethdb | |
parent | aa0538db0b5de2bb2c609d629b65d083649f9171 (diff) | |
download | dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar.gz dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar.bz2 dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar.lz dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar.xz dexon-5b0ee8ec304663898073b7a4c659e1def23716df.tar.zst dexon-5b0ee8ec304663898073b7a4c659e1def23716df.zip |
core, eth, trie: fix data races and merge/review issues
Diffstat (limited to 'ethdb')
-rw-r--r-- | ethdb/memory_database.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index 330834fa4..01273b9db 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -17,6 +17,7 @@ package ethdb import ( + "errors" "fmt" "sync" @@ -56,7 +57,10 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) { db.lock.RLock() defer db.lock.RUnlock() - return db.db[string(key)], nil + if entry, ok := db.db[string(key)]; ok { + return entry, nil + } + return nil, errors.New("not found") } func (db *MemDatabase) Keys() [][]byte { @@ -132,8 +136,8 @@ func (b *memBatch) Write() error { b.lock.RLock() defer b.lock.RUnlock() - b.db.lock.RLock() - defer b.db.lock.RUnlock() + b.db.lock.Lock() + defer b.db.lock.Unlock() for _, kv := range b.writes { b.db.db[string(kv.k)] = kv.v |