Skip to content

Commit

Permalink
sstable: use fixed error in Close
Browse files Browse the repository at this point in the history
Previously sstable.Reader.Close() would initialize a new error each time it was called.

In workloads that open and close many readers, this could actually have non-trivial
expense.

Instead, this change adds a pre-initialized error value and just assigns it in Close().
  • Loading branch information
dt committed Dec 21, 2020
1 parent 745f6c8 commit 6f499ee
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sstable/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

var errCorruptIndexEntry = base.CorruptionErrorf("pebble/table: corrupt index entry")
var errReaderClosed = errors.New("pebble/table: reader is closed")

const (
// Constants for dynamic readahead of data blocks. Note that the size values
Expand Down Expand Up @@ -1654,7 +1655,7 @@ func (r *Reader) Close() error {
}
}
// Make any future calls to Get, NewIter or Close return an error.
r.err = errors.New("pebble/table: reader is closed")
r.err = errReaderClosed
return nil
}

Expand Down

0 comments on commit 6f499ee

Please sign in to comment.