Browse Source

refactoring

pull/1427/head
Chris Lu 4 years ago
parent
commit
ee11d98650
  1. 4
      weed/storage/needle_map/memdb.go
  2. 2
      weed/storage/needle_map_sorted_file.go
  3. 4
      weed/storage/types/needle_types.go
  4. 2
      weed/storage/volume_checking.go
  5. 2
      weed/storage/volume_read_write.go
  6. 2
      weed/storage/volume_vacuum.go

4
weed/storage/needle_map/memdb.go

@ -88,7 +88,7 @@ func (cm *MemDb) SaveToIdx(idxName string) (ret error) {
defer idxFile.Close() defer idxFile.Close()
return cm.AscendingVisit(func(value NeedleValue) error { return cm.AscendingVisit(func(value NeedleValue) error {
if value.Offset.IsZero() || value.Size == TombstoneFileSize {
if value.Offset.IsZero() || value.Size.IsDeleted() {
return nil return nil
} }
_, err := idxFile.Write(value.ToBytes()) _, err := idxFile.Write(value.ToBytes())
@ -105,7 +105,7 @@ func (cm *MemDb) LoadFromIdx(idxName string) (ret error) {
defer idxFile.Close() defer idxFile.Close()
return idx.WalkIndexFile(idxFile, func(key NeedleId, offset Offset, size Size) error { 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.Delete(key)
} }
return cm.Set(key, offset, size) return cm.Set(key, offset, size)

2
weed/storage/needle_map_sorted_file.go

@ -80,7 +80,7 @@ func (m *SortedFileNeedleMap) Delete(key NeedleId, offset Offset) error {
return err return err
} }
if size == TombstoneFileSize {
if size.IsDeleted() {
return nil return nil
} }

4
weed/storage/types/needle_types.go

@ -15,6 +15,10 @@ type Offset struct {
type Size uint32 type Size uint32
func (s Size) IsDeleted() bool {
return s == TombstoneFileSize
}
type OffsetLower struct { type OffsetLower struct {
b3 byte b3 byte
b2 byte b2 byte

2
weed/storage/volume_checking.go

@ -27,7 +27,7 @@ func CheckVolumeDataIntegrity(v *Volume, indexFile *os.File) (lastAppendAtNs uin
if offset.IsZero() { if offset.IsZero() {
return 0, nil return 0, nil
} }
if size == TombstoneFileSize {
if size.IsDeleted() {
size = 0 size = 0
} }
if lastAppendAtNs, e = verifyNeedleIntegrity(v.DataBackend, v.Version(), offset.ToAcutalOffset(), key, size); e != nil { if lastAppendAtNs, e = verifyNeedleIntegrity(v.DataBackend, v.Version(), offset.ToAcutalOffset(), key, size); e != nil {

2
weed/storage/volume_read_write.go

@ -260,7 +260,7 @@ func (v *Volume) readNeedle(n *needle.Needle) (int, error) {
if !ok || nv.Offset.IsZero() { if !ok || nv.Offset.IsZero() {
return -1, ErrorNotFound return -1, ErrorNotFound
} }
if nv.Size == TombstoneFileSize {
if nv.Size.IsDeleted() {
return -1, errors.New("already deleted") return -1, errors.New("already deleted")
} }
if nv.Size == 0 { if nv.Size == 0 {

2
weed/storage/volume_vacuum.go

@ -413,7 +413,7 @@ func copyDataBasedOnIndexFile(srcDatName, srcIdxName, dstDatName, datIdxName str
offset, size := value.Offset, value.Size offset, size := value.Offset, value.Size
if offset.IsZero() || size == TombstoneFileSize {
if offset.IsZero() || size.IsDeleted() {
return nil return nil
} }

Loading…
Cancel
Save