{"record":{"id":"13c13d51b417571a","repo":"apache/cassandra","slug":"unable-to-create-directory-logdir","errorCode":null,"errorMessage":"Unable to create directory ${logDir}","messagePattern":"Unable to create directory (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/AsyncProfilerService.java","lineNumber":448,"sourceCode":"            (DatabaseDescriptor.getCDCLogLocation() != null && dir.startsWith(DatabaseDescriptor.getCDCLogLocation())) ||\n            (DatabaseDescriptor.getSavedCachesLocation() != null && dir.startsWith(DatabaseDescriptor.getSavedCachesLocation())))\n        {\n            throw new RuntimeException(\"You can not store Async-Profiler results into system Cassandra directory.\");\n        }\n\n        for (String location : StorageService.instance.getAllDataFileLocations())\n        {\n            if (dir.startsWith(location))\n                throw new RuntimeException(\"You can not store Async-Profiler results into a data directory of Cassandra.\");\n        }\n\n        try\n        {\n            new File(logDir).createDirectoriesIfNotExists();\n        }\n        catch (Throwable t)\n        {\n            throw new RuntimeException(\"Unable to create directory \" + logDir);\n        }\n    }\n\n    private void validateStartParameters(Map<String, String> parameters)\n    {\n        if (!ASYNC_PROFILER_START_PARAMS.equals(parameters.keySet()))\n        {\n            throw new IllegalArgumentException(\"Wrong parameters passed to start async profiler method. Passed parameters\" +\n                                               \" should be: \" + ASYNC_PROFILER_START_PARAMS);\n        }\n    }\n\n    private void validateStopParameters(Map<String, String> parameters)\n    {\n        if (!ASYNC_PROFILER_STOP_PARAMS.containsAll(parameters.keySet()))\n        {\n            throw new IllegalArgumentException(\"Wrong parameters passed to stop async profiler method. Passed parameters\" +\n                                               \" should be: \" + ASYNC_PROFILER_STOP_PARAMS);","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/AsyncProfilerService.java#L430-L466","documentation":"After validating the log directory location, maybeCreateProfilesLogDir attempts to create it (createDirectoriesIfNotExists). If that filesystem operation fails for any reason (permissions, read-only volume, path is a file), the original cause is discarded and a RuntimeException with the log dir path is thrown, so callers can see which directory could not be created.","triggerScenarios":"Profiling MBean calls (instance/apply/list/fetch/purge) when the configured log dir cannot be created: parent dirs missing and uncreatable, OS permission denied, read-only filesystem, or a regular file already exists at that path.","commonSituations":"Non-root Cassandra user lacking write access to the configured path; Docker/Kubernetes volumes mounted read-only; SELinux/AppArmor denials; disk full or typo in the directory path.","solutions":["Create the directory manually as the user running Cassandra and chown it appropriately (mkdir -p && chown cassandra)","Fix the configured log dir path (typo, wrong mount) to a writable location","Check filesystem mount flags/permissions (read-only, SELinux context) and remount or relabel","Inspect the original cause in Cassandra's debug logs if present; the rethrown message omits it"],"exampleFix":"// before\nasync_profiler_dir: /proc/cassandra-prof\n// after\nsudo mkdir -p /var/log/cassandra/async-profiler && sudo chown cassandra:cassandra /var/log/cassandra/async-profiler","handlingStrategy":"try-catch","validationCode":"Path p = Path.of(logDir);\nif (!Files.isDirectory(p)) Files.createDirectories(p); // fail early with a clear cause\nif (!Files.isWritable(p)) throw new AccessDeniedException(p.toString());","typeGuard":null,"tryCatchPattern":"try { svc.apply(cmd, file); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to create directory\")) { Files.createDirectories(Path.of(logDir)); svc.apply(cmd, file); } else throw e; }","preventionTips":["Pre-create the profiler log dir as the cassandra user with correct ownership","Verify the target mount is writable (not read-only, not full)","Check SELinux/AppArmor policies for the chosen path","Log the underlying cause — the rethrown RuntimeException hides it"],"tags":["filesystem","permissions","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}