GetBalancedStorage get storage by path
(path string)
| 446 | |
| 447 | // GetBalancedStorage get storage by path |
| 448 | func GetBalancedStorage(path string) driver.Driver { |
| 449 | path = utils.FixAndCleanPath(path) |
| 450 | storages := getStoragesByPath(path) |
| 451 | storageNum := len(storages) |
| 452 | switch storageNum { |
| 453 | case 0: |
| 454 | return nil |
| 455 | case 1: |
| 456 | return storages[0] |
| 457 | default: |
| 458 | virtualPath := utils.GetActualMountPath(storages[0].GetStorage().MountPath) |
| 459 | i, _ := balanceMap.LoadOrStore(virtualPath, 0) |
| 460 | i = (i + 1) % storageNum |
| 461 | balanceMap.Store(virtualPath, i) |
| 462 | return storages[i] |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | var detailsG singleflight.Group[*model.StorageDetails] |
| 467 |