Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race on sizeEstimation in Flushable #76

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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