MyCATApache/Mycat-Server · error · IOException
Failed to create local dir in $newDir.
Error message
Failed to create local dir in $newDir.
What it means
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.
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
Example fix
// before
File dir = new File(localDirs.get(dirId), "%02x".format(String.valueOf(subDirId)));
if (!file.exists() && !file.mkdir()) {
throw new IOException("Failed to create local dir in $newDir.");
}
// after
File dir = new File(localDirs.get(dirId), "%02x".format(String.valueOf(subDirId)));
dir.getParentFile().mkdirs(); // ensure parent exists
if (!dir.exists() && !dir.mkdirs()) {
throw new IOException("Failed to create local dir " + dir.getAbsolutePath());
} Defensive patterns
Strategy: validation
Validate before calling
File parent = new File(localDir);
if (!parent.isDirectory() || !parent.canWrite()) {
throw new IllegalStateException("local dir not usable: " + parent);
}
parent.mkdirs(); Type guard
boolean isUsableDir(File d) { return d != null && d.isDirectory() && d.canWrite(); } Try / catch
try { manager.getFile(dirId, subDirId); } catch (IOException e) { log.error("cannot create local subdir; check perms/disk/mounts", e); throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Failed to delete:
- Failed to list files for dir:
- Mkdirs failed to create
- error while calling spill() on
- error while calling spill() on
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/97028ae4346aa583.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/storage/DataNodeFileManager.java:116
/** Looks up a file by hashing it into one of our local subdirectories. */
// This method should be kept in sync with
// org.apache.spark.network.shuffle.ExternalShuffleBlockResolver#getFile().
public File getFile(String filename) throws IOException {
// Figure out which local directory it hashes to, and which subdirectory in that
int hash = JavaUtils.nonNegativeHash(filename);
int dirId = hash % localDirs.size();
int subDirId = (hash / localDirs.size()) % subDirsPerLocalDir;
synchronized (this) {
File file = subDirs.get(dirId).get(subDirId);
if (file != null) {
} else {
file = new File(localDirs.get(dirId), "%02x".format(String.valueOf(subDirId)));
if (!file.exists() && !file.mkdir()) {
throw new IOException("Failed to create local dir in $newDir.");
}
subDirs.get(dirId).add(subDirId,file);
}
}
/**
*类似二维数组
*/
return new File(subDirs.get(dirId).get(subDirId),filename);
}
public File getFile(ConnectionId connid) throws IOException {
return getFile(connid.name);
}
/**TODO config root
* Create local directories for storing block data. These directories are
* located inside configured local directories and won'tView on GitHub (pinned to 65f8d8beb7)