Skip to content

Commit

Permalink
fix data race related to VersionExists (#36)
Browse files Browse the repository at this point in the history
* fix data race related to VersionExists

* use regular lock instead of RW in mutable_tree.go
  • Loading branch information
p0mvn committed Mar 28, 2022
1 parent b4f8932 commit 71e959a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type MutableTree struct {
unsavedFastNodeRemovals map[string]interface{} // FastNodes that have not yet been removed from disk
ndb *nodeDB

mtx sync.RWMutex // versions Read/write lock.
mtx sync.Mutex
}

// NewMutableTree returns a new tree with the specified cache size and datastore.
Expand Down Expand Up @@ -88,8 +88,8 @@ func (tree *MutableTree) VersionExists(version int64) bool {

// AvailableVersions returns all available versions in ascending order
func (tree *MutableTree) AvailableVersions() []int {
tree.mtx.RLock()
defer tree.mtx.RUnlock()
tree.mtx.Lock()
defer tree.mtx.Unlock()

res := make([]int, 0, len(tree.versions))
for i, v := range tree.versions {
Expand Down

0 comments on commit 71e959a

Please sign in to comment.