diff --git a/weed/storage/needle_map/memdb.go b/weed/storage/needle_map/memdb.go index a80a7870c..b25b5e89a 100644 --- a/weed/storage/needle_map/memdb.go +++ b/weed/storage/needle_map/memdb.go @@ -88,7 +88,7 @@ func (cm *MemDb) SaveToIdx(idxName string) (ret error) { defer idxFile.Close() return cm.AscendingVisit(func(value NeedleValue) error { - if value.Offset.IsZero() || value.Size == TombstoneFileSize { + if value.Offset.IsZero() || value.Size.IsDeleted() { return nil } _, err := idxFile.Write(value.ToBytes()) @@ -105,7 +105,7 @@ func (cm *MemDb) LoadFromIdx(idxName string) (ret error) { defer idxFile.Close() return idx.WalkIndexFile(idxFile, func(key NeedleId, offset Offset, size Size) error { - if offset.IsZero() || size == TombstoneFileSize { + if offset.IsZero() || size.IsDeleted() { return cm.Delete(key) } return cm.Set(key, offset, size) diff --git a/weed/storage/needle_map_sorted_file.go b/weed/storage/needle_map_sorted_file.go index c89916f67..1ca113ca9 100644 --- a/weed/storage/needle_map_sorted_file.go +++ b/weed/storage/needle_map_sorted_file.go @@ -80,7 +80,7 @@ func (m *SortedFileNeedleMap) Delete(key NeedleId, offset Offset) error { return err } - if size == TombstoneFileSize { + if size.IsDeleted() { return nil } diff --git a/weed/storage/types/needle_types.go b/weed/storage/types/needle_types.go index c8234aa49..138643f7f 100644 --- a/weed/storage/types/needle_types.go +++ b/weed/storage/types/needle_types.go @@ -15,6 +15,10 @@ type Offset struct { type Size uint32 +func (s Size) IsDeleted() bool { + return s == TombstoneFileSize +} + type OffsetLower struct { b3 byte b2 byte diff --git a/weed/storage/volume_checking.go b/weed/storage/volume_checking.go index 36c6628aa..7a5a423b4 100644 --- a/weed/storage/volume_checking.go +++ b/weed/storage/volume_checking.go @@ -27,7 +27,7 @@ func CheckVolumeDataIntegrity(v *Volume, indexFile *os.File) (lastAppendAtNs uin if offset.IsZero() { return 0, nil } - if size == TombstoneFileSize { + if size.IsDeleted() { size = 0 } if lastAppendAtNs, e = verifyNeedleIntegrity(v.DataBackend, v.Version(), offset.ToAcutalOffset(), key, size); e != nil { diff --git a/weed/storage/volume_read_write.go b/weed/storage/volume_read_write.go index fa1a80cbd..d7b477a2d 100644 --- a/weed/storage/volume_read_write.go +++ b/weed/storage/volume_read_write.go @@ -260,7 +260,7 @@ func (v *Volume) readNeedle(n *needle.Needle) (int, error) { if !ok || nv.Offset.IsZero() { return -1, ErrorNotFound } - if nv.Size == TombstoneFileSize { + if nv.Size.IsDeleted() { return -1, errors.New("already deleted") } if nv.Size == 0 { diff --git a/weed/storage/volume_vacuum.go b/weed/storage/volume_vacuum.go index 505af50bb..9d366a27d 100644 --- a/weed/storage/volume_vacuum.go +++ b/weed/storage/volume_vacuum.go @@ -413,7 +413,7 @@ func copyDataBasedOnIndexFile(srcDatName, srcIdxName, dstDatName, datIdxName str offset, size := value.Offset, value.Size - if offset.IsZero() || size == TombstoneFileSize { + if offset.IsZero() || size.IsDeleted() { return nil }