aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-02-24 18:27:35 +0500
committerGitHub <noreply@github.com>2024-02-24 05:27:35 -0800
commit7187346cc1630f92c0aa4679965e4bdc0149a6d7 (patch)
tree1acec7a106bab7db1a934911bbfaf53a429cfa77
parent7c45992c7960cb213bdc6cfe7bc70c6c86d509e0 (diff)
downloadseaweedfs-7187346cc1630f92c0aa4679965e4bdc0149a6d7.tar.xz
seaweedfs-7187346cc1630f92c0aa4679965e4bdc0149a6d7.zip
avoid unexpected compact size (#5272)
https://github.com/seaweedfs/seaweedfs/issues/5215
-rw-r--r--weed/storage/volume_vacuum.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go
index 0eaca5ff4..b070fa901 100644
--- a/weed/storage/volume_vacuum.go
+++ b/weed/storage/volume_vacuum.go
@@ -423,7 +423,10 @@ func (v *Volume) copyDataBasedOnIndexFile(srcDatName, srcIdxName, dstDatName, da
if dstDatBackend, err = backend.CreateVolumeFile(dstDatName, preallocate, 0); err != nil {
return err
}
- defer dstDatBackend.Close()
+ defer func() {
+ dstDatBackend.Sync()
+ dstDatBackend.Close()
+ }()
oldNm := needle_map.NewMemDb()
defer oldNm.Close()
@@ -484,7 +487,20 @@ func (v *Volume) copyDataBasedOnIndexFile(srcDatName, srcIdxName, dstDatName, da
if err != nil {
return err
}
-
+ dstDatSize, _, err := dstDatBackend.GetStat()
+ if err != nil {
+ return err
+ }
+ if v.nm.ContentSize() > v.nm.DeletedSize() {
+ expectedContentSize := v.nm.ContentSize() - v.nm.DeletedSize()
+ if expectedContentSize > uint64(dstDatSize) {
+ return fmt.Errorf("volume %s unexpected new data size: %d does not match size of content minus deleted: %d",
+ v.Id.String(), dstDatSize, expectedContentSize)
+ }
+ } else {
+ glog.Warningf("volume %s content size: %d less deleted size: %d, new size: %d",
+ v.Id.String(), v.nm.ContentSize(), v.nm.DeletedSize(), dstDatSize)
+ }
err = newNm.SaveToIdx(datIdxName)
if err != nil {
return err