{"record":{"id":"b2dadb27fc21db56","repo":"apache/cassandra","slug":"failed-to-delete","errorCode":null,"errorMessage":"Failed to delete {}","messagePattern":"Failed to delete (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cache/AutoSavingCache.java","lineNumber":453,"sourceCode":"\n        private void deleteOldCacheFiles()\n        {\n            File savedCachesDir = new File(DatabaseDescriptor.getSavedCachesLocation());\n            assert savedCachesDir.exists() && savedCachesDir.isDirectory();\n            File[] files = savedCachesDir.tryList();\n            if (files != null)\n            {\n                String cacheNameFormat = String.format(\"%s-%s.db\", cacheType.toString(), CURRENT_VERSION);\n                for (File file : files)\n                {\n                    if (!file.isFile())\n                        continue; // someone's been messing with our directory.  naughty!\n\n                    if (file.name().endsWith(cacheNameFormat)\n                     || file.name().endsWith(cacheType.toString()))\n                    {\n                        if (!file.tryDelete())\n                            logger.warn(\"Failed to delete {}\", file.absolutePath());\n                    }\n                }\n            }\n            else\n            {\n                logger.warn(\"Could not list files in {}\", savedCachesDir);\n            }\n        }\n\n        public boolean isGlobal()\n        {\n            return false;\n        }\n    }\n\n    /**\n     * A base cache serializer that is used to serialize/deserialize a cache to/from disk.\n     * <p>","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cache/AutoSavingCache.java#L435-L471","documentation":"When saving a cache (key cache / row cache), AutoSavingCache.deleteOldCacheFiles cleans up stale files in the saved_caches directory that match this cache's name or type. If File.tryDelete() fails to unlink such a file, this warning is logged and the cleaner continues. Stale file remains on disk but cache save/load still proceeds.","triggerScenarios":"A file in saved_caches whose name ends with the cache's name format or cache type cannot be deleted — typically because the file is open by another process, or the Cassandra process lacks write/remove permission on the directory/file.","commonSituations":"Running Cassandra as a different user after a manual start (root-created files left behind); backup agents or file watchers holding files open; read-only or full filesystem; NFS-mounted saved_caches directories.","solutions":["Stop Cassandra and manually delete stale files in the saved_caches directory (they are disposable caches, safe to remove while the node is down).","Fix ownership/permissions: chown -R cassandra:cassandra /var/lib/cassandra/saved_caches.","Check disk space and mount status (df -h, mount) — a full or read-only filesystem makes unlink fail.","Ensure no external processes (backups, antivirus) hold those files open when Cassandra runs."],"exampleFix":"// before (bash): fix leftover root-owned cache files\nsudo rm -f /var/lib/cassandra/saved_caches/*\nsudo chown -R cassandra:cassandra /var/lib/cassandra/saved_caches","handlingStrategy":"fallback","validationCode":"// Pre-flight check on deployment (bash)\ntest -w /var/lib/cassandra/saved_caches || echo \"saved_caches not writable by $(id -un)\"\nfind /var/lib/cassandra/saved_caches ! -user cassandra -ls  # detect foreign-owned files","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always start Cassandra under the same service user; clean up after manual/root runs.","Exclude saved_caches from backup tools that hold files open.","Keep the cache directory on a local, writable volume (not NFS).","Manually clear saved_caches during planned restarts if warnings accumulate."],"tags":["cache","filesystem","cleanup","permissions"],"backgroundTag":"file-delete-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}