diff options
| author | chrislu <chris.lu@gmail.com> | 2022-10-13 23:10:49 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-10-13 23:10:49 -0700 |
| commit | e05637c42cbb7519aa97c3b46a0305872fa6d11a (patch) | |
| tree | e2ade7d0cac8c386c84f1c8ec41375bd905ee429 /weed/storage | |
| parent | dcd0743a35912dfa559ae912e5208f15dd186386 (diff) | |
| parent | a5b867af69ff7be5e0f0944b2ee4275524d542e9 (diff) | |
| download | seaweedfs-e05637c42cbb7519aa97c3b46a0305872fa6d11a.tar.xz seaweedfs-e05637c42cbb7519aa97c3b46a0305872fa6d11a.zip | |
Merge branch 'master' of https://github.com/seaweedfs/seaweedfs
Diffstat (limited to 'weed/storage')
| -rw-r--r-- | weed/storage/backend/disk_file.go | 3 | ||||
| -rw-r--r-- | weed/storage/disk_location.go | 2 | ||||
| -rw-r--r-- | weed/storage/erasure_coding/ec_volume.go | 1 | ||||
| -rw-r--r-- | weed/storage/needle_map/memdb.go | 5 | ||||
| -rw-r--r-- | weed/storage/volume.go | 18 | ||||
| -rw-r--r-- | weed/storage/volume_vacuum.go | 25 |
6 files changed, 25 insertions, 29 deletions
diff --git a/weed/storage/backend/disk_file.go b/weed/storage/backend/disk_file.go index 7a3a40977..18dde8dca 100644 --- a/weed/storage/backend/disk_file.go +++ b/weed/storage/backend/disk_file.go @@ -69,6 +69,9 @@ func (df *DiskFile) Truncate(off int64) error { } func (df *DiskFile) Close() error { + if err := df.Sync(); err != nil { + return err + } return df.File.Close() } diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 6f938da8f..b3be04703 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -364,7 +364,7 @@ func (l *DiskLocation) VolumesLen() int { func (l *DiskLocation) SetStopping() { l.volumesLock.Lock() for _, v := range l.volumes { - v.SetStopping() + v.SyncToDisk() } l.volumesLock.Unlock() diff --git a/weed/storage/erasure_coding/ec_volume.go b/weed/storage/erasure_coding/ec_volume.go index aa1e15722..ddee742a8 100644 --- a/weed/storage/erasure_coding/ec_volume.go +++ b/weed/storage/erasure_coding/ec_volume.go @@ -125,6 +125,7 @@ func (ev *EcVolume) Close() { ev.ecjFileAccessLock.Unlock() } if ev.ecxFile != nil { + _ = ev.ecxFile.Sync() _ = ev.ecxFile.Close() ev.ecxFile = nil } diff --git a/weed/storage/needle_map/memdb.go b/weed/storage/needle_map/memdb.go index 7fb98dcea..463245cd1 100644 --- a/weed/storage/needle_map/memdb.go +++ b/weed/storage/needle_map/memdb.go @@ -86,7 +86,10 @@ func (cm *MemDb) SaveToIdx(idxName string) (ret error) { if err != nil { return } - defer idxFile.Close() + defer func() { + idxFile.Sync() + idxFile.Close() + }() return cm.AscendingVisit(func(value NeedleValue) error { if value.Offset.IsZero() || value.Size.IsDeleted() { diff --git a/weed/storage/volume.go b/weed/storage/volume.go index 1a9c8bd24..ab8af91e2 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -180,21 +180,6 @@ func (v *Volume) DiskType() types.DiskType { return v.location.DiskType } -func (v *Volume) SetStopping() { - v.dataFileAccessLock.Lock() - defer v.dataFileAccessLock.Unlock() - if v.nm != nil { - if err := v.nm.Sync(); err != nil { - glog.Warningf("Volume SetStopping fail to sync volume idx %d", v.Id) - } - } - if v.DataBackend != nil { - if err := v.DataBackend.Sync(); err != nil { - glog.Warningf("Volume SetStopping fail to sync volume %d", v.Id) - } - } -} - func (v *Volume) SyncToDisk() { v.dataFileAccessLock.Lock() defer v.dataFileAccessLock.Unlock() @@ -228,10 +213,9 @@ func (v *Volume) Close() { v.nm = nil } if v.DataBackend != nil { - if err := v.DataBackend.Sync(); err != nil { + if err := v.DataBackend.Close(); err != nil { glog.Warningf("Volume Close fail to sync volume %d", v.Id) } - _ = v.DataBackend.Close() v.DataBackend = nil stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Dec() } diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index 47b0800eb..0eaca5ff4 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -55,10 +55,10 @@ func (v *Volume) Compact(preallocate int64, compactionBytePerSecond int64) error v.lastCompactRevision = v.SuperBlock.CompactionRevision glog.V(3).Infof("creating copies for volume %d ,last offset %d...", v.Id, v.lastCompactIndexOffset) if err := v.DataBackend.Sync(); err != nil { - glog.V(0).Infof("compact fail to sync volume %d", v.Id) + glog.V(0).Infof("compact failed to sync volume %d", v.Id) } if err := v.nm.Sync(); err != nil { - glog.V(0).Infof("compact fail to sync volume idx %d", v.Id) + glog.V(0).Infof("compact failed to sync volume idx %d", v.Id) } return v.copyDataAndGenerateIndexFile(v.FileName(".cpd"), v.FileName(".cpx"), preallocate, compactionBytePerSecond) } @@ -83,10 +83,10 @@ func (v *Volume) Compact2(preallocate int64, compactionBytePerSecond int64, prog return fmt.Errorf("volume %d backend is empty remote:%v", v.Id, v.HasRemoteFile()) } if err := v.DataBackend.Sync(); err != nil { - glog.V(0).Infof("compact2 fail to sync volume dat %d: %v", v.Id, err) + glog.V(0).Infof("compact2 failed to sync volume dat %d: %v", v.Id, err) } if err := v.nm.Sync(); err != nil { - glog.V(0).Infof("compact2 fail to sync volume idx %d: %v", v.Id, err) + glog.V(0).Infof("compact2 failed to sync volume idx %d: %v", v.Id, err) } return v.copyDataBasedOnIndexFile( v.FileName(".dat"), v.FileName(".idx"), @@ -120,7 +120,7 @@ func (v *Volume) CommitCompact() error { } if v.DataBackend != nil { if err := v.DataBackend.Close(); err != nil { - glog.V(0).Infof("fail to close volume %d", v.Id) + glog.V(0).Infof("failed to close volume %d", v.Id) } } v.DataBackend = nil @@ -270,7 +270,11 @@ func (v *Volume) makeupDiff(newDatFileName, newIdxFileName, oldDatFileName, oldI return fmt.Errorf("open idx file %s failed: %v", newIdxFileName, err) } - defer idx.Close() + defer func() { + idx.Sync() + idx.Close() + }() + stat, err := idx.Stat() if err != nil { return fmt.Errorf("stat file %s: %v", idx.Name(), err) @@ -387,9 +391,7 @@ func (scanner *VolumeFileScanner4Vacuum) VisitNeedle(n *needle.Needle, offset in } func (v *Volume) copyDataAndGenerateIndexFile(dstName, idxName string, preallocate int64, compactionBytePerSecond int64) (err error) { - var ( - dst backend.BackendStorageFile - ) + var dst backend.BackendStorageFile if dst, err = backend.CreateVolumeFile(dstName, preallocate, 0); err != nil { return err } @@ -493,7 +495,10 @@ func (v *Volume) copyDataBasedOnIndexFile(srcDatName, srcIdxName, dstDatName, da glog.Errorf("cannot open Volume Index %s: %v", datIdxName, err) return err } - defer indexFile.Close() + defer func() { + indexFile.Sync() + indexFile.Close() + }() if v.tmpNm != nil { v.tmpNm.Close() v.tmpNm = nil |
