{"record":{"id":"9160983ddcf7673b","repo":"dgraph-io/badger","slug":"errthresholdzero","errorCode":"ErrThresholdZero","errorMessage":"Value log GC can't run because threshold is set to zero","messagePattern":"Value log GC can't run because threshold is set to zero","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":51,"sourceCode":"\t// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.\n\tErrReadOnlyTxn = stderrors.New(\"No sets or deletes are allowed in a read-only transaction\")\n\n\t// ErrDiscardedTxn is returned if a previously discarded transaction is reused.\n\tErrDiscardedTxn = stderrors.New(\"This transaction has been discarded. Create a new one\")\n\n\t// ErrEmptyKey is returned if an empty key is passed on an update function.\n\tErrEmptyKey = stderrors.New(\"Key cannot be empty\")\n\n\t// ErrInvalidKey is returned if the key has a special !badger! prefix,\n\t// reserved for internal usage.\n\tErrInvalidKey = stderrors.New(\"Key is using a reserved !badger! prefix\")\n\n\t// ErrBannedKey is returned if the read/write key belongs to any banned namespace.\n\tErrBannedKey = stderrors.New(\"Key is using the banned prefix\")\n\n\t// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.\n\t// In such a case, GC can't be run.\n\tErrThresholdZero = stderrors.New(\n\t\t\"Value log GC can't run because threshold is set to zero\")\n\n\t// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.\n\tErrNoRewrite = stderrors.New(\n\t\t\"Value log GC attempt didn't result in any cleanup\")\n\n\t// ErrRejected is returned if a value log GC is called either while another GC is running, or\n\t// after DB::Close has been called.\n\tErrRejected = stderrors.New(\"Value log GC request rejected\")\n\n\t// ErrInvalidRequest is returned if the user request is invalid.\n\tErrInvalidRequest = stderrors.New(\"Invalid request\")\n\n\t// ErrManagedTxn is returned if the user tries to use an API which isn't\n\t// allowed due to external management of transactions, when using ManagedDB.\n\tErrManagedTxn = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action using ManagedDB\")\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L33-L69","documentation":"ErrThresholdZero is returned by value log GC APIs (db.RunValueLogGC) when the GC threshold option is zero. With a zero threshold the GC cannot decide which files are candidates, so Badger refuses to run it (errors.go:51).","triggerScenarios":"Calling db.RunValueLogGC(0) on a DB opened with WithCheckpointerMode/WithGC-related options where the discard/GC threshold (e.g. opt.CheckpointerOptions or vlog GC threshold) is 0; in modern Badger, RunValueLogGC(percent) with percentage < 1 behaves as a zero threshold.","commonSituations":"Operators running GC against a DB configured with thresholds disabled, or passing 0 as the rewrite percentage by mistake.","solutions":["Call db.RunValueLogGC with a valid percentage in (0, 100), e.g. 0.5 for 50% discardable space","Open the DB with a non-zero GC threshold option if GC is part of your maintenance routine","Skip manual vlog GC and rely on automatic vlog GC (default in newer Badger)"],"exampleFix":"// before\nerr := db.RunValueLogGC(0) // ErrThresholdZero\n// after\nerr := db.RunValueLogGC(0.5) // rewrite when >50% of the file is discardable","handlingStrategy":"validation","validationCode":"if gcPercent <= 0 || gcPercent >= 100 {\n    return errors.New(\"RunValueLogGC needs a percent in (0, 100)\")\n}","typeGuard":null,"tryCatchPattern":"if err := db.RunValueLogGC(pct); err != nil {\n    if errors.Is(err, badger.ErrThresholdZero) {\n        return fmt.Errorf(\"enable a non-zero GC threshold before running vlog GC\")\n    }\n    return err\n}","preventionTips":["Pass a valid discard percentage (e.g. 0.5) to RunValueLogGC","Open the DB with non-zero GC threshold options if GC is scheduled","Prefer Badger's automatic vlog GC over manual maintenance scripts"],"tags":["badger","garbage-collection","configuration","storage"],"backgroundTag":"gc-threshold-zero","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"}