{"record":{"id":"97028ae4346aa583","repo":"MyCATApache/Mycat-Server","slug":"failed-to-create-local-dir-in-newdir","errorCode":null,"errorMessage":"Failed to create local dir in $newDir.","messagePattern":"Failed to create local dir in \\$newDir\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/memory/unsafe/storage/DataNodeFileManager.java","lineNumber":116,"sourceCode":"\n\n  /** Looks up a file by hashing it into one of our local subdirectories. */\n  // This method should be kept in sync with\n  // org.apache.spark.network.shuffle.ExternalShuffleBlockResolver#getFile().\n  public File getFile(String filename) throws IOException {\n    // Figure out which local directory it hashes to, and which subdirectory in that\n    int hash = JavaUtils.nonNegativeHash(filename);\n    int dirId = hash % localDirs.size();\n    int subDirId = (hash / localDirs.size()) % subDirsPerLocalDir;\n\n    synchronized (this) {\n      File file = subDirs.get(dirId).get(subDirId);\n      if (file != null) {\n      \n      } else {\n        file = new File(localDirs.get(dirId), \"%02x\".format(String.valueOf(subDirId)));\n        if (!file.exists() && !file.mkdir()) {\n          throw new IOException(\"Failed to create local dir in $newDir.\");\n        }\n        subDirs.get(dirId).add(subDirId,file);\n      }\n    }\n\n    /**\n     *类似二维数组\n     */\n    return  new File(subDirs.get(dirId).get(subDirId),filename);\n  }\n\n  public File getFile(ConnectionId connid) throws IOException {\n    return getFile(connid.name);\n  }\n\n  /**TODO config root\n   * Create local directories for storing block data. These directories are\n   * located inside configured local directories and won't","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/storage/DataNodeFileManager.java#L98-L134","documentation":"DataNodeFileManager.getFile() lazily creates per-directory hash subdirectories (hex-formatted subDirId) under a configured local dir. When File.mkdir() fails (and the dir doesn't already exist), it throws IOException 'Failed to create local dir in $newDir.' Note the message uses an uninterpolated Scala-style $newDir token, so it does not show the actual path.","triggerScenarios":"Calling file()/getFile() (directly or via createTempLocalBlock) when the target subdirectory cannot be created — parent local dir missing, wrong permissions, read-only filesystem, disk full, or a file already exists at the subdirectory path.","commonSituations":"Misconfigured local dirs pointing to a non-existent or unwritable path; running the process as a user without write permission to the data directory; container with read-only volume mounts; path created by another user with different ownership.","solutions":["Verify each configured local dir exists and is writable by the process user before use; create it with mkdirs() at startup","Fix filesystem permissions (chown/chmod) or mount the data volume read-write","Check disk space and that no regular file occupies the subdirectory path; then retry"],"exampleFix":"// before\nFile dir = new File(localDirs.get(dirId), \"%02x\".format(String.valueOf(subDirId)));\nif (!file.exists() && !file.mkdir()) {\n  throw new IOException(\"Failed to create local dir in $newDir.\");\n}\n// after\nFile dir = new File(localDirs.get(dirId), \"%02x\".format(String.valueOf(subDirId)));\ndir.getParentFile().mkdirs(); // ensure parent exists\nif (!dir.exists() && !dir.mkdirs()) {\n  throw new IOException(\"Failed to create local dir \" + dir.getAbsolutePath());\n}","handlingStrategy":"validation","validationCode":"File parent = new File(localDir);\nif (!parent.isDirectory() || !parent.canWrite()) {\n  throw new IllegalStateException(\"local dir not usable: \" + parent);\n}\nparent.mkdirs();","typeGuard":"boolean isUsableDir(File d) { return d != null && d.isDirectory() && d.canWrite(); }","tryCatchPattern":"try { manager.getFile(dirId, subDirId); } catch (IOException e) { log.error(\"cannot create local subdir; check perms/disk/mounts\", e); throw e; }","preventionTips":["Eagerly mkdirs all configured local dirs at startup and fail fast","Run the process as a user owning the data directory","Monitor disk space and avoid read-only mounts for data paths","Fix the error message to include the actual absolute path"],"tags":["java","filesystem","io","storage"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}