{"record":{"id":"9fd4a8f61ce26b71","repo":"dgraph-io/badger","slug":"file-does-not-exist-for-table-d","errorCode":null,"errorMessage":"file does not exist for table %d","messagePattern":"file does not exist for table (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"levels.go","lineNumber":51,"sourceCode":"type levelsController struct {\n\tnextFileID atomic.Uint64\n\tl0stallsMs atomic.Int64\n\n\t// The following are initialized once and const.\n\tlevels []*levelHandler\n\tkv     *DB\n\n\tcstatus compactStatus\n}\n\n// revertToManifest checks that all necessary table files exist and removes all table files not\n// referenced by the manifest. idMap is a set of table file id's that were read from the directory\n// listing.\nfunc revertToManifest(kv *DB, mf *Manifest, idMap map[uint64]struct{}) error {\n\t// 1. Check all files in manifest exist.\n\tfor id := range mf.Tables {\n\t\tif _, ok := idMap[id]; !ok {\n\t\t\treturn fmt.Errorf(\"file does not exist for table %d\", id)\n\t\t}\n\t}\n\n\t// 2. Delete files that shouldn't exist.\n\tfor id := range idMap {\n\t\tif _, ok := mf.Tables[id]; !ok {\n\t\t\tkv.opt.Debugf(\"Table file %d not referenced in MANIFEST\\n\", id)\n\t\t\tfilename := table.NewFilename(id, kv.opt.Dir)\n\t\t\tif err := os.Remove(filename); err != nil {\n\t\t\t\treturn y.Wrapf(err, \"While removing table %d\", id)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc newLevelsController(db *DB, mf *Manifest) (*levelsController, error) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/levels.go#L33-L69","documentation":"During DB recovery, revertToManifest cross-checks the MANIFEST file against the actual table files in the directory. If the manifest references a table ID that no longer exists on disk, badger refuses to silently drop it and returns this error, because proceeding could lose committed data.","triggerScenarios":"Opening a badger DB whose directory is missing SSTable files listed in MANIFEST — e.g. someone deleted *.vlog/*.sst files, copied only part of the directory, or a crash left the manifest ahead of the files.","commonSituations":"Incomplete backup/restore of the badger directory; manually cleaning up disk space by deleting table files; filesystem corruption or interrupted copy; running against a directory restored with rsync excluding some files.","solutions":["Restore the missing table files from a backup so the directory matches the manifest","If data loss is acceptable, back up the directory and repair the MANIFEST (remove the dangling table entries) or start from the last good backup","Never mix files from two different DB directories; copy the whole directory atomically","Run badger info on the directory to see which files/manifest entries are inconsistent"],"exampleFix":"# before: directory missing 003.sst referenced by MANIFEST -> open fails\n# after: restore full directory from backup\naws s3 cp s3://my-backup/badger/ ./data/badger/ --recursive  # ensure ALL .sst files restored\nbadger info --dir ./data/badger  # verify consistency before opening","handlingStrategy":"validation","validationCode":"# shell: verify directory consistency before opening\nbadger info --dir ./data/badger\nls ./data/badger/*.sst | wc -l  # compare against manifest table count","typeGuard":null,"tryCatchPattern":"// Go\ndb, err := badger.Open(opts)\nif err != nil && strings.Contains(err.Error(), \"file does not exist for table\") {\n    // stop and restore from backup; do not delete files blindly\n    return fmt.Errorf(\"corrupt/incomplete badger dir: %w\", err)\n}","preventionTips":["Copy badger directories only while the DB is closed, and copy everything (MANIFEST + all .sst/.vlog)","Take atomic snapshots/backups","Never delete .sst files manually to free space","Run badger info after restore and before open"],"tags":["manifest","recovery","data-loss"],"backgroundTag":"manifest-table-file-missing","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"}