Skip to content

Commit

Permalink
Merge pull request #203 from lovoo/revert_in_memory_locks
Browse files Browse the repository at this point in the history
revert in memory locks
  • Loading branch information
Benjamin Riedel authored Oct 10, 2019
2 parents 80207ca + 8801b53 commit 2554930
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions storage/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"strings"
"sync"

"github.com/syndtr/goleveldb/leveldb/util"
)
Expand Down Expand Up @@ -71,8 +70,6 @@ type memory struct {
storage map[string][]byte
offset *int64
recovered bool
// mutex to protect map reads/writes
rwm sync.RWMutex
}

// NewMemory returns a new in-memory storage.
Expand All @@ -84,33 +81,25 @@ func NewMemory() Storage {
}

func (m *memory) Has(key string) (bool, error) {
m.rwm.RLock()
_, has := m.storage[key]
m.rwm.RUnlock()
return has, nil
}

func (m *memory) Get(key string) ([]byte, error) {
m.rwm.RLock()
value, _ := m.storage[key]
m.rwm.RUnlock()
return value, nil
}

func (m *memory) Set(key string, value []byte) error {
if value == nil {
return fmt.Errorf("cannot write nil value")
}
m.rwm.Lock()
m.storage[key] = value
m.rwm.Unlock()
return nil
}

func (m *memory) Delete(key string) error {
m.rwm.Lock()
delete(m.storage, key)
m.rwm.Unlock()
return nil
}

Expand Down

0 comments on commit 2554930

Please sign in to comment.