diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-12-04 21:50:26 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-12-04 21:50:26 -0800 |
| commit | d171d9f988130eb1517e6d7609dbedbae1fa58bc (patch) | |
| tree | 52bb2171e0bf15c6cbd9ff6f4fe7deef82001d07 | |
| parent | cc839f935dec652e682e1289580e996d99feeedb (diff) | |
| download | seaweedfs-d171d9f988130eb1517e6d7609dbedbae1fa58bc.tar.xz seaweedfs-d171d9f988130eb1517e6d7609dbedbae1fa58bc.zip | |
volume: ensure the volume dat and idx files are always closed
fix https://github.com/chrislusf/seaweedfs/issues/1646
| -rw-r--r-- | weed/storage/volume_loading.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index fe4980e31..34eee876d 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -25,6 +25,20 @@ func loadVolumeWithoutIndex(dirname string, collection string, id needle.VolumeI func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind NeedleMapType, preallocate int64) (err error) { alreadyHasSuperBlock := false + hasLoadedVolume := false + defer func() { + if !hasLoadedVolume { + if v.nm != nil { + v.nm.Close() + v.nm = nil + } + if v.DataBackend != nil { + v.DataBackend.Close() + v.DataBackend = nil + } + } + }() + hasVolumeInfoFile := v.maybeLoadVolumeInfo() && v.volumeInfo.Version != 0 if v.HasRemoteFile() { @@ -151,5 +165,9 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Inc() + if err == nil { + hasLoadedVolume = true + } + return err } |
