{"record":{"id":"64ad30665ceb9308","repo":"dgraph-io/dgraph","slug":"error-cache-percentages-s-does-not-sum-up-to-1","errorCode":null,"errorMessage":"ERROR: cache percentages (%s) does not sum up to 100","messagePattern":"ERROR: cache percentages \\((.+?)\\) does not sum up to 100","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":1407,"sourceCode":"\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 {\n\t\treturn nil, errors.Errorf(\"ERROR: cache percentages (%s) does not sum up to 100\",\n\t\t\tstrings.Join(cp, \"+\"))\n\t}\n\n\treturn cachePercent, nil\n}\n\n// ParseCompression returns badger.compressionType and compression level given compression string\n// of format compression-type:compression-level\nfunc ParseCompression(cStr string) (bo.CompressionType, int) {\n\tcStrSplit := strings.Split(cStr, \":\")\n\tcType := cStrSplit[0]\n\tlevel := 3\n\n\tvar err error\n\tif len(cStrSplit) == 2 {\n\t\tlevel, err = strconv.Atoi(cStrSplit[1])\n\t\tCheck(err)\n\t\tif level <= 0 {","sourceCodeStart":1389,"sourceCodeEnd":1425,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L1389-L1425","documentation":"After parsing all cache percentage entries, this function verifies that they sum to exactly 100. If the total differs (e.g. \"50+30\" = 80, or \"40+70\" = 110), it rejects the whole list with this error, joining the original strings with '+' for readability. This guarantees cache allocations are expressed as a complete partition of capacity.","triggerScenarios":"Calling the cache-configuration API with percentage entries whose integer sum is not exactly 100, e.g. \"50,30\" or \"40,70\", or a single value like \"80\". Note each individual entry must also pass the earlier parse and non-negative checks first.","commonSituations":"Adding or removing a cache tier without rebalancing the others; rounding values (33+33+33=99); misreading the format as fractions (\"0.5,0.5\"), though decimals fail the earlier Atoi parse; stale config left over from a version change in tier count.","solutions":["Adjust the percentage values so they sum to exactly 100 (e.g. change \"50,30\" to \"50,50\").","If a tier was added or removed, redistribute the freed or needed percentage across the remaining tiers.","Avoid fractional rounding: assign the remainder to one tier (e.g. 34+33+33) so the total is exactly 100."],"exampleFix":"// before\ncachePercent, err := setCachePercentages(strings.Split(\"50,30\", \",\")) // sums to 80\n\n// after\ncachePercent, err := setCachePercentages(strings.Split(\"50,50\", \",\")) // sums to 100","handlingStrategy":"validation","validationCode":"func validateCachePercentSum(cp []string) error {\n    sum := 0\n    for _, p := range cp {\n        v, err := strconv.Atoi(p)\n        if err != nil {\n            return fmt.Errorf(\"cache percentage %q is not an integer\", p)\n        }\n        if v < 0 {\n            return fmt.Errorf(\"cache percentage %q is negative\", p)\n        }\n        sum += v\n    }\n    if sum != 100 {\n        return fmt.Errorf(\"cache percentages %v sum to %d, want 100\", cp, sum)\n    }\n    return nil\n}","typeGuard":"func sumsTo100(cp []string) bool {\n    sum := 0\n    for _, p := range cp {\n        v, err := strconv.Atoi(p)\n        if err != nil {\n            return false\n        }\n        sum += v\n    }\n    return sum == 100\n}","tryCatchPattern":"cachePercent, err := setCachePercentages(cp)\nif err != nil {\n    if strings.Contains(err.Error(), \"does not sum up to 100\") {\n        return fmt.Errorf(\"cache config %v must total exactly 100\", cp)\n    }\n    return err\n}","preventionTips":["After any config edit, verify the percentage entries total exactly 100.","When adding or removing a tier, rebalance all percentages in the same change.","Assign rounding remainders to one tier so integer entries sum to 100.","Add a startup-time precheck that sums the entries and fails with a clear message."],"tags":["configuration","validation","cache"],"backgroundTag":"invalid-config-value","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}