Skip to content

Commit

Permalink
sstable: use package-level error in place of runtime allocation
Browse files Browse the repository at this point in the history
Currently, `sstable.(*Writer).Close`, calls `errors.New` on the happy
path when finalizing an sstable. While this call is relatively
inexpensive and infrequent, it is unnecessary.

Extract out error definition into a package-level variable that can be
referenced throughout the course of the program's runtime.
  • Loading branch information
nicktrav committed Nov 23, 2021
1 parent 50e31f6 commit 3036ce0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sstable/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/cockroachdb/pebble/internal/private"
)

var errWriterClosed = errors.New("pebble: writer is closed")

// WriterMetadata holds info about a finished sstable.
type WriterMetadata struct {
Size uint64
Expand Down Expand Up @@ -806,7 +808,7 @@ func (w *Writer) Close() (err error) {
}

// Make any future calls to Set or Close return an error.
w.err = errors.New("pebble: writer is closed")
w.err = errWriterClosed
return nil
}

Expand Down

0 comments on commit 3036ce0

Please sign in to comment.