Skip to content

Commit

Permalink
fix: remove mutex in prefixdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kjessec committed Mar 4, 2022
1 parent bf23575 commit 682decc
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions prefixdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (pdb *PrefixDB) Get(key []byte) ([]byte, error) {
if len(key) == 0 {
return nil, errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

pkey := pdb.prefixed(key)
value, err := pdb.db.Get(pkey)
Expand All @@ -43,8 +43,8 @@ func (pdb *PrefixDB) Has(key []byte) (bool, error) {
if len(key) == 0 {
return false, errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

ok, err := pdb.db.Has(pdb.prefixed(key))
if err != nil {
Expand All @@ -62,8 +62,8 @@ func (pdb *PrefixDB) Set(key []byte, value []byte) error {
if value == nil {
return errValueNil
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

pkey := pdb.prefixed(key)
if err := pdb.db.Set(pkey, value); err != nil {
Expand All @@ -80,8 +80,8 @@ func (pdb *PrefixDB) SetSync(key []byte, value []byte) error {
if value == nil {
return errValueNil
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

return pdb.db.SetSync(pdb.prefixed(key), value)
}
Expand All @@ -91,8 +91,8 @@ func (pdb *PrefixDB) Delete(key []byte) error {
if len(key) == 0 {
return errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

return pdb.db.Delete(pdb.prefixed(key))
}
Expand All @@ -102,8 +102,8 @@ func (pdb *PrefixDB) DeleteSync(key []byte) error {
if len(key) == 0 {
return errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

return pdb.db.DeleteSync(pdb.prefixed(key))
}
Expand All @@ -113,8 +113,8 @@ func (pdb *PrefixDB) Iterator(start, end []byte) (Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

var pstart, pend []byte
pstart = append(cp(pdb.prefix), start...)
Expand All @@ -136,8 +136,8 @@ func (pdb *PrefixDB) ReverseIterator(start, end []byte) (Iterator, error) {
if (start != nil && len(start) == 0) || (end != nil && len(end) == 0) {
return nil, errKeyEmpty
}
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

var pstart, pend []byte
pstart = append(cp(pdb.prefix), start...)
Expand All @@ -156,8 +156,8 @@ func (pdb *PrefixDB) ReverseIterator(start, end []byte) (Iterator, error) {

// NewBatch implements DB.
func (pdb *PrefixDB) NewBatch() Batch {
pdb.mtx.Lock()
defer pdb.mtx.Unlock()
//pdb.mtx.Lock()
//defer pdb.mtx.Unlock()

return newPrefixBatch(pdb.prefix, pdb.db.NewBatch())
}
Expand Down

0 comments on commit 682decc

Please sign in to comment.