mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-20 00:27:57 +08:00
volume: fail fast if idx files are missing
fix https://github.com/chrislusf/seaweedfs/issues/1796
This commit is contained in:
@@ -2,6 +2,7 @@ package storage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -148,3 +149,18 @@ func verifyDeletedNeedleIntegrity(datFile backend.BackendStorageFile, v needle.V
|
|||||||
}
|
}
|
||||||
return n.AppendAtNs, err
|
return n.AppendAtNs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Volume) checkIdxFile() error {
|
||||||
|
datFileSize, _, err := v.DataBackend.GetStat()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get stat %s: %v", v.FileName(".dat"), err)
|
||||||
|
}
|
||||||
|
if datFileSize <= super_block.SuperBlockSize {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
indexFileName := v.FileName(".idx")
|
||||||
|
if util.FileExists(indexFileName) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("idx file %s does not exists", indexFileName)
|
||||||
|
}
|
||||||
|
@@ -96,6 +96,10 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind
|
|||||||
v.dirIdx = v.dir
|
v.dirIdx = v.dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check volume idx files
|
||||||
|
if err := v.checkIdxFile(); err != nil {
|
||||||
|
glog.Fatalf("check volume idx file %s: %v", v.FileName(".idx"), err)
|
||||||
|
}
|
||||||
var indexFile *os.File
|
var indexFile *os.File
|
||||||
if v.noWriteOrDelete {
|
if v.noWriteOrDelete {
|
||||||
glog.V(0).Infoln("open to read file", v.FileName(".idx"))
|
glog.V(0).Infoln("open to read file", v.FileName(".idx"))
|
||||||
|
Reference in New Issue
Block a user