{"record":{"id":"da61246cd2bbcc58","repo":"dgraph-io/badger","slug":"valuethreshold-d-greater-than-max-batch-size-of","errorCode":null,"errorMessage":"Valuethreshold %d greater than max batch size of %d. Either reduce opt.ValueThreshold or increase opt.BaseTableSize.","messagePattern":"Valuethreshold (.+?) greater than max batch size of (.+?)\\. Either reduce opt\\.ValueThreshold or increase opt\\.BaseTableSize\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":172,"sourceCode":"\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) {\n\t\treturn ErrValueLogSize\n\t}\n\n\tif opt.ReadOnly {\n\t\t// Do not perform compaction in read only mode.\n\t\topt.CompactL0OnClose = false\n\t}\n\n\tneedCache := (opt.Compression != options.None) || (len(opt.EncryptionKey) > 0)\n\tif needCache && opt.BlockCacheSize == 0 {\n\t\tpanic(\"BlockCacheSize should be set since compression/encryption are enabled\")\n\t}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/db.go#L154-L190","documentation":"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.","triggerScenarios":"Calling badger.Open with opt.ValueThreshold greater than (15*MemTableSize)/100, e.g. a large ValueThreshold (like 1MB) combined with a small MemTableSize.","commonSituations":"Raising ValueThreshold without checking MemTableSize; shrinking BaseTableSize/MemTableSize for tests while keeping production ValueThreshold.","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"],"exampleFix":"// before\nopt.MemTableSize = 8 << 20 // 8MB, maxBatchSize ~1.2MB\nopt.ValueThreshold = 4 << 20 // 4MB > batch size -> error\n// after\nopt.MemTableSize = 64 << 20\nopt.ValueThreshold = 4 << 20 // now under maxBatchSize (~9.6MB)","handlingStrategy":"validation","validationCode":"maxBatch := (15 * opt.MemTableSize) / 100\nif opt.ValueThreshold > maxBatch {\n    return fmt.Errorf(\"lower ValueThreshold (<%d) or raise MemTableSize\", maxBatch)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive ValueThreshold from MemTableSize in config code","Test Open() with production options in CI","Document the 15% maxBatchSize rule next to your option setters"],"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"}