MyCATApache/Mycat-Server · error · IOException
Failed to create a temp directory
Error message
Failed to create a temp directory (under ${rootDir}) after ${maxAttempts} attempts! What it means
createDirectory attempts up to MAX_DIR_CREATION_ATTEMPTS to create a uniquely-named temp subdirectory (UUID-suffixed) under a root directory. If every mkdirs() call fails or collides, it throws IOException. This guards against indefinite loops when the filesystem is broken or exhausted.
Solutions
- Ensure the root directory exists and is writable by the process user (mkdir -p and chown/chmod it).
- Check disk space and mount state (df -h; mount) for the filesystem holding rootDir.
- Fix any configured scratch/spill directories pointing at read-only or nonexistent paths.
- Catch IOException and fall back to an alternative temp root (e.g. java.io.tmpdir) with a logged warning.
Example fix
// before
File dir = JavaUtils.createDirectory(new File("/mnt/ro-scratch"), "blockmgr");
// after
File root = new File("/mnt/ro-scratch");
if (!root.canWrite()) root = new File(System.getProperty("java.io.tmpdir"));
File dir = JavaUtils.createDirectory(root, "blockmgr"); Defensive patterns
Strategy: fallback
Validate before calling
File root = new File(rootDir);
if (!root.isDirectory() || !root.canWrite()) { throw new IllegalStateException("scratch dir unusable: " + rootDir); } Try / catch
try { return JavaUtils.createDirectory(root, prefix); } catch (IOException e) { log.warn("temp dir creation failed under {}", root, e); return JavaUtils.createDirectory(new File(System.getProperty("java.io.tmpdir")), prefix); } Prevention
- Verify scratch directories exist and are writable at process startup
- Monitor disk space on spill/scratch volumes
- Run the process as a user with write access to configured dirs
When it happens
Trigger: Calling JavaUtils.createDirectory(rootDir) when rootDir does not exist or is not writable, the filesystem is full, or mkdirs() repeatedly fails (e.g. root is a read-only mount or a file exists with the same path prefix).
Common situations: Deployments where the configured local scratch directory (e.g. /tmp or a block-manager dir) is missing or read-only; disk-full conditions on data nodes; running as a user without write permission on the parent directory.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Mkdirs failed to create
- Failed to create local dir in $newDir.
- Failed to delete:
- Failed to list files for dir:
- Error opening jar
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/7b8aa4da7a379c12.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/utils/JavaUtils.java:335
unit = "KB";
} else {
value = size;
unit = "B";
}
return value + unit;
}
public static File createDirectory(String rootDir, String blockmgr) throws IOException {
int attempts = 0;
int maxAttempts = MAX_DIR_CREATION_ATTEMPTS;
File dir = null;
while (dir == null) {
attempts += 1;
if (attempts > maxAttempts) {
throw new IOException("Failed to create a temp directory (under " + rootDir + ") after " +
maxAttempts + " attempts!");
}
try {
dir = new File(rootDir, blockmgr + "-" + UUID.randomUUID().toString());
if (dir.exists() || !dir.mkdirs()) {
dir = null;
}
} catch (Exception e) {
logger.error(e.getMessage());
}
}
return dir.getCanonicalFile();
}
/* Calculates 'x' modulo 'mod', takes to consideration sign of x,
* i.e. if 'x' is negative, than 'x' % 'mod' is negative too
* so function return (x % mod) + mod in that case.View on GitHub (pinned to 65f8d8beb7)