{"record":{"id":"bac908ce90f3f591","repo":"dgraph-io/badger","slug":"vlogpercentile-must-be-within-range-of-0-0-1-0","errorCode":null,"errorMessage":"vlogPercentile must be within range of 0.0-1.0","messagePattern":"vlogPercentile must be within range of 0\\.0-1\\.0","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":160,"sourceCode":"\nfunc checkAndSetOptions(opt *Options) error {\n\t// It's okay to have zero compactors which will disable all compactions but\n\t// we cannot have just one compactor otherwise we will end up with all data\n\t// on level 2.\n\tif opt.NumCompactors == 1 {\n\t\treturn errors.New(\"Cannot have 1 compactor. Need at least 2\")\n\t}\n\n\tif opt.InMemory && (opt.Dir != \"\" || opt.ValueDir != \"\") {\n\t\treturn errors.New(\"Cannot use badger in Disk-less mode with Dir or ValueDir set\")\n\t}\n\topt.maxBatchSize = (15 * opt.MemTableSize) / 100\n\topt.maxBatchCount = opt.maxBatchSize / int64(skl.MaxNodeSize)\n\n\t// This is the maximum value, vlogThreshold can have if dynamic thresholding is enabled.\n\topt.maxValueThreshold = math.Min(maxValueThreshold, float64(opt.maxBatchSize))\n\tif opt.VLogPercentile < 0.0 || opt.VLogPercentile > 1.0 {\n\t\treturn errors.New(\"vlogPercentile must be within range of 0.0-1.0\")\n\t}\n\n\t// We are limiting opt.ValueThreshold to maxValueThreshold for now.\n\tif opt.ValueThreshold > maxValueThreshold {\n\t\treturn fmt.Errorf(\"Invalid ValueThreshold, must be less or equal to %d\",\n\t\t\tmaxValueThreshold)\n\t}\n\n\t// If ValueThreshold is greater than opt.maxBatchSize, we won't be able to push any data using\n\t// the transaction APIs. Transaction batches entries into batches of size opt.maxBatchSize.\n\tif opt.ValueThreshold > opt.maxBatchSize {\n\t\treturn fmt.Errorf(\"Valuethreshold %d greater than max batch size of %d. Either \"+\n\t\t\t\"reduce opt.ValueThreshold or increase opt.BaseTableSize.\",\n\t\t\topt.ValueThreshold, opt.maxBatchSize)\n\t}\n\t// ValueLogFileSize should be strictly LESS than 2<<30 otherwise we will\n\t// overflow the uint32 when we mmap it in OpenMemtable.\n\tif !(opt.ValueLogFileSize < 2<<30 && opt.ValueLogFileSize >= 1<<20) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/db.go#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"Loading a percentage value (0-100) from config instead of a fraction; sign errors; naive math like value/100 applied twice.","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"],"exampleFix":"// before\nopt.VLogPercentile = cfg.VlogPercentile // e.g. 90 from config\n// after\nopt.VLogPercentile = cfg.VlogPercentile / 100.0","handlingStrategy":"validation","validationCode":"p := opt.VLogPercentile\nif p < 0.0 || p > 1.0 {\n    return fmt.Errorf(\"vlogPercentile %v out of [0,1]\", p)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep percentages out of config; store fractions","Clamp: opt.VLogPercentile = math.Min(1.0, math.Max(0.0, p))","Unit-test option construction"],"tags":["badger","configuration","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}