(ctx context.Context, from, to, batchSize, taskId uint64)
| 453 | } |
| 454 | |
| 455 | func (s *StorageManager) downloadMetaInRange(ctx context.Context, from, to, batchSize, taskId uint64) error { |
| 456 | rangeStart := from |
| 457 | for from < to { |
| 458 | s.mu.Lock() |
| 459 | localL1 := s.localL1 |
| 460 | kvEntryCount := s.kvEntryCount |
| 461 | s.mu.Unlock() |
| 462 | |
| 463 | // In case remove is supported and kvEntryCount is decreased |
| 464 | batchLimit := min(min(from+batchSize, to), kvEntryCount) |
| 465 | |
| 466 | kvIndices := []uint64{} |
| 467 | for i := from; i < batchLimit; i++ { |
| 468 | kvIndices = append(kvIndices, i) |
| 469 | } |
| 470 | |
| 471 | metas, err := s.l1Source.GetKvMetas(kvIndices, localL1) |
| 472 | for retryTimes := 0; (retryTimes < 10) && (err != nil); retryTimes++ { |
| 473 | // Retry the request for 10 times in case it could fail occasionally in poor network connection |
| 474 | time.Sleep(2 * time.Second) |
| 475 | metas, err = s.l1Source.GetKvMetas(kvIndices, localL1) |
| 476 | } |
| 477 | |
| 478 | if err != nil { |
| 479 | return err |
| 480 | } |
| 481 | |
| 482 | s.mu.Lock() |
| 483 | if localL1 != s.localL1 { |
| 484 | s.mu.Unlock() |
| 485 | continue |
| 486 | } |
| 487 | for i, meta := range metas { |
| 488 | s.blobMetas[kvIndices[i]] = meta |
| 489 | } |
| 490 | s.mu.Unlock() |
| 491 | |
| 492 | s.lg.Info( |
| 493 | "One batch metas has been downloaded", "first", from, |
| 494 | "batchLimit", batchLimit, |
| 495 | "to", to, |
| 496 | "progress", fmt.Sprintf("%.1f%%", float64((from-rangeStart)*100)/float64(to-rangeStart)), |
| 497 | "taskId", taskId) |
| 498 | |
| 499 | select { |
| 500 | case <-ctx.Done(): |
| 501 | s.lg.Info("StorageManager res done, return") |
| 502 | return nil |
| 503 | default: |
| 504 | } |
| 505 | from = batchLimit |
| 506 | } |
| 507 | return nil |
| 508 | } |
| 509 | |
| 510 | // This function is only called by DownloadFinished which already uses s.mu to protect the s.blobMetas, so |
| 511 | // we don't need to lock in this function |
no test coverage detected