refactoring

This commit is contained in:
Chris Lu 2020-08-18 17:35:19 -07:00
parent 332caf0cd7
commit ee11d98650
6 changed files with 10 additions and 6 deletions

View File

@ -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)

View File

@ -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
} }

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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
} }