MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / GetBalancedStorage

Function GetBalancedStorage

internal/op/storage.go:448–464  ·  view source on GitHub ↗

GetBalancedStorage get storage by path

(path string)

Source from the content-addressed store, hash-verified

446
447// GetBalancedStorage get storage by path
448func 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
466var detailsG singleflight.Group[*model.StorageDetails]
467

Callers 3

TestGetBalancedStorageFunction · 0.92
IsStorageSignEnabledFunction · 0.92
GetStorageAndActualPathFunction · 0.85

Calls 6

FixAndCleanPathFunction · 0.92
GetActualMountPathFunction · 0.92
getStoragesByPathFunction · 0.85
LoadOrStoreMethod · 0.80
GetStorageMethod · 0.65
StoreMethod · 0.45

Tested by 1

TestGetBalancedStorageFunction · 0.74