Skip to content

Commit

Permalink
whisper/mailserver : recover corrupt db files before opening (ethereu…
Browse files Browse the repository at this point in the history
…m#20891)

* whisper/mailserver : recover db file when openfile corrupted

* whisper/mailserver : fix db -> s.db

* whisper/mailserver : common/errors for dbfile
  • Loading branch information
ucwong committed Apr 8, 2020
1 parent c8e9a91 commit 6975172
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions whisper/mailserver/mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
)
Expand Down Expand Up @@ -70,6 +71,9 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
}

s.db, err = leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 32})
if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
s.db, err = leveldb.RecoverFile(path, nil)
}
if err != nil {
return fmt.Errorf("open DB file: %s", err)
}
Expand Down

0 comments on commit 6975172

Please sign in to comment.