_popPendingLog pops the next pending LogEntry from the c.pendingLogs heap. When the popped entry is an unused range, performs a defensive check for duplicates with the next entry in pending. If unused range overlaps with next entry, reduces the unused range to stop at the next pending entry.
(ctx context.Context)
| 917 | // performs a defensive check for duplicates with the next entry in pending. If unused range overlaps with next entry, |
| 918 | // reduces the unused range to stop at the next pending entry. |
| 919 | func (c *changeCache) _popPendingLog(ctx context.Context) *LogEntry { |
| 920 | poppedEntry := heap.Pop(&c.pendingLogs).(*LogEntry) |
| 921 | // If it's not a range, no additional handling needed |
| 922 | if !poppedEntry.IsUnusedRange() { |
| 923 | return poppedEntry |
| 924 | } |
| 925 | // If there are no more pending logs, no additional handling needed |
| 926 | if len(c.pendingLogs) == 0 { |
| 927 | return poppedEntry |
| 928 | } |
| 929 | |
| 930 | nextPendingEntry := c.pendingLogs[0] |
| 931 | // If popped entry range does not overlap with next pending entry, no additional handling needed |
| 932 | // e.g. popped [15-20], nextPendingEntry is [25] |
| 933 | if poppedEntry.EndSequence < nextPendingEntry.Sequence { |
| 934 | return poppedEntry |
| 935 | } |
| 936 | |
| 937 | // If nextPendingEntry's sequence duplicates the start of the unused range, ignored popped entry and return next entry instead |
| 938 | // e.g. popped [15-20], nextPendingEntry is [15] |
| 939 | if poppedEntry.Sequence == nextPendingEntry.Sequence { |
| 940 | base.InfofCtx(ctx, base.KeyCache, "Unused sequence range in pendingLogs (%d, %d) has start equal to next pending sequence (%s, %d) - unused range will be ignored", poppedEntry.Sequence, poppedEntry.EndSequence, nextPendingEntry.DocID, nextPendingEntry.Sequence) |
| 941 | return c._popPendingLog(ctx) |
| 942 | } |
| 943 | |
| 944 | // Otherwise, reduce the popped unused range to end before the next pending sequence |
| 945 | // e.g. popped [15-20], nextPendingEntry is [18] |
| 946 | base.InfofCtx(ctx, base.KeyCache, "Unused sequence range in pendingLogs (%d, %d) overlaps with next pending sequence (%s, %d) - unused range will be truncated", poppedEntry.Sequence, poppedEntry.EndSequence, nextPendingEntry.DocID, nextPendingEntry.Sequence) |
| 947 | poppedEntry.EndSequence = nextPendingEntry.Sequence - 1 |
| 948 | return poppedEntry |
| 949 | } |
| 950 | |
| 951 | func (c *changeCache) GetStableSequence(docID string) SequenceID { |
| 952 | // Stable sequence is independent of docID in changeCache |
no test coverage detected