dgraph-io/badger · error
Unable to parse log id.
Error message
Unable to parse log id.
What it means
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.
Source
Thrown at memtable.go:61
func (db *DB) openMemTables(opt Options) error {
// We don't need to open any tables in in-memory mode.
if db.opt.InMemory {
return nil
}
files, err := os.ReadDir(db.opt.Dir)
if err != nil {
return errFile(err, db.opt.Dir, "Unable to open mem dir.")
}
var fids []int
for _, file := range files {
if !strings.HasSuffix(file.Name(), memFileExt) {
continue
}
fsz := len(file.Name())
fid, err := strconv.ParseInt(file.Name()[:fsz-len(memFileExt)], 10, 64)
if err != nil {
return errFile(err, file.Name(), "Unable to parse log id.")
}
fids = append(fids, int(fid))
}
// Sort in ascending order.
sort.Slice(fids, func(i, j int) bool {
return fids[i] < fids[j]
})
for _, fid := range fids {
flags := os.O_RDWR
if db.opt.ReadOnly {
flags = os.O_RDONLY
}
mt, err := db.openMemTable(fid, flags)
if err != nil {
return y.Wrapf(err, "while opening fid: %d", fid)
}
// If this memtable is empty we don't need to add it. This is aView on GitHub (pinned to 2a001d466f)
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
Example fix
// before: directory contains 'badger-key-registry.clog' style stray file // after // ls opt.Dir // 000000.clog 000001.clog MANIFEST KEYREGISTRY // rm stray-file.clog # only if it is not a valid numeric-id memtable file
Defensive patterns
Strategy: validation
Validate before calling
files, err := os.ReadDir(dbDir)
if err != nil { return err }
for _, f := range files {
if !strings.HasSuffix(f.Name(), memFileExt) { continue }
idStr := f.Name()[:len(f.Name())-len(memFileExt)]
if _, err := strconv.ParseInt(idStr, 10, 64); err != nil {
return fmt.Errorf("stray memtable file %q (bad id %q); move it away before opening", f.Name(), idStr)
}
} Type guard
func validMemFileName(name, ext string) bool {
if !strings.HasSuffix(name, ext) { return false }
_, err := strconv.ParseInt(strings.TrimSuffix(name, ext), 10, 64)
return err == nil
} Try / catch
if err := badger.Open(opt); err != nil {
if strings.Contains(err.Error(), "Unable to parse log id") {
// quarantine stray files, then retry once
return quarantineStrayFiles(opt.Dir)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- ErrValueLogSize
- ErrThresholdZero
- %s with size %d exceeded %d limit. %s: %s
- %s. Path=%s. Error=%v
- Unable to open mem dir.
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/16a1f306b49561e3.
Report an issue: GitHub.