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

Method _addToCache

db/change_cache.go:837–872  ·  view source on GitHub ↗

Adds an entry to the appropriate channels' caches, returning the affected channels. lateSequence flag indicates whether it was a change arriving out of sequence

(ctx context.Context, change *LogEntry)

Source from the content-addressed store, hash-verified

835// Adds an entry to the appropriate channels' caches, returning the affected channels. lateSequence
836// flag indicates whether it was a change arriving out of sequence
837func (c *changeCache) _addToCache(ctx context.Context, change *LogEntry) []channels.ID {
838
839 if change.Sequence >= c.nextSequence {
840 c.nextSequence = change.Sequence + 1
841 }
842 // check if change is unused sequence range
843 if change.EndSequence != 0 {
844 c.nextSequence = change.EndSequence + 1
845 }
846 delete(c.receivedSeqs, change.Sequence)
847
848 // If unused sequence, notify the cache and return
849 if change.UnusedSequence {
850 c.channelCache.AddUnusedSequence(change)
851 return nil
852 }
853
854 if change.IsPrincipal {
855 c.channelCache.AddPrincipal(change)
856 return nil
857 }
858
859 // updatedChannels tracks the set of channels that should be notified of the change. This includes
860 // the change's active channels, as well as any channel removals for the active revision.
861 updatedChannels := c.channelCache.AddToCache(ctx, change)
862 if base.LogDebugEnabled(ctx, base.KeyChanges) {
863 base.DebugfCtx(ctx, base.KeyChanges, " #%d ==> channels %v", change.Sequence, base.UD(updatedChannels))
864 }
865
866 if change.TimeReceived != 0 {
867 c.db.DbStats.Database().DCPCachingCount.Add(1)
868 c.db.DbStats.Database().DCPCachingTime.Add(change.TimeReceived.Since())
869 }
870
871 return updatedChannels
872}
873
874// _addPendingLogs Add the first change(s) from pendingLogs if they're the next sequence. If not, and we've been
875// waiting too long for nextSequence, move nextSequence to skipped queue.

Callers 2

processEntryMethod · 0.95
_addPendingLogsMethod · 0.95

Calls 9

LogDebugEnabledFunction · 0.92
DebugfCtxFunction · 0.92
UDFunction · 0.92
AddUnusedSequenceMethod · 0.65
AddPrincipalMethod · 0.65
AddToCacheMethod · 0.65
AddMethod · 0.45
DatabaseMethod · 0.45
SinceMethod · 0.45

Tested by

no test coverage detected