From 31de87ce9a09e82c87f89ea3dd8f240106169b6e Mon Sep 17 00:00:00 2001 From: Animesh Chandra Pathak Date: Wed, 23 Oct 2019 15:12:31 +0530 Subject: [PATCH] Refactor rollup (#4184) --- posting/list.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/posting/list.go b/posting/list.go index 03c60280ff5..8e29b2d1256 100644 --- a/posting/list.go +++ b/posting/list.go @@ -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] @@ -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)