Skip to content

Commit

Permalink
Refactor rollup (#4184)
Browse files Browse the repository at this point in the history
  • Loading branch information
animesh2049 authored Oct 23, 2019
1 parent 8a5c2f2 commit 31de87c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,11 @@ func (l *List) rollup(readTs uint64) (*rollupOutput, error) {
var startUid, endUid uint64
var splitIdx int

// Method to properly initialize all the variables described above.
init := func() {
// Method to properly initialize the variables above
// when a multi-part list boundary is crossed.
initializeSplit := func() {
enc = codec.Encoder{BlockSize: blockSize}

// If not a multi-part list, all UIDs go to the same encoder.
if len(l.plist.Splits) == 0 {
plist = out.plist
endUid = math.MaxUint64
return
}

// Otherwise, load the corresponding part and set endUid to correctly
// detect the end of the list.
startUid = l.plist.Splits[splitIdx]
Expand All @@ -833,14 +827,21 @@ func (l *List) rollup(readTs uint64) (*rollupOutput, error) {
plist = &pb.PostingList{}
}

init()
// If not a multi-part list, all UIDs go to the same encoder.
if len(l.plist.Splits) == 0 {
plist = out.plist
endUid = math.MaxUint64
} else {
initializeSplit()
}

err := l.iterate(readTs, 0, func(p *pb.Posting) error {
if p.Uid > endUid {
plist.Pack = enc.Done()
out.parts[startUid] = plist

splitIdx++
init()
initializeSplit()
}

enc.Add(p.Uid)
Expand Down

0 comments on commit 31de87c

Please sign in to comment.