{"record":{"id":"7c7875eca29a434c","repo":"dgraph-io/badger","slug":"error-opening-table-s-v-s","errorCode":null,"errorMessage":"error opening table %s: %v\n%s","messagePattern":"error opening table (.+?): (.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"levels.go","lineNumber":124,"sourceCode":"\t\tfname := table.NewFilename(fileID, db.opt.Dir)\n\t\tselect {\n\t\tcase <-tick.C:\n\t\t\tdb.opt.Infof(\"%d tables out of %d opened in %s\\n\", numOpened.Load(),\n\t\t\t\tlen(mf.Tables), time.Since(start).Round(time.Millisecond))\n\t\tdefault:\n\t\t}\n\t\tif err := throttle.Do(); err != nil {\n\t\t\tcloseAllTables(tables)\n\t\t\treturn nil, err\n\t\t}\n\t\tif fileID > maxFileID {\n\t\t\tmaxFileID = fileID\n\t\t}\n\t\tgo func(fname string, tf TableManifest) {\n\t\t\tvar rerr error\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\trerr = fmt.Errorf(\"error opening table %s: %v\\n%s\", fname, r, debug.Stack())\n\t\t\t\t}\n\t\t\t\tthrottle.Done(rerr)\n\t\t\t\tnumOpened.Add(1)\n\t\t\t}()\n\t\t\t// tables is sized by opt.MaxLevels, and nothing upstream constrains\n\t\t\t// the level recorded in the manifest, so reject an out-of-range level\n\t\t\t// here rather than letting the append below panic.\n\t\t\tif int(tf.Level) >= len(tables) {\n\t\t\t\trerr = fmt.Errorf(\n\t\t\t\t\t\"manifest records table %s at level %d, but MaxLevels is %d\",\n\t\t\t\t\tfname, tf.Level, len(tables))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdk, err := db.registry.DataKey(tf.KeyID)\n\t\t\tif err != nil {\n\t\t\t\trerr = y.Wrapf(err, \"Error while reading datakey\")\n\t\t\t\treturn\n\t\t\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/levels.go#L106-L142","documentation":"When opening a DB, badger opens all manifest-listed tables concurrently in goroutines; any panic or error while opening a table is captured and returned as this wrapped error including the file name, panic value, and a stack trace. It indicates a corrupt or unreadable SSTable.","triggerScenarios":"A panic occurs while loading a table file (corrupt SSTable, truncated file, checksum failure, incompatible encryption/registry key, or out-of-range level in a patched build).","commonSituations":"Corrupted table files after a machine crash or power loss; copying the DB directory while badger was running; restoring files encrypted with a different key; mixing table files across badger versions.","solutions":["Inspect and drop/repair the specific corrupt table reported in the error (badger's DropAll/repair tooling or badger info)","Restore the table file from backup","Verify encryption/DataKey registry matches the one used when the tables were written","Ensure the DB directory is copied while the DB is closed"],"exampleFix":"// before\nbadger.Open(opts) // fails: error opening table 005.sst: checksum mismatch\n// after\ndefOpts := badger.DefaultOptions(\"./data/badger\")\ndefOpts.ReadOnly = true // open read-only to inspect/repair\n// then remove or replace the corrupt table file listed in the error before normal open","handlingStrategy":"try-catch","validationCode":"// Go: pre-check files exist and are non-zero before open\nfor _, f := range manifestTables {\n    fi, err := os.Stat(filepath.Join(dir, keyIDToFile(f)))\n    if err != nil || fi.Size() == 0 { return fmt.Errorf(\"table missing/empty: %v\", err) }\n}","typeGuard":null,"tryCatchPattern":"// Go\ndb, err := badger.Open(opts)\nif err != nil {\n    var stackHint = \"error opening table\"\n    if strings.Contains(err.Error(), stackHint) {\n        // parse fname from error, quarantine/restore that file, then retry\n        return quarantineAndRetry(err)\n    }\n    return err\n}","preventionTips":["Never copy or rsync the badger dir while it is open","Keep the encryption key/registry consistent with the data files","Restore from backup rather than editing corrupt SSTables","Monitor disk health; corruption often follows crashes/power loss"],"tags":["corruption","sstable","recovery"],"backgroundTag":"table-open-panic","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"}