dgraph-io/badger · error

Invalid ValueThreshold, must be less or equal to %d

Error message

Invalid ValueThreshold, must be less or equal to %d

What it means

badger stores values smaller than ValueThreshold inline in the LSM tree and larger values in the value log. checkAndSetOptions rejects ValueThreshold values above maxValueThreshold (1GB) because a single value larger than that cap cannot be handled by the value-log design.

Source

Thrown at db.go:165

	if opt.NumCompactors == 1 {
		return errors.New("Cannot have 1 compactor. Need at least 2")
	}

	if opt.InMemory && (opt.Dir != "" || opt.ValueDir != "") {
		return errors.New("Cannot use badger in Disk-less mode with Dir or ValueDir set")
	}
	opt.maxBatchSize = (15 * opt.MemTableSize) / 100
	opt.maxBatchCount = opt.maxBatchSize / int64(skl.MaxNodeSize)

	// This is the maximum value, vlogThreshold can have if dynamic thresholding is enabled.
	opt.maxValueThreshold = math.Min(maxValueThreshold, float64(opt.maxBatchSize))
	if opt.VLogPercentile < 0.0 || opt.VLogPercentile > 1.0 {
		return errors.New("vlogPercentile must be within range of 0.0-1.0")
	}

	// We are limiting opt.ValueThreshold to maxValueThreshold for now.
	if opt.ValueThreshold > maxValueThreshold {
		return fmt.Errorf("Invalid ValueThreshold, must be less or equal to %d",
			maxValueThreshold)
	}

	// If ValueThreshold is greater than opt.maxBatchSize, we won't be able to push any data using
	// the transaction APIs. Transaction batches entries into batches of size opt.maxBatchSize.
	if opt.ValueThreshold > opt.maxBatchSize {
		return fmt.Errorf("Valuethreshold %d greater than max batch size of %d. Either "+
			"reduce opt.ValueThreshold or increase opt.BaseTableSize.",
			opt.ValueThreshold, opt.maxBatchSize)
	}
	// ValueLogFileSize should be strictly LESS than 2<<30 otherwise we will
	// overflow the uint32 when we mmap it in OpenMemtable.
	if !(opt.ValueLogFileSize < 2<<30 && opt.ValueLogFileSize >= 1<<20) {
		return ErrValueLogSize
	}

	if opt.ReadOnly {
		// Do not perform compaction in read only mode.

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Lower opt.ValueThreshold to at most 1GB (1<<30)
  2. Use the default ValueThreshold (48) unless you have a measured reason to raise it

Example fix

// before
opt.ValueThreshold = math.MaxInt64
// after
opt.ValueThreshold = 48 // or <= 1<<30
Defensive patterns

Strategy: validation

Validate before calling

if opt.ValueThreshold > 1<<30 {
    return errors.New("ValueThreshold must be <= 1GB")
}

Prevention

When it happens

Trigger: Calling badger.Open with opt.ValueThreshold set above 1<<30 (1GB), typically while trying to force all values into the LSM.

Common situations: Setting an extremely large ValueThreshold to disable vlog writes; copying a value from a tuned production config into a test.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/9f8e44853b5f505f. Report an issue: GitHub.