mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
close file in ScanVolumeFile()
fix https://github.com/chrislusf/seaweedfs/issues/761
This commit is contained in:
parent
1fcbed4e90
commit
f050b22d6c
|
@ -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()
|
||||
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 {
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue