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

View file

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

View file

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

View file

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

View file

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

View file

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