Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

prevent segfault after mmap failure #707

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ func (db *DB) mmap(minsz int) error {

// Memory-map the data file as a byte slice.
if err := mmap(db, size); err != nil {
return err
// mmap failed; the system may have run out of space. Fallback to
// mapping the bare minimum needed for the current db size.
if err2 := mmap(db, db.datasz); err2 != nil {
panic(fmt.Sprintf("failed to revert db size after failed mmap: %v", err2))
}
return MmapError(err.Error())
}

// Save references to the meta pages.
Expand Down
7 changes: 7 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ var (
// non-bucket key on an existing bucket key.
ErrIncompatibleValue = errors.New("incompatible value")
)

// MmapError represents an error resulting from a failed mmap call. Typically,
// this error means that no further database writes will be possible. The most
// common cause is insufficient disk space.
type MmapError string

func (e MmapError) Error() string { return string(e) }