Skip to content

Commit

Permalink
Add mutex around Get/Set/Remove
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Feb 9, 2023
1 parent aa6aa64 commit dbe212c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (tree *MutableTree) prepareOrphansSlice() []*Node {
// to slices stored within IAVL. It returns true when an existing value was
// updated, while false means it was a new key.
func (tree *MutableTree) Set(key, value []byte) (updated bool, err error) {
if !tree.mtx.TryLock() {
panic("TONYTEST: error acquiring lock on iavl Remove")
}
defer tree.mtx.Unlock()
var orphaned []*Node
orphaned, updated, err = tree.set(key, value)
if err != nil {
Expand Down Expand Up @@ -319,6 +323,11 @@ func (tree *MutableTree) recursiveSet(node *Node, key []byte, value []byte, orph
// Remove removes a key from the working tree. The given key byte slice should not be modified
// after this call, since it may point to data stored inside IAVL.
func (tree *MutableTree) Remove(key []byte) ([]byte, bool, error) {
if !tree.mtx.TryLock() {
panic("TONYTEST: error acquiring lock on iavl Remove")
}
defer tree.mtx.Unlock()

val, orphaned, removed, err := tree.remove(key)
if err != nil {
return nil, false, err
Expand Down

0 comments on commit dbe212c

Please sign in to comment.