dgraph-io/badger · error
vlogPercentile must be within range of 0.0-1.0
Error message
vlogPercentile must be within range of 0.0-1.0
What it means
badger.Option VLogPercentile controls the fraction of writes routed to the value log via percentile-based dynamic thresholding. Open() rejects the options before starting the DB if the value is outside the valid [0.0, 1.0] range, since it is interpreted as a probability.
Source
Thrown at db.go:160
func checkAndSetOptions(opt *Options) error {
// It's okay to have zero compactors which will disable all compactions but
// we cannot have just one compactor otherwise we will end up with all data
// on level 2.
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) {View on GitHub (pinned to 2a001d466f)
Solutions
- Set VLogPercentile to a value in [0.0, 1.0]
- If your config stores percentages, divide by 100 before assigning
- Omit VLogPercentile to use the default of 0.1
Example fix
// before opt.VLogPercentile = cfg.VlogPercentile // e.g. 90 from config // after opt.VLogPercentile = cfg.VlogPercentile / 100.0
Defensive patterns
Strategy: validation
Validate before calling
p := opt.VLogPercentile
if p < 0.0 || p > 1.0 {
return fmt.Errorf("vlogPercentile %v out of [0,1]", p)
} Prevention
- Keep percentages out of config; store fractions
- Clamp: opt.VLogPercentile = math.Min(1.0, math.Max(0.0, p))
- Unit-test option construction
When it happens
Trigger: Calling badger.Open (or OpenSync/OpenManaged) with opt.VLogPercentile set to a negative number or a value greater than 1.0, e.g. 1.5 or -0.1 from a config file parsed as a percentage.
Common situations: Loading a percentage value (0-100) from config instead of a fraction; sign errors; naive math like value/100 applied twice.
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
- Invalid ValueThreshold, must be less or equal to %d
- Valuethreshold %d greater than max batch size of %d. Either
- ErrEmptyKey
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/bac908ce90f3f591.
Report an issue: GitHub.