MCPcopy
hub / github.com/aceld/zinx / snapshot

Function snapshot

zutils/shard_lock_map.go:334–352  ·  view source on GitHub ↗

Returns a array of channels that contains elements in each shard, which likely takes a snapshot of `slm`. It returns once the size of each buffered channel is determined, before all the channels are populated using goroutines.

(slm ShardLockMaps)

Source from the content-addressed store, hash-verified

332// It returns once the size of each buffered channel is determined,
333// before all the channels are populated using goroutines.
334func snapshot(slm ShardLockMaps) (chanList []chan Tuple) {
335 chanList = make([]chan Tuple, slm.shardCount)
336 wg := sync.WaitGroup{}
337 wg.Add(slm.shardCount)
338 for index, shard := range slm.shards {
339 go func(index int, shard *SingleShardMap) {
340 shard.RLock()
341 chanList[index] = make(chan Tuple, len(shard.items))
342 wg.Done()
343 for key, val := range shard.items {
344 chanList[index] <- Tuple{key, val}
345 }
346 shard.RUnlock()
347 close(chanList[index])
348 }(index, shard)
349 }
350 wg.Wait()
351 return chanList
352}
353
354// fanIn reads elements from channels `chanList` into channel `out`
355func fanIn(chanList []chan Tuple, out chan Tuple) {

Callers 1

IterBufferedMethod · 0.85

Calls 1

AddMethod · 0.65

Tested by

no test coverage detected