Skip to content

Commit

Permalink
storage: fix RocksDB error and go os error discrepancy
Browse files Browse the repository at this point in the history
Because error returned from RocksDB is different from go's os error, we need to
bridge the gap by examining error message.

Release note: None
  • Loading branch information
windchan7 committed May 30, 2018
1 parent 0f9fafe commit f07c7f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/storage/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type Engine interface {
// ReadFile reads the content from the file with the given filename int this RocksDB's env.
ReadFile(filename string) ([]byte, error)
// DeleteFile deletes the file with the given filename from this RocksDB's env.
// If the file with given filename doesn't exist, return os.ErrNotExist.
DeleteFile(filename string) error
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/engine/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,7 @@ func (r *RocksDB) ReadFile(filename string) ([]byte, error) {
}

// DeleteFile deletes the file with the given filename from this RocksDB's env.
// If the file with given filename doesn't exist, return os.ErrNotExist.
func (r *RocksDB) DeleteFile(filename string) error {
if err := statusToError(C.DBEnvDeleteFile(r.rdb, goToCSlice([]byte(filename)))); err != nil {
return notFoundErrOrDefault(err)
Expand Down Expand Up @@ -2706,7 +2707,7 @@ func mvccScanDecodeKeyValue(repr []byte) (key MVCCKey, value []byte, orepr []byt
}

func notFoundErrOrDefault(err error) error {
if strings.Contains(err.Error(), "No such file or directory") {
if strings.Contains(err.Error(), "No such file or directory") || strings.Contains(err.Error(), "File not found") {
return os.ErrNotExist
}
return err
Expand Down

0 comments on commit f07c7f0

Please sign in to comment.