MCPcopy Create free account
hub / github.com/ethstorage/es-node / downloadMetaInParallel

Method downloadMetaInParallel

ethstorage/storage_manager.go:414–453  ·  view source on GitHub ↗
(ctx context.Context, from, to, batchSize uint64)

Source from the content-addressed store, hash-verified

412}
413
414func (s *StorageManager) downloadMetaInParallel(ctx context.Context, from, to, batchSize uint64) error {
415 var wg sync.WaitGroup
416 taskNum := uint64(MetaDownloadThread)
417
418 // We don't need to download in parallel if the meta amount is small
419 if to-from < uint64(taskNum)*batchSize {
420 return s.downloadMetaInRange(ctx, from, to, batchSize, 0)
421 }
422
423 chanRes := make(chan error, taskNum)
424 defer close(chanRes)
425
426 rangeSize := (to - from) / uint64(taskNum)
427 for taskIdx := uint64(0); taskIdx < taskNum; taskIdx++ {
428 rangeStart := taskIdx * rangeSize
429 rangeEnd := (taskIdx + 1) * rangeSize
430 if taskIdx == taskNum-1 {
431 rangeEnd = to
432 }
433 wg.Add(1)
434
435 go func(start, end, taskId uint64, out chan<- error) {
436 defer wg.Done()
437 err := s.downloadMetaInRange(ctx, start, end, batchSize, taskId)
438
439 chanRes <- err
440 }(rangeStart, rangeEnd, taskIdx, chanRes)
441 }
442
443 wg.Wait()
444
445 for i := uint64(0); i < taskNum; i++ {
446 res := <-chanRes
447 if res != nil {
448 return res
449 }
450 }
451
452 return nil
453}
454
455func (s *StorageManager) downloadMetaInRange(ctx context.Context, from, to, batchSize, taskId uint64) error {
456 rangeStart := from

Callers 1

DownloadAllMetasMethod · 0.95

Calls 1

downloadMetaInRangeMethod · 0.95

Tested by

no test coverage detected