dgraph-io/dgraph · error

ERROR: cache percentages (%s) does not sum up to 100

Error message

ERROR: cache percentages (%s) does not sum up to 100

What it means

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.

Source

Thrown at x/x.go:1407

			numExpected, len(cp))
	}

	var cachePercent []int64
	percentSum := 0
	for _, percent := range cp {
		x, err := strconv.Atoi(percent)
		if err != nil {
			return nil, errors.Errorf("ERROR: unable to parse cache percentage(%s)", percent)
		}
		if x < 0 {
			return nil, errors.Errorf("ERROR: cache percentage(%s) cannot be negative", percent)
		}
		cachePercent = append(cachePercent, int64(x))
		percentSum += x
	}

	if percentSum != 100 {
		return nil, errors.Errorf("ERROR: cache percentages (%s) does not sum up to 100",
			strings.Join(cp, "+"))
	}

	return cachePercent, nil
}

// ParseCompression returns badger.compressionType and compression level given compression string
// of format compression-type:compression-level
func ParseCompression(cStr string) (bo.CompressionType, int) {
	cStrSplit := strings.Split(cStr, ":")
	cType := cStrSplit[0]
	level := 3

	var err error
	if len(cStrSplit) == 2 {
		level, err = strconv.Atoi(cStrSplit[1])
		Check(err)
		if level <= 0 {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Adjust the percentage values so they sum to exactly 100 (e.g. change "50,30" to "50,50").
  2. If a tier was added or removed, redistribute the freed or needed percentage across the remaining tiers.
  3. Avoid fractional rounding: assign the remainder to one tier (e.g. 34+33+33) so the total is exactly 100.

Example fix

// before
cachePercent, err := setCachePercentages(strings.Split("50,30", ",")) // sums to 80

// after
cachePercent, err := setCachePercentages(strings.Split("50,50", ",")) // sums to 100
Defensive patterns

Strategy: validation

Validate before calling

func validateCachePercentSum(cp []string) error {
    sum := 0
    for _, p := range cp {
        v, err := strconv.Atoi(p)
        if err != nil {
            return fmt.Errorf("cache percentage %q is not an integer", p)
        }
        if v < 0 {
            return fmt.Errorf("cache percentage %q is negative", p)
        }
        sum += v
    }
    if sum != 100 {
        return fmt.Errorf("cache percentages %v sum to %d, want 100", cp, sum)
    }
    return nil
}

Type guard

func sumsTo100(cp []string) bool {
    sum := 0
    for _, p := range cp {
        v, err := strconv.Atoi(p)
        if err != nil {
            return false
        }
        sum += v
    }
    return sum == 100
}

Try / catch

cachePercent, err := setCachePercentages(cp)
if err != nil {
    if strings.Contains(err.Error(), "does not sum up to 100") {
        return fmt.Errorf("cache config %v must total exactly 100", cp)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/64ad30665ceb9308. Report an issue: GitHub.