From f07c7f0b1f76f832dfe0c3239a595fa58d129a9c Mon Sep 17 00:00:00 2001 From: Victor Chen Date: Wed, 30 May 2018 14:56:49 -0400 Subject: [PATCH] storage: fix RocksDB error and go os error discrepancy 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 --- pkg/storage/engine/engine.go | 1 + pkg/storage/engine/rocksdb.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/storage/engine/engine.go b/pkg/storage/engine/engine.go index bbe2906b563a..ff707064c850 100644 --- a/pkg/storage/engine/engine.go +++ b/pkg/storage/engine/engine.go @@ -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 } diff --git a/pkg/storage/engine/rocksdb.go b/pkg/storage/engine/rocksdb.go index 11cea040438e..a0aa81732007 100644 --- a/pkg/storage/engine/rocksdb.go +++ b/pkg/storage/engine/rocksdb.go @@ -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) @@ -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