Browse Source

filer: leveldb store add auto recovery, report correct error

fix https://github.com/chrislusf/seaweedfs/issues/1326
pull/1329/head
Chris Lu 5 years ago
parent
commit
e5a0787653
  1. 4
      unmaintained/compact_leveldb/compact_leveldb.go
  2. 4
      weed/filer2/leveldb/leveldb_store.go
  3. 6
      weed/filer2/leveldb2/leveldb2_store.go
  4. 10
      weed/storage/needle_map_leveldb.go

4
unmaintained/compact_leveldb/compact_leveldb.go

@ -5,6 +5,7 @@ import (
"log" "log"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
) )
@ -25,6 +26,9 @@ func main() {
} }
db, err := leveldb.OpenFile(*dir, opts) db, err := leveldb.OpenFile(*dir, opts)
if errors.IsCorrupted(err) {
db, err = leveldb.RecoverFile(*dir, opts)
}
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

4
weed/filer2/leveldb/leveldb_store.go

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
leveldb_util "github.com/syndtr/goleveldb/leveldb/util" leveldb_util "github.com/syndtr/goleveldb/leveldb/util"
@ -49,6 +50,9 @@ func (store *LevelDBStore) initialize(dir string) (err error) {
} }
if store.db, err = leveldb.OpenFile(dir, opts); err != nil { if store.db, err = leveldb.OpenFile(dir, opts); err != nil {
if errors.IsCorrupted(err) {
store.db, err = leveldb.RecoverFile(dir, opts)
}
glog.Infof("filer store open dir %s: %v", dir, err) glog.Infof("filer store open dir %s: %v", dir, err)
return return
} }

6
weed/filer2/leveldb2/leveldb2_store.go

@ -9,6 +9,7 @@ import (
"os" "os"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
leveldb_util "github.com/syndtr/goleveldb/leveldb/util" leveldb_util "github.com/syndtr/goleveldb/leveldb/util"
@ -52,9 +53,12 @@ func (store *LevelDB2Store) initialize(dir string, dbCount int) (err error) {
dbFolder := fmt.Sprintf("%s/%02d", dir, d) dbFolder := fmt.Sprintf("%s/%02d", dir, d)
os.MkdirAll(dbFolder, 0755) os.MkdirAll(dbFolder, 0755)
db, dbErr := leveldb.OpenFile(dbFolder, opts) db, dbErr := leveldb.OpenFile(dbFolder, opts)
if errors.IsCorrupted(dbErr) {
db, dbErr = leveldb.RecoverFile(dbFolder, opts)
}
if dbErr != nil { if dbErr != nil {
glog.Errorf("filer store open dir %s: %v", dbFolder, dbErr) glog.Errorf("filer store open dir %s: %v", dbFolder, dbErr)
return
return dbErr
} }
store.dbs = append(store.dbs, db) store.dbs = append(store.dbs, db)
} }

10
weed/storage/needle_map_leveldb.go

@ -5,14 +5,17 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/chrislusf/seaweedfs/weed/storage/idx"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
"github.com/chrislusf/seaweedfs/weed/storage/idx"
"github.com/syndtr/goleveldb/leveldb"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/storage/needle_map" "github.com/chrislusf/seaweedfs/weed/storage/needle_map"
. "github.com/chrislusf/seaweedfs/weed/storage/types" . "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/syndtr/goleveldb/leveldb"
) )
type LevelDbNeedleMap struct { type LevelDbNeedleMap struct {
@ -32,6 +35,9 @@ func NewLevelDbNeedleMap(dbFileName string, indexFile *os.File, opts *opt.Option
glog.V(1).Infof("Opening %s...", dbFileName) glog.V(1).Infof("Opening %s...", dbFileName)
if m.db, err = leveldb.OpenFile(dbFileName, opts); err != nil { if m.db, err = leveldb.OpenFile(dbFileName, opts); err != nil {
if errors.IsCorrupted(err) {
m.db, err = leveldb.RecoverFile(dbFileName, opts)
}
return return
} }
glog.V(1).Infof("Loading %s...", indexFile.Name()) glog.V(1).Infof("Loading %s...", indexFile.Name())

Loading…
Cancel
Save