apache/cassandra · critical · FSWriteError

Could not copy file to

Error message

Could not copy file%s to %s

What it means

copyWithConfirm(String, String) throws FSWriteError wrapping an IOException from Files.copy, with message 'Could not copy fileX to Y'. It indicates the file copy failed at the OS level after source/destination decisions were made. FSWriteError is a fatal FS error in Cassandra, usually surfacing as JVM death of the affected node.

Solutions

  1. Verify both source and destination paths exist and are writable.
  2. Free disk space or fix permissions on the destination directory.
  3. Inspect the FSWriteError cause for the precise OS-level error.

Example fix

// before
FileUtils.copyWithConfirm(from, to);

// after
File dest = new File(to);
if (!dest.getParentFile().exists())
    dest.getParentFile().mkdirs();
FileUtils.copyWithConfirm(from, to);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!new File(to).getParentFile().exists()) new File(to).getParentFile().mkdirs(); if (new File(to).getParentFile().getFreeSpace() < new File(from).length()) throw new IllegalStateException("insufficient space");

Try / catch

try { FileUtils.copyWithConfirm(from, to); } catch (FSWriteError e) { /* check e.getCause(): permissions, ENOSPC, missing dir */ }

Prevention

When it happens

Trigger: Calling FileUtils.copyWithConfirm when Files.copy throws IOException — destination directory missing/unwritable, source unreadable, disk full, or cross-filesystem issues.

Common situations: Commitlog archive with a misconfigured or removed archive directory; permission changes on the archive dir; insufficient disk space during archival/copy operations.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0f9b65c7819fbec5. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/io/util/FileUtils.java:227

    public static void copyWithConfirm(String from, String to)
    {
        copyWithConfirm(new File(from), new File(to));
    }

    public static void copyWithConfirm(File from, File to)
    {
        assert from.exists();
        if (logger.isTraceEnabled())
            logger.trace("Copying {} to {}", from.path(), to.path());

        try
        {
            Files.copy(from.toPath(), to.toPath());
        }
        catch (IOException e)
        {
            throw new FSWriteError(e, "Could not copy file" + from + " to " + to);
        }
    }

    public static void truncate(String path, long size)
    {
        File file = new File(path);
        try (FileChannel channel = file.newReadWriteChannel())
        {
            channel.truncate(size);
        }
        catch (IOException e)
        {
            throw PathUtils.propagateUnchecked(e, file.toPath(), true);
        }
    }

    public static void closeQuietly(Closeable c)
    {

View on GitHub (pinned to 88fd0f6a0e)