aboutsummaryrefslogtreecommitdiff
path: root/go/storage/volume.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-08-11 11:38:55 -0700
committerChris Lu <chris.lu@gmail.com>2013-08-11 11:38:55 -0700
commit7cef280bdc77099e0048692893f440038c8cc0cb (patch)
tree3ca2932cd752172e8959b212c3713810aa7e90f2 /go/storage/volume.go
parent27f04a382ad3790ab97106f3a86d19b47f79fb85 (diff)
downloadseaweedfs-7cef280bdc77099e0048692893f440038c8cc0cb.tar.xz
seaweedfs-7cef280bdc77099e0048692893f440038c8cc0cb.zip
handle cases when .idx files are also readonly
adjusting log level
Diffstat (limited to 'go/storage/volume.go')
-rw-r--r--go/storage/volume.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/go/storage/volume.go b/go/storage/volume.go
index c212e9b37..ef720ff75 100644
--- a/go/storage/volume.go
+++ b/go/storage/volume.go
@@ -73,12 +73,12 @@ func (v *Volume) load(alsoLoadIndex bool) error {
if e == nil && alsoLoadIndex {
var indexFile *os.File
if v.readOnly {
- glog.V(4).Infoln("opening file", fileName+".idx")
+ glog.V(2).Infoln("opening file", fileName+".idx")
if indexFile, e = os.Open(fileName + ".idx"); e != nil && !os.IsNotExist(e) {
return fmt.Errorf("cannot open index file %s.idx: %s", fileName, e.Error())
}
if indexFile != nil {
- glog.V(4).Infoln("check file", fileName+".cdb")
+ glog.V(2).Infoln("check file", fileName+".cdb")
if _, err := os.Stat(fileName + ".cdb"); os.IsNotExist(err) {
glog.V(0).Infof("converting %s.idx to %s.cdb", fileName, fileName)
if e = ConvertIndexToCdb(fileName+".cdb", indexFile); e != nil {
@@ -89,7 +89,7 @@ func (v *Volume) load(alsoLoadIndex bool) error {
}
}
}
- glog.V(4).Infoln("open file", fileName+".cdb")
+ glog.V(2).Infoln("open file", fileName+".cdb")
if v.nm, e = OpenCdbMap(fileName + ".cdb"); e != nil {
if os.IsNotExist(e) {
glog.V(0).Infof("Failed to read cdb file :%s, fall back to normal readonly mode.", fileName)
@@ -99,14 +99,23 @@ func (v *Volume) load(alsoLoadIndex bool) error {
}
}
}
- glog.V(4).Infoln("open to write file", fileName+".idx")
- indexFile, e = os.OpenFile(fileName+".idx", os.O_RDWR|os.O_CREATE, 0644)
- if e != nil {
- return fmt.Errorf("cannot create Volume Data %s.dat: %s", fileName, e.Error())
+ if v.readOnly {
+ glog.V(1).Infoln("open to read file", fileName+".idx")
+ indexFile, e = os.OpenFile(fileName+".idx", os.O_RDONLY, 0644)
+ if e != nil {
+ return fmt.Errorf("cannot read Volume Data %s.dat: %s", fileName, e.Error())
+ }
+ } else {
+ glog.V(1).Infoln("open to write file", fileName+".idx")
+ indexFile, e = os.OpenFile(fileName+".idx", os.O_RDWR|os.O_CREATE, 0644)
+ if e != nil {
+ return fmt.Errorf("cannot create Volume Data %s.dat: %s", fileName, e.Error())
+ }
+ }
+ glog.V(0).Infoln("loading file", fileName+".idx", "readonly", v.readOnly)
+ if v.nm, e = LoadNeedleMap(indexFile); e != nil {
+ glog.V(0).Infoln("loading error:", e)
}
- glog.V(4).Infoln("loading file", fileName+".idx")
- v.nm, e = LoadNeedleMap(indexFile)
- glog.V(4).Infoln("loading error:", e)
}
return e
}