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

no space left on device: Service must be restarted #362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions leveldb/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package errors
import (
"errors"
"fmt"
"strings"

"github.com/syndtr/goleveldb/leveldb/storage"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -76,3 +77,15 @@ func SetFd(err error, fd storage.FileDesc) error {
}
return err
}

// IsUnrecoverableError Determine whether there is no need to restart the error that can be repaired
// for example, the disk is full. This error is a fixable error
func IsUnrecoverableError(err error) bool {
if err == nil {
return false
}
if strings.Contains(err.Error(), "no space left on device") {
return false
}
return true
}
10 changes: 5 additions & 5 deletions leveldb/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (w *Writer) writeBlock() {
// writePending finishes the current journal and writes the buffer to the
// underlying writer.
func (w *Writer) writePending() {
if w.err != nil {
if errors.IsUnrecoverableError(w.err) {
return
}
if w.pending {
Expand All @@ -422,7 +422,7 @@ func (w *Writer) writePending() {
func (w *Writer) Close() error {
w.seq++
w.writePending()
if w.err != nil {
if errors.IsUnrecoverableError(w.err) {
return w.err
}
w.err = errors.New("leveldb/journal: closed Writer")
Expand All @@ -434,7 +434,7 @@ func (w *Writer) Close() error {
func (w *Writer) Flush() error {
w.seq++
w.writePending()
if w.err != nil {
if errors.IsUnrecoverableError(w.err) {
return w.err
}
if w.f != nil {
Expand Down Expand Up @@ -467,7 +467,7 @@ func (w *Writer) Reset(writer io.Writer) (err error) {
// after the next Close, Flush or Next call, and should no longer be used.
func (w *Writer) Next() (io.Writer, error) {
w.seq++
if w.err != nil {
if errors.IsUnrecoverableError(w.err) {
return nil, w.err
}
if w.pending {
Expand Down Expand Up @@ -501,7 +501,7 @@ func (x singleWriter) Write(p []byte) (int, error) {
if w.seq != x.seq {
return 0, errors.New("leveldb/journal: stale writer")
}
if w.err != nil {
if errors.IsUnrecoverableError(w.err) {
return 0, w.err
}
n0 := len(p)
Expand Down
5 changes: 3 additions & 2 deletions leveldb/table/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/golang/snappy"

"github.com/syndtr/goleveldb/leveldb/comparer"
lerrors "github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -236,7 +237,7 @@ func (w *Writer) finishBlock() error {
//
// It is safe to modify the contents of the arguments after Append returns.
func (w *Writer) Append(key, value []byte) error {
if w.err != nil {
if lerrors.IsUnrecoverableError(w.err) {
return w.err
}
if w.nEntries > 0 && w.cmp.Compare(w.dataBlock.prevKey, key) >= 0 {
Expand Down Expand Up @@ -285,7 +286,7 @@ func (w *Writer) BytesLen() int {
// after Close, but calling BlocksLen, EntriesLen and BytesLen
// is still possible.
func (w *Writer) Close() error {
if w.err != nil {
if lerrors.IsUnrecoverableError(w.err) {
return w.err
}

Expand Down