{"record":{"id":"4776f61869fa86a0","repo":"dgraph-io/badger","slug":"file-with-id-d-not-found","errorCode":null,"errorMessage":"file with ID: %d not found","messagePattern":"file with ID: (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"value.go","lineNumber":943,"sourceCode":"\t\tvlog.db.threshold.update(valueSizes)\n\t\t// We write to disk here so that all entries that are part of the same transaction are\n\t\t// written to the same vlog file.\n\t\tif err := toDisk(); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn toDisk()\n}\n\n// Gets the logFile and acquires and RLock() for the mmap. You must call RUnlock on the file\n// (if non-nil)\nfunc (vlog *valueLog) getFileRLocked(vp valuePointer) (*logFile, error) {\n\tvlog.filesLock.RLock()\n\tdefer vlog.filesLock.RUnlock()\n\tret, ok := vlog.filesMap[vp.Fid]\n\tif !ok {\n\t\t// log file has gone away, we can't do anything. Return.\n\t\treturn nil, fmt.Errorf(\"file with ID: %d not found\", vp.Fid)\n\t}\n\n\t// Check for valid offset if we are reading from writable log.\n\tmaxFid := vlog.maxFid\n\t// In read-only mode we don't need to check for writable offset as we are not writing anything.\n\t// Moreover, this offset is not set in readonly mode.\n\tif !vlog.opt.ReadOnly && vp.Fid == maxFid {\n\t\tcurrentOffset := vlog.woffset()\n\t\tif vp.Offset >= currentOffset {\n\t\t\treturn nil, fmt.Errorf(\n\t\t\t\t\"Invalid value pointer offset: %d greater than current offset: %d\",\n\t\t\t\tvp.Offset, currentOffset)\n\t\t}\n\t}\n\n\tret.lock.RLock()\n\treturn ret, nil\n}","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/value.go#L925-L961","documentation":"getFileRLocked looks up the value log file matching the value pointer's file ID (vp.Fid) in vlog.filesMap and returns this error when there is no such entry. It means the vlog file a key's valuePointer references is no longer known to this DB instance — deleted, never loaded, or the pointer is stale. Badger does not retry; it returns the error to the caller.","triggerScenarios":"Reading a key whose valuePointer references a FID that was garbage-collected, a valuePointer from a different DB directory, stale SST entries after a crash where vlog files were lost, or manual deletion of *.vlog files.","commonSituations":"Restoring only SSTs but not all vlogs from backup; deleting vlog files to reclaim space; mixing data directories across instances; crash where vlogs lived on a failed disk but the LSM survived.","solutions":["Ensure all value log files present at write time remain in the DB directory — never delete vlogs manually; let badger's GC manage them.","Restore the complete DB directory (SSTs AND vlogs together) rather than a partial copy.","If pointers are stale but data exists elsewhere, iterate-and-rewrite affected keys so valuePointers move to current files.","If files are unrecoverable, rebuild via Stream/Backup into a fresh DB — the referenced values are gone.","Confirm you opened the same directory the data was written to (correct dir paths, no volume mix-ups)."],"exampleFix":"// before: deleting old vlog files to free space\n$ rm /data/badger/000001.vlog\n// later: read fails: file with ID: 1 not found\n// after: use badger's own GC\nif err := db.RunValueLogGC(0.5); err != nil { /* handle */ }\n// and restore full backups: include *.vlog and *.sst","handlingStrategy":"fallback","validationCode":"// Go: sanity-check a valuePointer's file is known before reading\nfunc vpFileKnown(vp badger.ValuePointer, known map[uint32]struct{}) bool {\n    _, ok := known[vp.Fid]\n    return ok\n}","typeGuard":"func isFileNotFoundErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"file with ID\") &&\n        strings.Contains(err.Error(), \"not found\")\n}","tryCatchPattern":"item, err := txn.Get(key)\nif err != nil && isFileNotFoundErr(err) {\n    // the value's vlog file is gone; treat as missing and regenerate\n    log.Printf(\"stale value pointer for %s: %v\", key, err)\n    return regenerateValue(key)\n}","preventionTips":["Never delete *.vlog files manually; use db.RunValueLogGC.","Back up SSTs and vlogs together from the same checkpoint.","Open the exact directory the data was written to.","After restoring partial data, rewrite affected keys to refresh valuePointers."],"tags":["badger","value-log","stale-pointer","data-loss"],"backgroundTag":"vlog-file-not-found","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"}