MCPcopy Create free account
hub / github.com/Super-long/ChubbyGo / snapshot

Function snapshot

BaseServer/concurrentHashMap.go:216–236  ·  view source on GitHub ↗

Returns a array of channels that contains elements in each shard, which likely takes a snapshot of `m`. It returns once the size of each buffered channel is determined, before all the channels are populated using goroutines. 返回值是SHARD_COUNT个缓冲channel

(m ConcurrentHashMap)

Source from the content-addressed store, hash-verified

214// before all the channels are populated using goroutines.
215// 返回值是SHARD_COUNT个缓冲channel
216func snapshot(m ConcurrentHashMap) (chans []chan Tuple) {
217 chans = make([]chan Tuple, SHARD_COUNT)
218 wg := sync.WaitGroup{}
219 wg.Add(SHARD_COUNT)
220 // Foreach shard.
221 for index, shard := range m.ThreadSafeHashMap {
222 go func(index int, shard *ConcurrentMapShared) {
223 // Foreach key, value pair.
224 shard.RLock()
225 chans[index] = make(chan Tuple, len(shard.items))
226 wg.Done()
227 for key, val := range shard.items {
228 chans[index] <- Tuple{key, val}
229 }
230 shard.RUnlock()
231 close(chans[index])
232 }(index, shard)
233 }
234 wg.Wait()
235 return chans
236}
237
238// fanIn reads elements from channels `chans` into channel `out`
239func fanIn(chans []chan Tuple, out chan Tuple) {

Callers 2

IterMethod · 0.85
IterBufferedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected