{"record":{"id":"a1441c6cd89d31e3","repo":"dgraph-io/badger","slug":"s-path-s-error-v","errorCode":null,"errorMessage":"%s. Path=%s. Error=%v","messagePattern":"(.+?)\\. Path=(.+?)\\. Error=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"value.go","lineNumber":556,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tvlog.filesLock.Lock()\n\tvlog.filesMap[fid] = lf\n\ty.AssertTrue(vlog.maxFid < fid)\n\tvlog.maxFid = fid\n\t// writableLogOffset is only written by write func, by read by Read func.\n\t// To avoid a race condition, all reads and updates to this variable must be\n\t// done via atomics.\n\tvlog.writableLogOffset.Store(vlogHeaderSize)\n\tvlog.numEntriesWritten = 0\n\tvlog.filesLock.Unlock()\n\n\treturn lf, nil\n}\n\nfunc errFile(err error, path string, msg string) error {\n\treturn fmt.Errorf(\"%s. Path=%s. Error=%v\", msg, path, err)\n}\n\n// init initializes the value log struct. This initialization needs to happen\n// before compactions start.\nfunc (vlog *valueLog) init(db *DB) {\n\tvlog.opt = db.opt\n\tvlog.db = db\n\t// We don't need to open any vlog files or collect stats for GC if DB is opened\n\t// in InMemory mode. InMemory mode doesn't create any files/directories on disk.\n\tif vlog.opt.InMemory {\n\t\treturn\n\t}\n\tvlog.dirPath = vlog.opt.ValueDir\n\n\tif vlog.opt.ReadOnly {\n\t\treturn\n\t}\n","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/value.go#L538-L574","documentation":"errFile is badger's helper that wraps an underlying error with a message, the value log file path involved, and the original error. It is used when operations on a vlog file (open, iterate, populating the files map) fail so the developer can tell WHICH file caused the failure. The root cause (os.PathError, syscall errors, corruption) is preserved via %v and can be inspected from the error string.","triggerScenarios":"Any failure while opening or iterating a value log file: DB.Open with a corrupted/unreadable *.vlog file, insufficient file descriptors, wrong permissions on the badger directory, a vlog file deleted or truncated while the DB runs, or disk I/O errors during replay.","commonSituations":"Restoring a badger directory from partial backups; running with ulimit -n too low so os.Open fails; read-only filesystem mounts; copying DB files while badger was running; disk full or hardware errors during vlog replay.","solutions":["Read the wrapped Error= text to find the root cause (permission denied, too many open files, no such file) and fix that condition.","Raise ulimit -n (e.g. 65536) and ensure the badger directory and *.vlog files are readable/writable by the process user.","Verify vlog files are intact and fully copied — never copy a live badger directory; stop the DB or use DB.Backup/DB.Load.","If the file is genuinely corrupted, restore from backup or, accepting data loss, move the bad vlog file aside and reopen.","Check disk space (df -h) and dmesg for underlying I/O errors."],"exampleFix":"// before: copying a live DB directory then opening it\n$ cp -r /var/lib/badger /backup && reopen /backup\n// Error: ... Path=/backup/000001.vlog. Error=file truncated\n// after: stop badger (or use backup API) before copying\nerr := db.Backup(w, 0)\n// or: shutdown badger, rsync --archive the directory, then open","handlingStrategy":"try-catch","validationCode":"// Go: pre-flight checks before opening badger\nfunc checkVlogDir(dir string) error {\n    fi, err := os.Stat(dir)\n    if err != nil {\n        return err\n    }\n    if !fi.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", dir)\n    }\n    f, err := os.OpenFile(dir, os.O_RDWR, 0o700)\n    if err != nil {\n        return err\n    }\n    return f.Close()\n}","typeGuard":"func isVlogFileError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \". Path=\")\n}","tryCatchPattern":"if err := db.Open(opt); err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) {\n        log.Printf(\"vlog file %s: %v — check perms/fd limits\", perr.Path, perr.Err)\n    }\n    return fmt.Errorf(\"badger open failed: %w\", err)\n}","preventionTips":["Keep ulimit -n well above the number of vlog files (e.g. 65536).","Never copy/rsync a live badger directory; stop the DB or use DB.Backup.","Ensure the process user owns the badger dir with read/write permissions.","Monitor disk space and device health before reopening."],"tags":["storage","badger","value-log","file-io"],"backgroundTag":"vlog-file-open-failed","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"}