aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-20 23:38:46 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-20 23:38:46 -0700
commitcbfe31a9a8e94b9601e59497e4a272374bba50f3 (patch)
tree2ddd9ffb77ca00ca9c8bdf4ac1e7072e729729cf
parent3505b06023fa82322a614bb303d4aaeae08d228c (diff)
downloadseaweedfs-cbfe31a9a8e94b9601e59497e4a272374bba50f3.tar.xz
seaweedfs-cbfe31a9a8e94b9601e59497e4a272374bba50f3.zip
idx file sync before compaction
-rw-r--r--weed/storage/needle_map.go5
-rw-r--r--weed/storage/volume_vacuum.go11
2 files changed, 12 insertions, 4 deletions
diff --git a/weed/storage/needle_map.go b/weed/storage/needle_map.go
index 77d081ea7..8962e78cb 100644
--- a/weed/storage/needle_map.go
+++ b/weed/storage/needle_map.go
@@ -30,6 +30,7 @@ type NeedleMapper interface {
DeletedCount() int
MaxFileKey() NeedleId
IndexFileSize() uint64
+ Sync() error
}
type baseNeedleMapper struct {
@@ -59,3 +60,7 @@ func (nm *baseNeedleMapper) appendToIndexFile(key NeedleId, offset Offset, size
_, err := nm.indexFile.Write(bytes)
return err
}
+
+func (nm *baseNeedleMapper) Sync() error {
+ return nm.indexFile.Sync()
+}
diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go
index cec7badec..67c3957de 100644
--- a/weed/storage/volume_vacuum.go
+++ b/weed/storage/volume_vacuum.go
@@ -56,6 +56,9 @@ func (v *Volume) Compact(preallocate int64, compactionBytePerSecond int64) error
if err := v.DataBackend.Sync(); err != nil {
glog.V(0).Infof("compact fail 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)
+ }
return v.copyDataAndGenerateIndexFile(filePath+".cpd", filePath+".cpx", preallocate, compactionBytePerSecond)
}
@@ -77,7 +80,10 @@ func (v *Volume) Compact2(preallocate int64, compactionBytePerSecond int64) erro
v.lastCompactRevision = v.SuperBlock.CompactionRevision
glog.V(3).Infof("creating copies for volume %d ...", v.Id)
if err := v.DataBackend.Sync(); err != nil {
- glog.V(0).Infof("compact2 fail to sync volume %d", v.Id)
+ glog.V(0).Infof("compact2 fail to sync volume dat %d", v.Id)
+ }
+ if err := v.nm.Sync(); err != nil {
+ glog.V(0).Infof("compact2 fail to sync volume idx %d", v.Id)
}
return copyDataBasedOnIndexFile(filePath+".dat", filePath+".idx", filePath+".cpd", filePath+".cpx", v.SuperBlock, v.Version(), preallocate, compactionBytePerSecond)
}
@@ -99,9 +105,6 @@ func (v *Volume) CommitCompact() error {
glog.V(3).Infof("Got volume %d committing lock...", v.Id)
v.nm.Close()
if v.DataBackend != nil {
- if err := v.DataBackend.Sync(); err != nil {
- glog.V(0).Infof("fail to sync volume %d", v.Id)
- }
if err := v.DataBackend.Close(); err != nil {
glog.V(0).Infof("fail to close volume %d", v.Id)
}