dgraph-io/badger · error
Invalid filename: %s
Error message
Invalid filename: %s
What it means
OpenTable derives the table ID from the mmap'd file's base name via ParseFileID. If the filename doesn't contain a parseable table ID (the expected 'NNNNNN.sst' / table-number format), OpenTable closes the file and returns 'Invalid filename: <name>'.
Source
Thrown at table/table.go:285
// deleting. Checksum for all blocks of table is verified based on value of chkMode.
func OpenTable(mf *z.MmapFile, opts Options) (*Table, error) {
// BlockSize is used to compute the approximate size of the decompressed
// block. It should not be zero if the table is compressed.
if opts.BlockSize == 0 && opts.Compression != options.None {
_ = mf.Close(-1)
return nil, errors.New("Block size cannot be zero")
}
fileInfo, err := mf.Fd.Stat()
if err != nil {
mf.Close(-1)
return nil, y.Wrap(err, "")
}
filename := fileInfo.Name()
id, ok := ParseFileID(filename)
if !ok {
mf.Close(-1)
return nil, fmt.Errorf("Invalid filename: %s", filename)
}
t := &Table{
MmapFile: mf,
id: id,
opt: &opts,
IsInmemory: false,
tableSize: int(fileInfo.Size()),
CreatedAt: fileInfo.ModTime(),
}
// Caller is given one reference.
t.ref.Store(1)
if err := t.initBiggestAndSmallest(); err != nil {
_ = mf.Close(-1)
return nil, y.Wrapf(err, "failed to initialize table")
}
if opts.ChkMode == options.OnTableRead || opts.ChkMode == options.OnTableAndBlockRead {View on GitHub (pinned to 2a001d466f)
Solutions
- Ensure the file name matches badger's table naming scheme (numeric ID + table extension) before calling OpenTable; only pass files matched by the table-id regex/glob
- Rename the file back to its valid form (e.g. 000001.sst) if it was renamed for backup
- Filter directory listings using table.ParseFileID or the table file pattern before constructing tables
- Open the DB through badger.Open so only valid table files are opened
Example fix
// before
mf, err := z.OpenMmapFile("000001.sst.bak", ...) // invalid name
tbl, err := table.OpenTable(mf, opts)
// after
id, ok := table.ParseFileID("000001.sst")
if !ok { return fmt.Errorf("not a table file") }
tbl, err := table.OpenTable(mf, opts) Defensive patterns
Strategy: validation
Validate before calling
if _, ok := table.ParseFileID(filepath.Base(path)); !ok {
return nil, fmt.Errorf("%s is not a badger table file", path)
} Type guard
func isTableFile(name string) bool {
_, ok := table.ParseFileID(name)
return ok
} Try / catch
tbl, err := table.OpenTable(mf, opts)
if err != nil {
if strings.HasPrefix(err.Error(), "Invalid filename:") {
_ = mf.Close(-1) // not a table file; skip it
return nil, err
}
return nil, err
} Prevention
- Filter directory entries with ParseFileID (or the *.sst pattern) before opening as tables
- Never rename table files; if you must copy them, restore the exact original name
- Skip temp/lock/vlog files when scanning a badger directory
- Open DBs through badger.Open rather than manually opening mmap files
When it happens
Trigger: Opening a mmap'd file that is not a badger table file — e.g. keylog/vlog files, temp files, lock files, files with unusual suffixes, or renamed tables — by passing it to OpenTable; pointing OpenTable at a file copied with a modified name (e.g. '000001.sst.bak' or 'table1.sst').
Common situations: Iterating a directory and opening every mmap-able file as a table instead of filtering *.sst; renaming or copying table files for backup/inspection with extra extensions; hand-edited or corrupted filenames; running OpenTable on files from a different badger component.
Related errors
- Cannot find directory %q for read-only open
- Unable to open log dir.
- Unable to parse log id.
- Unable to open mem dir.
- ERROR: Invalid badger.compression argument
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/81b6ceded657015d.
Report an issue: GitHub.