* // sanityCheck can be kept around for debugging, and can be called when deallocating Pack. func sanityCheck(prefix string, out *rollupOutput) { seen := make(map[string]string) hb := func(which string, pack *pb.UidPack, block *pb.UidBlock) { paddr := fmt.Sprintf("%p", pack) baddr := fmt.Spri
(out *rollupOutput, readTs uint64, split bool)
| 1588 | */ |
| 1589 | |
| 1590 | func (l *List) encode(out *rollupOutput, readTs uint64, split bool) error { |
| 1591 | var plist *pb.PostingList |
| 1592 | var startUid, endUid uint64 |
| 1593 | var splitIdx int |
| 1594 | enc := codec.Encoder{BlockSize: blockSize} |
| 1595 | |
| 1596 | // Method to properly initialize the variables above |
| 1597 | // when a multi-part list boundary is crossed. |
| 1598 | initializeSplit := func() { |
| 1599 | enc = codec.Encoder{BlockSize: blockSize} |
| 1600 | |
| 1601 | // Load the corresponding part and set endUid to correctly detect the end of the list. |
| 1602 | startUid = l.plist.Splits[splitIdx] |
| 1603 | if splitIdx+1 == len(l.plist.Splits) { |
| 1604 | endUid = math.MaxUint64 |
| 1605 | } else { |
| 1606 | endUid = l.plist.Splits[splitIdx+1] - 1 |
| 1607 | } |
| 1608 | |
| 1609 | plist = &pb.PostingList{} |
| 1610 | } |
| 1611 | |
| 1612 | // If not a multi-part list, all UIDs go to the same encoder. |
| 1613 | if len(l.plist.Splits) == 0 || !split { |
| 1614 | plist = out.plist |
| 1615 | endUid = math.MaxUint64 |
| 1616 | } else { |
| 1617 | initializeSplit() |
| 1618 | } |
| 1619 | |
| 1620 | err := l.iterate(readTs, 0, func(p *pb.Posting) error { |
| 1621 | if p.Uid > endUid && split { |
| 1622 | plist.Pack = enc.Done() |
| 1623 | out.parts[startUid] = plist |
| 1624 | |
| 1625 | splitIdx++ |
| 1626 | initializeSplit() |
| 1627 | } |
| 1628 | |
| 1629 | enc.Add(p.Uid) |
| 1630 | if p.Facets != nil || p.PostingType != pb.Posting_REF { |
| 1631 | plist.Postings = append(plist.Postings, p) |
| 1632 | } |
| 1633 | return nil |
| 1634 | }) |
| 1635 | // Finish writing the last part of the list (or the whole list if not a multi-part list). |
| 1636 | if err != nil { |
| 1637 | return errors.Wrapf(err, "cannot iterate through the list") |
| 1638 | } |
| 1639 | plist.Pack = enc.Done() |
| 1640 | if plist.Pack != nil { |
| 1641 | if plist.Pack.BlockSize != uint32(blockSize) { |
| 1642 | return errors.Errorf("actual block size %d is different from expected value %d", |
| 1643 | plist.Pack.BlockSize, blockSize) |
| 1644 | } |
| 1645 | } |
| 1646 | if split && len(l.plist.Splits) > 0 { |
| 1647 | out.parts[startUid] = plist |