Skip to content

Commit

Permalink
bug fix determing the correct portion of index file for sb.mem
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Sep 11, 2023
1 parent 79e04c4 commit 037a94f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (*ZapPlugin) Open(path string) (segment.Segment, error) {

rv := &Segment{
SegmentBase: SegmentBase{
mem: mm[0 : len(mm)-FooterSize],
fieldsMap: make(map[string]uint16),
fieldFSTs: make(map[uint16]*vellum.FST),
fieldDvReaders: make([]map[uint16]*docValueReader, len(segmentSections)),
Expand Down Expand Up @@ -212,10 +211,17 @@ func (s *Segment) loadConfig() error {
s.docValueOffset = binary.BigEndian.Uint64(s.mm[docValueOffset : docValueOffset+8])

fieldsIndexOffset := docValueOffset - 8
// for version 16, parse the sectionsIndexOffset

// determining the right footer size based on version, this becomes important
// while loading the fields portion or the sections portion of the index file.
var footerSize int
if s.version >= IndexSectionsVersion {
// for version 16 and above, parse the sectionsIndexOffset
s.sectionsIndexOffset = binary.BigEndian.Uint64(s.mm[fieldsIndexOffset : fieldsIndexOffset+8])
fieldsIndexOffset = fieldsIndexOffset - 8
footerSize = FooterSize
} else {
footerSize = FooterSize - 8
}

s.fieldsIndexOffset = binary.BigEndian.Uint64(s.mm[fieldsIndexOffset : fieldsIndexOffset+8])
Expand All @@ -229,6 +235,7 @@ func (s *Segment) loadConfig() error {
// 8*4 + 4*3 = 44 bytes being accounted from all the offsets
// above being read from the file
s.incrementBytesRead(44)
s.SegmentBase.mem = s.mm[:len(s.mm)-footerSize]
return nil
}

Expand Down

0 comments on commit 037a94f

Please sign in to comment.