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 authored Mar 22, 2022
1 parent 8371754 commit 2b3c847
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 @@ -68,8 +68,8 @@ func (tree *MutableTree) IsEmpty() bool {

// VersionExists returns whether or not a version exists.
func (tree *MutableTree) VersionExists(version int64) bool {
tree.mtx.RLock()
defer tree.mtx.RUnlock()
tree.mtx.Lock()
defer tree.mtx.Unlock()

if tree.allRootLoaded {
return tree.versions[version]
Expand All @@ -86,8 +86,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 2b3c847

Please sign in to comment.