Skip to content

Commit

Permalink
Merge pull request #76 from hkalina/jkalina/race2-fix
Browse files Browse the repository at this point in the history
Fix race on sizeEstimation in Flushable
  • Loading branch information
uprendis authored Dec 15, 2023
2 parents 1326ba9 + a3bd810 commit 2653b30
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions kvdb/flushable/flushable.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ func (w *Flushable) Drop() {

// NotFlushedPairs returns num of not flushed keys, including deleted keys.
func (w *Flushable) NotFlushedPairs() int {
w.lock.RLock()
defer w.lock.RUnlock()

return w.modified.Size()
}

// NotFlushedSizeEst returns estimation of not flushed data, including deleted keys.
func (w *Flushable) NotFlushedSizeEst() int {
w.lock.RLock()
defer w.lock.RUnlock()

return *w.sizeEstimation
}

Expand Down Expand Up @@ -228,12 +234,20 @@ func (w *Flushable) flush() error {

// Stat returns a particular internal stat of the database.
func (w *Flushable) Stat(property string) (string, error) {
return w.underlying.Stat(property)
w.lock.RLock()
underlying := w.underlying
w.lock.RUnlock()

return underlying.Stat(property)
}

// Compact flattens the underlying data store for the given key range.
func (w *Flushable) Compact(start []byte, limit []byte) error {
return w.underlying.Compact(start, limit)
w.lock.RLock()
underlying := w.underlying
w.lock.RUnlock()

return underlying.Compact(start, limit)
}

/*
Expand Down

0 comments on commit 2653b30

Please sign in to comment.