{"record":{"id":"41549bd3ee78376a","repo":"dgraph-io/dgraph","slug":"error-expected-d-cache-percentages-got-d","errorCode":null,"errorMessage":"ERROR: expected %d cache percentages, got %d","messagePattern":"ERROR: expected (.+?) cache percentages, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":1388,"sourceCode":"\t\tswitch val := v.(type) {\n\t\tcase map[string]interface{}:\n\t\t\taCopy = append(aCopy, DeepCopyJsonMap(val))\n\t\tcase []interface{}:\n\t\t\taCopy = append(aCopy, DeepCopyJsonArray(val))\n\t\tdefault:\n\t\t\taCopy = append(aCopy, val)\n\t\t}\n\t}\n\treturn aCopy\n}\n\n// GetCachePercentages returns the slice of cache percentages given the \",\" (comma) separated\n// cache percentages(integers) string and expected number of caches.\nfunc GetCachePercentages(cpString string, numExpected int) ([]int64, error) {\n\tcp := strings.Split(cpString, \",\")\n\t// Sanity checks\n\tif len(cp) != numExpected {\n\t\treturn nil, errors.Errorf(\"ERROR: expected %d cache percentages, got %d\",\n\t\t\tnumExpected, len(cp))\n\t}\n\n\tvar cachePercent []int64\n\tpercentSum := 0\n\tfor _, percent := range cp {\n\t\tx, err := strconv.Atoi(percent)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"ERROR: unable to parse cache percentage(%s)\", percent)\n\t\t}\n\t\tif x < 0 {\n\t\t\treturn nil, errors.Errorf(\"ERROR: cache percentage(%s) cannot be negative\", percent)\n\t\t}\n\t\tcachePercent = append(cachePercent, int64(x))\n\t\tpercentSum += x\n\t}\n\n\tif percentSum != 100 {","sourceCodeStart":1370,"sourceCodeEnd":1406,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L1370-L1406","documentation":"GetCachePercentages splits a comma-separated string of cache percentage integers and first checks that the count matches numExpected. When the number of comma-separated values differs from the expected number of caches, it returns this error instead of guessing a distribution.","triggerScenarios":"Calling GetCachePercentages(cpString, numExpected) with a cpString that splits into a different number of items than numExpected — e.g. \"50,50\" when 3 caches are expected.","commonSituations":"Config values like 'cache-pct: 60,40' copied from a different drive count, trailing/missing commas changing the split count, or drive/cache configuration updated without updating the percentage list.","solutions":["Provide exactly numExpected comma-separated values, e.g. \"40,30,30\" for 3 caches","Update the cache percentage config to match the current number of caches/drives","Check for stray commas or whitespace entries that alter the split count"],"exampleFix":"// before\ncp, err := GetCachePercentages(\"50,50\", 3) // expected 3, got 2\n// after\ncp, err := GetCachePercentages(\"40,30,30\", 3)","handlingStrategy":"validation","validationCode":"func checkCachePercentages(cpString string, expected int) error {\n    n := len(strings.Split(cpString, \",\"))\n    if n != expected {\n        return fmt.Errorf(\"config has %d cache percentages, need %d\", n, expected)\n    }\n    return nil\n}","typeGuard":"func hasExpectedParts(cpString string, expected int) bool { return len(strings.Split(cpString, \",\")) == expected }","tryCatchPattern":null,"preventionTips":["Keep the percentage list length in sync with the number of caches/drives","Validate cache config at startup with the expected count from the deployment config","Avoid trailing commas and empty entries in comma-separated lists"],"tags":["configuration","cache","validation"],"backgroundTag":"config-value-count-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}