{"record":{"id":"07016c3d3f5e1de3","repo":"dgraph-io/badger","slug":"errnorewrite","errorCode":"ErrNoRewrite","errorMessage":"Value log GC attempt didn't result in any cleanup","messagePattern":"Value log GC attempt didn't result in any cleanup","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"errors.go","lineNumber":55,"sourceCode":"\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\n\t// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when\n\t// NamespaceOffset is non-negative.\n\tErrNamespaceMode = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.\")","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L37-L73","documentation":"ErrNoRewrite is returned by DB.RunValueLogGC when the value log garbage-collection attempt completed but no log file was rewritten, meaning nothing was actually cleaned up. Badger returns it so callers know GC found no reclaimable data rather than silently reporting success. It is a sentinel (errors.Is-comparable) error defined in errors.go.","triggerScenarios":"Calling db.RunValueLogGC(discardRatio) when the value log files have no discardable (overwritten/deleted) data above the discardRatio threshold; the GC scans a candidate log file, finds too few valid-sample rewrites, and returns without truncating.","commonSituations":"Periodic GC jobs polling frequently on a small or append-heavy workload; running GC right after opening the DB before any keys have been overwritten; calling GC repeatedly in a loop where only the first call rewrites a file (tests like db_test.go loop until ErrNoRewrite).","solutions":["Treat ErrNoRewrite as a normal stop signal, not a failure: break out of your GC loop when it is returned","Reduce GC frequency or lower the discardRatio only if you genuinely expect reclaimable data","Ensure deletes/overwrites actually occur before expecting GC to reclaim space","Verify you are not retrying GC in a tight loop, which wastes I/O"],"exampleFix":"// before\nif err := db.RunValueLogGC(0.5); err != nil {\n\treturn err\n}\n// after\nif err := db.RunValueLogGC(0.5); err != nil && !errors.Is(err, ErrNoRewrite) {\n\treturn err\n}","handlingStrategy":"type-guard","validationCode":"if discardRatio <= 0.0 || discardRatio >= 1.0 { return errors.New(\"discardRatio must be in (0,1)\") }","typeGuard":"func isNoRewrite(err error) bool { return errors.Is(err, ErrNoRewrite) }","tryCatchPattern":"if err := db.RunValueLogGC(0.5); err != nil {\n\tif errors.Is(err, ErrNoRewrite) {\n\t\treturn nil // nothing to collect\n\t}\n\treturn err\n}","preventionTips":["Always compare with errors.Is(err, ErrNoRewrite) before treating a GC error as fatal","Loop GC until ErrNoRewrite instead of fixed iteration counts","Only schedule GC when writes/deletes have occurred since the last GC"],"tags":["badger","garbage-collection","value-log","sentinel-error"],"backgroundTag":"gc-no-cleanup","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"}