{"record":{"id":"4644cdbb55c85e7f","repo":"apache/cassandra","slug":"unable-to-create-directory-dir","errorCode":null,"errorMessage":"Unable to create directory \" + dir","messagePattern":"Unable to create directory \" \\+ dir","errorType":"exception","errorClass":"FSWriteError","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/db/Directories.java","lineNumber":1314,"sourceCode":"                                                              .list()\n                                                              .keySet()\n                                                              .spliterator(), Spliterator.DISTINCT, false)\n                                                .map(d -> d.id);\n\n        return builder.generator(curIds);\n    }\n\n    private static File getOrCreate(File base, String... subdirs)\n    {\n        File dir = subdirs == null || subdirs.length == 0 ? base : new File(base, join(subdirs));\n        if (dir.exists())\n        {\n            if (!dir.isDirectory())\n                throw new AssertionError(String.format(\"Invalid directory path %s: path exists but is not a directory\", dir));\n        }\n        else if (!dir.tryCreateDirectories() && !(dir.exists() && dir.isDirectory()))\n        {\n            throw new FSWriteError(new IOException(\"Unable to create directory \" + dir), dir);\n        }\n        return dir;\n    }\n\n    public static Optional<File> get(File base, String... subdirs)\n    {\n        File dir = subdirs == null || subdirs.length == 0 ? base : new File(base, join(subdirs));\n        return dir.exists() ? Optional.of(dir) : Optional.empty();\n    }\n\n    public static File getWithoutCreation(File base, String... subdirs)\n    {\n        return subdirs == null || subdirs.length == 0 ? base : new File(base, join(subdirs));\n    }\n\n    private static String join(String... s)\n    {\n        return StringUtils.join(s, File.pathSeparator());","sourceCodeStart":1296,"sourceCodeEnd":1332,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/Directories.java#L1296-L1332","documentation":"During Directories construction Cassandra verifies/creates the data directory hierarchy (keyspace/table subdirectories, backups, snapshots). If a directory does not exist and tryCreateDirectories() fails (and it does not exist as a directory afterwards), it throws FSWriteError wrapping an IOException 'Unable to create directory <dir>'.","triggerScenarios":"Startup or table creation while the parent data directory is missing, or the filesystem is read-only, or the cassandra user lacks write permission on the parent; also when the path exists but creation race-fails.","commonSituations":"Wrong ownership/permissions after running Cassandra once as root (dirs owned by root, service later runs as cassandra); read-only mounts (container images, snapshot restores); SELinux/AppArmor denials; full filesystems; data_file_directories pointing at non-existent, uncreatable paths.","solutions":["Fix ownership/permissions: `chown -R cassandra:cassandra <data_dir>` and ensure the directory is writable (chmod 755).","Check the filesystem is not read-only (`mount | grep ro`) and remount read-write; free space if the disk is full.","Verify data_file_directories paths in cassandra.yaml exist or their parents are creatable by the cassandra user.","Check SELinux/AppArmor audit logs and adjust policy or contexts (`restorecon -R`) if denials are recorded."],"exampleFix":"// before (running as wrong user or wrong perms)\n$ ls -ld /var/lib/cassandra/data\ndrwxr-xr-x root root\n// after\n$ sudo chown -R cassandra:cassandra /var/lib/cassandra\n$ sudo systemctl restart cassandra","handlingStrategy":"validation","validationCode":"Path dir = Paths.get(dataDir, ks, table);\nFiles.createDirectories(dir.getParent());\nif (!Files.isWritable(dir.getParent())) throw new IllegalStateException(\"Not writable: \" + dir);\n","typeGuard":null,"tryCatchPattern":"try {\n    new Directories(metadata, dataDirectories);\n} catch (FSWriteError e) {\n    if (e.getMessage().startsWith(\"Unable to create directory\"))\n        throw new ConfigurationException(\"Check ownership/permissions/read-only fs for: \" + e.getMessage(), e);\n    throw e;\n}\n","preventionTips":["Provision data directories with correct ownership (cassandra:cassandra) before startup.","Never run Cassandra as root (avoids root-owned dirs later unwritable).","Ensure mounts are rw and filesystems have free space at boot (systemd/health checks).","Verify SELinux/AppArmor contexts on data directories."],"tags":["filesystem","permissions","startup","directories"],"backgroundTag":"file-write-permission-denied","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"}