Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert in memory locks #203

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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