aboutsummaryrefslogtreecommitdiff
path: root/go/storage/volume.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-06-19 18:10:38 -0700
committerChris Lu <chris.lu@gmail.com>2013-06-19 18:10:38 -0700
commit50269b74ce615ab02f6bf64a2bc0fc9e71122267 (patch)
tree887f63247a589cb027e65331b9243edcad61f479 /go/storage/volume.go
parent715d327df0ad64a70837711c664e1ef024e0bcc5 (diff)
downloadseaweedfs-50269b74ce615ab02f6bf64a2bc0fc9e71122267.tar.xz
seaweedfs-50269b74ce615ab02f6bf64a2bc0fc9e71122267.zip
add dataCenter option when assign file keys
add dataCenter option when starting volume servers some work related to freeze a volume. Not tested yet.
Diffstat (limited to 'go/storage/volume.go')
-rw-r--r--go/storage/volume.go52
1 files changed, 48 insertions, 4 deletions
diff --git a/go/storage/volume.go b/go/storage/volume.go
index 98f712433..4e6db3634 100644
--- a/go/storage/volume.go
+++ b/go/storage/volume.go
@@ -70,10 +70,29 @@ func (v *Volume) load(alsoLoadIndex bool) error {
e = v.maybeWriteSuperBlock()
}
if e == nil && alsoLoadIndex {
- indexFile, ie := os.OpenFile(fileName+".idx", os.O_RDWR|os.O_CREATE, 0644)
- if ie != nil {
- return fmt.Errorf("cannot create Volume Data %s.dat: %s", fileName, e)
- }
+ var indexFile *os.File
+ if v.readOnly {
+ if indexFile, e = os.Open(fileName + ".idx"); e != nil && !os.IsNotExist(e) {
+ return fmt.Errorf("cannot open index file %s.idx: %s", fileName, e)
+ }
+ if indexFile != nil {
+ log.Printf("converting %s.idx to %s.cdb", fileName, fileName)
+ if e = ConvertIndexToCdb(fileName+".cdb", indexFile); e != nil {
+ log.Printf("error converting %s.idx to %s.cdb: %s", fileName, fileName)
+ } else {
+ indexFile.Close()
+ os.Remove(indexFile.Name())
+ indexFile = nil
+ }
+ }
+ v.nm, e = OpenCdbMap(fileName + ".cdb")
+ return e
+ } else {
+ 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)
+ }
+ }
v.nm, e = LoadNeedleMap(indexFile)
}
return e
@@ -224,6 +243,31 @@ func (v *Volume) commitCompact() error {
}
return nil
}
+func (v *Volume) freeze() error {
+ if v.readOnly {
+ return nil
+ }
+ nm, ok := v.nm.(*NeedleMap)
+ if !ok {
+ return nil
+ }
+ v.accessLock.Lock()
+ defer v.accessLock.Unlock()
+ bn, _ := nakeFilename(v.dataFile.Name())
+ cdbFn := bn + ".cdb"
+ log.Printf("converting %s to %s", nm.indexFile.Name(), cdbFn)
+ err := DumpNeedleMapToCdb(cdbFn, nm)
+ if err != nil {
+ return err
+ }
+ if v.nm, err = OpenCdbMap(cdbFn); err != nil {
+ return err
+ }
+ nm.indexFile.Close()
+ os.Remove(nm.indexFile.Name())
+ v.readOnly = true
+ return nil
+}
func ScanVolumeFile(dirname string, id VolumeId,
visitSuperBlock func(SuperBlock) error,