Browse Source

close file in ScanVolumeFile()

fix https://github.com/chrislusf/seaweedfs/issues/761
pull/763/head
Chris Lu 6 years ago
parent
commit
f050b22d6c
  1. 17
      weed/storage/volume.go
  2. 1
      weed/storage/volume_read_write.go
  3. 9
      weed/storage/volume_vacuum.go

17
weed/storage/volume.go

@ -57,6 +57,13 @@ func (v *Volume) Version() Version {
}
func (v *Volume) Size() int64 {
v.dataFileAccessLock.Lock()
defer v.dataFileAccessLock.Unlock()
if v.dataFile == nil {
return 0
}
stat, e := v.dataFile.Stat()
if e == nil {
return stat.Size()
@ -69,8 +76,14 @@ func (v *Volume) Size() int64 {
func (v *Volume) Close() {
v.dataFileAccessLock.Lock()
defer v.dataFileAccessLock.Unlock()
v.nm.Close()
_ = v.dataFile.Close()
if v.nm != nil {
v.nm.Close()
v.nm = nil
}
if v.dataFile != nil {
_ = v.dataFile.Close()
v.dataFile = nil
}
}
func (v *Volume) NeedToReplicate() bool {

1
weed/storage/volume_read_write.go

@ -193,6 +193,7 @@ func ScanVolumeFile(dirname string, collection string, id VolumeId,
if err = visitSuperBlock(v.SuperBlock); err != nil {
return fmt.Errorf("Failed to process volume %d super block: %v", id, err)
}
defer v.Close()
version := v.Version()

9
weed/storage/volume_vacuum.go

@ -44,7 +44,10 @@ func (v *Volume) commitCompact() error {
defer v.dataFileAccessLock.Unlock()
glog.V(3).Infof("Got volume %d committing lock...", v.Id)
v.nm.Close()
_ = v.dataFile.Close()
if err := v.dataFile.Close(); err != nil {
glog.V(0).Infof("fail to close volume %d", v.Id)
}
v.dataFile = nil
var e error
if e = v.makeupDiff(v.FileName()+".cpd", v.FileName()+".cpx", v.FileName()+".dat", v.FileName()+".idx"); e != nil {
@ -60,10 +63,10 @@ func (v *Volume) commitCompact() error {
} else {
var e error
if e = os.Rename(v.FileName()+".cpd", v.FileName()+".dat"); e != nil {
return e
return fmt.Errorf("rename %s: %v", v.FileName()+".cpd", e)
}
if e = os.Rename(v.FileName()+".cpx", v.FileName()+".idx"); e != nil {
return e
return fmt.Errorf("rename %s: %v", v.FileName()+".cpx", e)
}
}

Loading…
Cancel
Save