dgraph-io/badger · error
Valuethreshold %d greater than max batch size of %d. Either
Error message
Valuethreshold %d greater than max batch size of %d. Either reduce opt.ValueThreshold or increase opt.BaseTableSize.
What it means
Transaction writes are batched to at most opt.maxBatchSize bytes, which is derived from MemTableSize (15%). If ValueThreshold exceeds maxBatchSize, every large value would exceed the batch budget and transactions could never push data, so Open() fails fast.
Source
Thrown at db.go:172
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.
opt.CompactL0OnClose = false
}
needCache := (opt.Compression != options.None) || (len(opt.EncryptionKey) > 0)
if needCache && opt.BlockCacheSize == 0 {
panic("BlockCacheSize should be set since compression/encryption are enabled")
}View on GitHub (pinned to 2a001d466f)
Solutions
- Reduce opt.ValueThreshold below opt.maxBatchSize
- Increase opt.MemTableSize so that 15% of it exceeds ValueThreshold
- Follow the error's advice: reduce ValueThreshold or increase BaseTableSize
Example fix
// before opt.MemTableSize = 8 << 20 // 8MB, maxBatchSize ~1.2MB opt.ValueThreshold = 4 << 20 // 4MB > batch size -> error // after opt.MemTableSize = 64 << 20 opt.ValueThreshold = 4 << 20 // now under maxBatchSize (~9.6MB)
Defensive patterns
Strategy: validation
Validate before calling
maxBatch := (15 * opt.MemTableSize) / 100
if opt.ValueThreshold > maxBatch {
return fmt.Errorf("lower ValueThreshold (<%d) or raise MemTableSize", maxBatch)
} Prevention
- Derive ValueThreshold from MemTableSize in config code
- Test Open() with production options in CI
- Document the 15% maxBatchSize rule next to your option setters
When it happens
Trigger: Calling badger.Open with opt.ValueThreshold greater than (15*MemTableSize)/100, e.g. a large ValueThreshold (like 1MB) combined with a small MemTableSize.
Common situations: Raising ValueThreshold without checking MemTableSize; shrinking BaseTableSize/MemTableSize for tests while keeping production ValueThreshold.
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
- ErrValueLogSize
- ErrZeroBandwidth
- vlogPercentile must be within range of 0.0-1.0
- Invalid ValueThreshold, must be less or equal to %d
- ErrEmptyKey
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/da61246cd2bbcc58.
Report an issue: GitHub.