Skip to content

Commit

Permalink
Fix snapshot race (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar authored Jun 12, 2022
1 parent 7ce54ab commit ff08c96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
12 changes: 12 additions & 0 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,15 @@ func (c *Collection) chunks() int {
max, _ := c.fill.Max()
return int(commit.ChunkAt(max) + 1)
}

// readChunk acquires appropriate locks for a chunk and executes a read callback.
// This is used for snapshotting purposes only.
func (c *Collection) readChunk(chunk commit.Chunk, fn func(uint64, commit.Chunk, bitmap.Bitmap) error) error {

// Lock both the chunk and the fill list
c.slock.RLock(uint(chunk))
c.lock.RLock()
defer c.slock.RUnlock(uint(chunk))
defer c.lock.RUnlock()
return fn(c.commits[chunk], chunk, chunk.OfBitmap(c.fill))
}
17 changes: 0 additions & 17 deletions txn_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,3 @@ func (txn *Txn) rangeWrite(fn func(commitID uint64, chunk commit.Chunk, fill bit
lock.Unlock(uint(chunk))
})
}

// readChunk acquires appropriate locks for a chunk and executes a read callback
func (c *Collection) readChunk(chunk commit.Chunk, fn func(uint64, commit.Chunk, bitmap.Bitmap) error) (err error) {
lock := c.slock
lock.RLock(uint(chunk))

// Compute the fill
c.lock.RLock()
fill := chunk.OfBitmap(c.fill)
commitID := c.commits[chunk]
c.lock.RUnlock()

// Call the delegate
err = fn(commitID, chunk, fill)
lock.RUnlock(uint(chunk))
return
}

0 comments on commit ff08c96

Please sign in to comment.