{"record":{"id":"16a1f306b49561e3","repo":"dgraph-io/badger","slug":"unable-to-parse-log-id-16a1f3","errorCode":null,"errorMessage":"Unable to parse log id.","messagePattern":"Unable to parse log id\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"memtable.go","lineNumber":61,"sourceCode":"func (db *DB) openMemTables(opt Options) error {\n\t// We don't need to open any tables in in-memory mode.\n\tif db.opt.InMemory {\n\t\treturn nil\n\t}\n\tfiles, err := os.ReadDir(db.opt.Dir)\n\tif err != nil {\n\t\treturn errFile(err, db.opt.Dir, \"Unable to open mem dir.\")\n\t}\n\n\tvar fids []int\n\tfor _, file := range files {\n\t\tif !strings.HasSuffix(file.Name(), memFileExt) {\n\t\t\tcontinue\n\t\t}\n\t\tfsz := len(file.Name())\n\t\tfid, err := strconv.ParseInt(file.Name()[:fsz-len(memFileExt)], 10, 64)\n\t\tif err != nil {\n\t\t\treturn errFile(err, file.Name(), \"Unable to parse log id.\")\n\t\t}\n\t\tfids = append(fids, int(fid))\n\t}\n\n\t// Sort in ascending order.\n\tsort.Slice(fids, func(i, j int) bool {\n\t\treturn fids[i] < fids[j]\n\t})\n\tfor _, fid := range fids {\n\t\tflags := os.O_RDWR\n\t\tif db.opt.ReadOnly {\n\t\t\tflags = os.O_RDONLY\n\t\t}\n\t\tmt, err := db.openMemTable(fid, flags)\n\t\tif err != nil {\n\t\t\treturn y.Wrapf(err, \"while opening fid: %d\", fid)\n\t\t}\n\t\t// If this memtable is empty we don't need to add it. This is a","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/memtable.go#L43-L79","documentation":"openMemTables scans the badger directory for memtable WAL files (named '%05d.clog'-style with a numeric id). This error wraps a strconv.ParseInt failure when the filename prefix before the memtable extension is not a valid base-10 integer, meaning a stray or corrupt file matching the memtable extension exists in the DB directory.","triggerScenarios":"Opening a DB (badger.Open) whose directory contains a file ending in the memtable extension whose name prefix is not a numeric id, e.g. a truncated/partially-written file, a manually renamed file, or leftover temp data.","commonSituations":"Manual file manipulation or backup-restore of the badger directory; disk-full crashes leaving partial files; copying files from another instance; a crash during memtable creation that left a misnamed file.","solutions":["List files in the DB directory with the memtable extension and inspect their names; remove or rename any file whose prefix is not a 5+ digit numeric id","Only open badger on directories it created; restore from backup instead of hand-editing files","Check disk space and filesystem health; ensure the process is not killed mid-write (use clean shutdown)","If the file is a leftover WAL of no value and you can afford data loss in the memtable (not flushed to LSM), remove it and reopen"],"exampleFix":"// before: directory contains 'badger-key-registry.clog' style stray file\n// after\n//   ls opt.Dir\n//   000000.clog  000001.clog  MANIFEST  KEYREGISTRY\n//   rm stray-file.clog   # only if it is not a valid numeric-id memtable file","handlingStrategy":"validation","validationCode":"files, err := os.ReadDir(dbDir)\nif err != nil { return err }\nfor _, f := range files {\n    if !strings.HasSuffix(f.Name(), memFileExt) { continue }\n    idStr := f.Name()[:len(f.Name())-len(memFileExt)]\n    if _, err := strconv.ParseInt(idStr, 10, 64); err != nil {\n        return fmt.Errorf(\"stray memtable file %q (bad id %q); move it away before opening\", f.Name(), idStr)\n    }\n}","typeGuard":"func validMemFileName(name, ext string) bool {\n    if !strings.HasSuffix(name, ext) { return false }\n    _, err := strconv.ParseInt(strings.TrimSuffix(name, ext), 10, 64)\n    return err == nil\n}","tryCatchPattern":"if err := badger.Open(opt); err != nil {\n    if strings.Contains(err.Error(), \"Unable to parse log id\") {\n        // quarantine stray files, then retry once\n        return quarantineStrayFiles(opt.Dir)\n    }\n    return err\n}","preventionTips":["Never manually create/rename files in the badger directory","Use backup/restore APIs instead of copying subsets of files","Monitor disk-full and clean shutdowns; crashes can leave partial files","Alert on any file in the DB dir not matching expected naming patterns"],"tags":["badger","storage","corrupt-file","startup"],"backgroundTag":"memtable-log-id-parse-failure","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"}