Skip to content

Commit

Permalink
trimming mergeToWriter API signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Thejas-bhat committed Sep 20, 2023
1 parent e49a45b commit b8f406e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
23 changes: 11 additions & 12 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ func mergeSegmentBases(segmentBases []*SegmentBase, drops []*roaring.Bitmap, pat
// wrap it for counting (tracking offsets)
cr := NewCountHashWriterWithStatsReporter(br, s)

newDocNums, numDocs, storedIndexOffset, fieldsIndexOffset, docValueOffset, _, _, _, sectionsIndexOffset, err :=
newDocNums, numDocs, storedIndexOffset, _, _, _, sectionsIndexOffset, err :=
MergeToWriter(segmentBases, drops, chunkMode, cr, closeCh)
if err != nil {
cleanup()
return nil, 0, err
}

err = persistFooter(numDocs, storedIndexOffset, fieldsIndexOffset, sectionsIndexOffset,
docValueOffset, chunkMode, cr.Sum32(), cr)
// passing the sectionsIndexOffset as fieldsIndexOffset and the docValueOffset as 0 for the footer
err = persistFooter(numDocs, storedIndexOffset, sectionsIndexOffset, sectionsIndexOffset,
0, chunkMode, cr.Sum32(), cr)
if err != nil {
cleanup()
return nil, 0, err
Expand Down Expand Up @@ -110,11 +111,9 @@ func mergeSegmentBases(segmentBases []*SegmentBase, drops []*roaring.Bitmap, pat

func MergeToWriter(segments []*SegmentBase, drops []*roaring.Bitmap,
chunkMode uint32, cr *CountHashWriter, closeCh chan struct{}) (
newDocNums [][]uint64,
numDocs, storedIndexOffset, fieldsIndexOffset, docValueOffset uint64,
dictLocs []uint64, fieldsInv []string, fieldsMap map[string]uint16, sectionsIndexOffset uint64,
newDocNums [][]uint64, numDocs, storedIndexOffset uint64, dictLocs []uint64,
fieldsInv []string, fieldsMap map[string]uint16, sectionsIndexOffset uint64,
err error) {
docValueOffset = uint64(fieldNotUninverted)

var fieldsSame bool
fieldsSame, fieldsInv = mergeFields(segments)
Expand All @@ -123,7 +122,7 @@ func MergeToWriter(segments []*SegmentBase, drops []*roaring.Bitmap,
numDocs = computeNewDocCount(segments, drops)

if isClosed(closeCh) {
return nil, 0, 0, 0, 0, nil, nil, nil, 0, seg.ErrClosed
return nil, 0, 0, nil, nil, nil, 0, seg.ErrClosed
}

// the merge opaque is especially important when it comes to tracking the file
Expand All @@ -141,7 +140,7 @@ func MergeToWriter(segments []*SegmentBase, drops []*roaring.Bitmap,
storedIndexOffset, newDocNums, err = mergeStoredAndRemap(segments, drops,
fieldsMap, fieldsInv, fieldsSame, numDocs, cr, closeCh)
if err != nil {
return nil, 0, 0, 0, 0, nil, nil, nil, 0, err
return nil, 0, 0, nil, nil, nil, 0, err
}

// at this point, ask each section implementation to merge itself
Expand All @@ -150,7 +149,7 @@ func MergeToWriter(segments []*SegmentBase, drops []*roaring.Bitmap,

err = x.Merge(mergeOpaque, segments, drops, fieldsInv, newDocNums, cr, closeCh)
if err != nil {
return nil, 0, 0, 0, 0, nil, nil, nil, 0, err
return nil, 0, 0, nil, nil, nil, 0, err
}
}
} else {
Expand All @@ -161,10 +160,10 @@ func MergeToWriter(segments []*SegmentBase, drops []*roaring.Bitmap,
// to the various indexes (each in different section) available for a field.
sectionsIndexOffset, err = persistFieldsSection(fieldsInv, cr, dictLocs, mergeOpaque)
if err != nil {
return nil, 0, 0, 0, 0, nil, nil, nil, 0, err
return nil, 0, 0, nil, nil, nil, 0, err
}

return newDocNums, numDocs, storedIndexOffset, sectionsIndexOffset, docValueOffset, dictLocs, fieldsInv, fieldsMap, sectionsIndexOffset, nil
return newDocNums, numDocs, storedIndexOffset, dictLocs, fieldsInv, fieldsMap, sectionsIndexOffset, nil
}

// mapFields takes the fieldsInv list and returns a map of fieldName
Expand Down
4 changes: 2 additions & 2 deletions section_inverted_text_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (i *invertedIndexOpaque) grabBuf(size int) []byte {
buf = make([]byte, size)
i.tmp0 = buf
}
return buf[0:size]
return buf[:size]
}

func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uint64, err error) {
Expand Down Expand Up @@ -407,7 +407,7 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin
if cap(docTermMap) < len(io.results) {
docTermMap = make([][]byte, len(io.results))
} else {
docTermMap = docTermMap[0:len(io.results)]
docTermMap = docTermMap[:len(io.results)]
for docNum := range docTermMap { // reset the docTermMap
docTermMap[docNum] = docTermMap[docNum][:0]
}
Expand Down
1 change: 1 addition & 0 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func persistFieldsSection(fieldsInv []string, w *CountHashWriter, dictLocs []uin
// crc + ver + chunk + docValueOffset + sectionsIndexOffset + field offset + stored offset + num docs
const FooterSize = 4 + 4 + 4 + 8 + 8 + 8 + 8 + 8

// in the index sections format, the fieldsIndexOffset points to the sectionsIndexOffset
func persistFooter(numDocs, storedIndexOffset, fieldsIndexOffset, sectionsIndexOffset, docValueOffset uint64,
chunkMode uint32, crcBeforeFooter uint32, writerIn io.Writer) error {
w := NewCountHashWriter(writerIn)
Expand Down

0 comments on commit b8f406e

Please sign in to comment.