Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor rollup #4184

Merged
merged 2 commits into from
Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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