{"record":{"id":"2bf15653e93c4480","repo":"benbjohnson/litestream","slug":"remove-ltx-directory-w","errorCode":null,"errorMessage":"remove ltx directory: %w","messagePattern":"remove ltx directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":532,"sourceCode":"\tdb.metaPath = path\n}\n\n// LTXDir returns path of the root LTX directory.\nfunc (db *DB) LTXDir() string {\n\treturn filepath.Join(db.metaPath, \"ltx\")\n}\n\n// ResetLocalState removes local LTX files, forcing a fresh snapshot on next sync.\n// This is useful for recovering from corrupted or missing LTX files.\n// The database file itself is not modified.\nfunc (db *DB) ResetLocalState(ctx context.Context) error {\n\tdb.Logger.Info(\"resetting local litestream state\",\n\t\t\"meta_path\", db.metaPath,\n\t\t\"ltx_dir\", db.LTXDir())\n\n\t// Remove all LTX files\n\tif err := os.RemoveAll(db.LTXDir()); err != nil && !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"remove ltx directory: %w\", err)\n\t}\n\n\t// Clear cached LTX file info\n\tdb.maxLTXFileInfos.Lock()\n\tdb.maxLTXFileInfos.m = make(map[int]*ltx.FileInfo)\n\tdb.maxLTXFileInfos.Unlock()\n\n\tdb.invalidatePosCache()\n\n\tdb.Logger.Info(\"local state reset complete, next sync will create fresh snapshot\")\n\treturn nil\n}\n\n// LTXLevelDir returns path of the given LTX compaction level.\n// Panics if level is negative.\nfunc (db *DB) LTXLevelDir(level int) string {\n\treturn filepath.Join(db.LTXDir(), strconv.Itoa(level))\n}","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/db.go#L514-L550","documentation":"Raised during local state reset (litestream reset / DB reset path) when os.RemoveAll on the database's LTX directory fails with an error other than not-exist. The wrapper is 'remove ltx directory: %w'. Reset aborts so a half-deleted local state is never silently reused.","triggerScenarios":"Calling the DB reset path (db.go reset) while db.LTXDir() cannot be removed — filesystem permission denied, directory busy (open file handles by a running litestream process), read-only mount, or I/O error.","commonSituations":"Running reset as a user without ownership of /var/lib/litestream; litestream daemon still running and holding files open; container with read-only data volume; NFS/ephemeral storage I/O failures.","solutions":["Stop the litestream process before resetting so no files are held open","Fix permissions/ownership on the LTX directory (chown/chmod) or run reset as the same user as litestream","Ensure the volume is writable (not read-only mount)","Remove the directory manually as root, then retry","Confirm the path from 'meta_path'/'ltx_dir' in the preceding log line points where you expect"],"exampleFix":"// before: reset while daemon holds handles\n$ litestream reset /var/lib/db\n// remove ltx directory: unlinkat /var/lib/db/ltx: device or resource busy\n// after: stop first, then reset\n$ systemctl stop litestream\n$ litestream reset /var/lib/db\n$ systemctl start litestream","handlingStrategy":"validation","validationCode":"// Check writability and that no process holds the dir before reset\ntest := filepath.Join(ltxDir, \".probe\")\nif err := os.WriteFile(test, nil, 0o600); err != nil {\n    return fmt.Errorf(\"ltx dir not writable: %w\", err)\n}\nos.Remove(test)\n// also: pgrep litestream must return nothing","typeGuard":null,"tryCatchPattern":"if err := resetDB(dbPath); err != nil {\n    if errors.Is(err, os.ErrPermission) {\n        // advise running as the litestream user\n    }\n    return err\n}","preventionTips":["Stop the litestream daemon before resetting","Run reset as the same OS user that owns the meta/LTX dirs","Use writable volumes for the litestream data path"],"tags":["filesystem","permissions","reset","local-state"],"backgroundTag":"file-delete-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}