本文整理匯總了Golang中github.com/couchbase/sync_gateway/base.Set.Union方法的典型用法代碼示例。如果您正苦於以下問題:Golang Set.Union方法的具體用法?Golang Set.Union怎麽用?Golang Set.Union使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbase/sync_gateway/base.Set
的用法示例。
在下文中一共展示了Set.Union方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processEntry
// Handles a newly-arrived LogEntry.
func (c *changeCache) processEntry(change *LogEntry) base.Set {
c.lock.Lock()
defer c.lock.Unlock()
if c.logsDisabled {
return nil
}
sequence := change.Sequence
nextSequence := c.nextSequence
if _, found := c.receivedSeqs[sequence]; found {
base.LogTo("Cache+", " Ignoring duplicate of #%d", sequence)
return nil
}
c.receivedSeqs[sequence] = struct{}{}
// FIX: c.receivedSeqs grows monotonically. Need a way to remove old sequences.
var changedChannels base.Set
if sequence == nextSequence || nextSequence == 0 {
// This is the expected next sequence so we can add it now:
changedChannels = c._addToCache(change)
// Also add any pending sequences that are now contiguous:
changedChannels = changedChannels.Union(c._addPendingLogs())
} else if sequence > nextSequence {
// There's a missing sequence (or several), so put this one on ice until it arrives:
heap.Push(&c.pendingLogs, change)
numPending := len(c.pendingLogs)
base.LogTo("Cache", " Deferring #%d (%d now waiting for #%d...#%d)",
sequence, numPending, nextSequence, c.pendingLogs[0].Sequence-1)
changeCacheExpvars.Get("maxPending").(*base.IntMax).SetIfMax(int64(numPending))
if numPending > c.options.CachePendingSeqMaxNum {
// Too many pending; add the oldest one:
changedChannels = c._addPendingLogs()
}
} else if sequence > c.initialSequence {
// Out-of-order sequence received!
// Remove from skipped sequence queue
if !c.WasSkipped(sequence) {
// Error removing from skipped sequences
base.LogTo("Cache", " Received unexpected out-of-order change - not in skippedSeqs (seq %d, expecting %d) doc %q / %q", sequence, nextSequence, change.DocID, change.RevID)
} else {
base.LogTo("Cache", " Received previously skipped out-of-order change (seq %d, expecting %d) doc %q / %q ", sequence, nextSequence, change.DocID, change.RevID)
change.Skipped = true
}
changedChannels = c._addToCache(change)
// Add to cache before removing from skipped, to ensure lowSequence doesn't get incremented until results are available
// in cache
c.RemoveSkipped(sequence)
}
return changedChannels
}
示例2: _addPendingLogs
// Add the first change(s) from pendingLogs if they're the next sequence. If not, and we've been
// waiting too long for nextSequence, move nextSequence to skipped queue.
// Returns the channels that changed.
func (c *changeCache) _addPendingLogs() base.Set {
var changedChannels base.Set
for len(c.pendingLogs) > 0 {
change := c.pendingLogs[0]
isNext := change.Sequence == c.nextSequence
if isNext {
heap.Pop(&c.pendingLogs)
changedChannels = changedChannels.Union(c._addToCache(change))
} else if len(c.pendingLogs) > c.options.CachePendingSeqMaxNum || time.Since(c.pendingLogs[0].TimeReceived) >= c.options.CachePendingSeqMaxWait {
changeCacheExpvars.Add("outOfOrder", 1)
c.PushSkipped(c.nextSequence)
c.nextSequence++
} else {
break
}
}
return changedChannels
}