{"record":{"id":"72916deb9f0e1d24","repo":"apache/cassandra","slug":"s-exists-but-is-not-writable","errorCode":null,"errorMessage":"%s exists but is not writable","messagePattern":"(.+?) exists but is not writable","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java","lineNumber":458,"sourceCode":"        {\n            return inDirectory(new File(directory));\n        }\n\n        /**\n         * The directory where to write the sstables (mandatory option).\n         * <p>\n         * This is a mandatory option.\n         *\n         * @param directory the directory to use, which should exists and be writable.\n         * @return this builder.\n         * @throws IllegalArgumentException if {@code directory} doesn't exist or is not writable.\n         */\n        public Builder inDirectory(File directory)\n        {\n            if (!directory.exists())\n                throw new IllegalArgumentException(directory + \" doesn't exists\");\n            if (!directory.isWritable())\n                throw new IllegalArgumentException(directory + \" exists but is not writable\");\n\n            this.directory = directory;\n            return this;\n        }\n\n        public Builder withType(String typeDefinition) throws SyntaxException\n        {\n            typeStatements.add(QueryProcessor.parseStatement(typeDefinition, CreateTypeStatement.Raw.class, \"CREATE TYPE\"));\n            return this;\n        }\n\n        /**\n         * The schema (CREATE TABLE statement) for the table for which sstable are to be created.\n         * <p>\n         * Please note that the provided CREATE TABLE statement <b>must</b> use a fully-qualified\n         * table name, one that include the keyspace name.\n         * <p>\n         * This is a mandatory option.","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java#L440-L476","documentation":"Thrown by CQLSSTableWriter.Builder.inDirectory(File) as an IllegalArgumentException when the directory exists but the process lacks write permission to it. The writer will not be able to create SSTable data files there, so the builder fails fast at configuration time.","triggerScenarios":"Calling inDirectory(File) pointing at a directory that exists but is not writable by the current OS user — e.g. /var/lib/cassandra when running the bulk loader as a non-cassandra user, or a read-only mounted volume.","commonSituations":"Running the standalone sstableloader/bulk-loader under a different user than the data directory owner; read-only container filesystems or mounts; overly restrictive umask or chmod after provisioning.","solutions":["Chown/chmod the directory so the running user can write (e.g. chmod u+w or chown cassandra:cassandra)","Point inDirectory at a directory writable by the current user","Remount the volume read-write if it is mounted ro","Run the process as a user with write access to the target data directory"],"exampleFix":"// before\nbuilder.inDirectory(new File(\"/var/lib/cassandra/data\")); // owned by cassandra, we are root-without-write? no—other user\n// after\n// shell: sudo chown -R $USER /var/lib/cassandra/data  (or choose a writable dir)\nbuilder.inDirectory(new File(System.getProperty(\"java.io.tmpdir\"), \"sstables-out\"));","handlingStrategy":"validation","validationCode":"if (dir.exists() && !dir.canWrite()) throw new IllegalStateException(\"no write permission on \" + dir);","typeGuard":"null","tryCatchPattern":"try { builder.inDirectory(dir); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"not writable\")) { /* chmod/chown or pick another dir */ } throw e; }","preventionTips":["Run the bulk loader as a user that owns or can write the data directory","Avoid read-only mounts for SSTable output","Check canWrite() in pre-flight before starting long bulk loads","Standardize permissions on data directories during provisioning"],"tags":["sstable","bulk-loading","filesystem","permissions"],"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"}