MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / _popPendingLog

Method _popPendingLog

db/change_cache.go:919–949  ·  view source on GitHub ↗

_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)

Source from the content-addressed store, hash-verified

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.
919func (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
951func (c *changeCache) GetStableSequence(docID string) SequenceID {
952 // Stable sequence is independent of docID in changeCache

Callers 1

_addPendingLogsMethod · 0.95

Calls 3

InfofCtxFunction · 0.92
PopMethod · 0.80
IsUnusedRangeMethod · 0.80

Tested by

no test coverage detected