MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / GetCachePercentages

Function GetCachePercentages

x/x.go:1307–1335  ·  view source on GitHub ↗

GetCachePercentages returns the slice of cache percentages given the "," (comma) separated cache percentages(integers) string and expected number of caches.

(cpString string, numExpected int)

Source from the content-addressed store, hash-verified

1305// GetCachePercentages returns the slice of cache percentages given the "," (comma) separated
1306// cache percentages(integers) string and expected number of caches.
1307func GetCachePercentages(cpString string, numExpected int) ([]int64, error) {
1308 cp := strings.Split(cpString, ",")
1309 // Sanity checks
1310 if len(cp) != numExpected {
1311 return nil, errors.Errorf("ERROR: expected %d cache percentages, got %d",
1312 numExpected, len(cp))
1313 }
1314
1315 var cachePercent []int64
1316 percentSum := 0
1317 for _, percent := range cp {
1318 x, err := strconv.Atoi(percent)
1319 if err != nil {
1320 return nil, errors.Errorf("ERROR: unable to parse cache percentage(%s)", percent)
1321 }
1322 if x < 0 {
1323 return nil, errors.Errorf("ERROR: cache percentage(%s) cannot be negative", percent)
1324 }
1325 cachePercent = append(cachePercent, int64(x))
1326 percentSum += x
1327 }
1328
1329 if percentSum != 100 {
1330 return nil, errors.Errorf("ERROR: cache percentages (%s) does not sum up to 100",
1331 strings.Join(cp, "+"))
1332 }
1333
1334 return cachePercent, nil
1335}
1336
1337// ParseCompression returns badger.compressionType and compression level given compression string
1338// of format compression-type:compression-level

Callers 2

runFunction · 0.92
UpdateCacheMbFunction · 0.92

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected