apache/cassandra · critical · FSWriteError

FSWriteError

Error message

FSWriteError

What it means

writeChunk() writes a compressed chunk to the file channel and appends its CRC. Any IOException from channel.write() (or the CRC metadata append) is wrapped in FSWriteError with the file path, failing the write operation because partial chunk writes would corrupt the compressed SSTable layout.

Source

Thrown at src/java/org/apache/cassandra/io/compress/CompressedSequentialWriter.java:271

            buffer.position(uncompressedLength);

        // next chunk should be written right after current + length of the checksum (int)
        chunkOffset += compressedLength + 4;
        if (runPostFlush != null)
            runPostFlush.accept(getLastFlushOffset());
    }

    protected void writeChunk(ByteBuffer toWrite)
    {
        try
        {
            channel.write(toWrite);
            toWrite.rewind();
            crcMetadata.appendDirect(toWrite, true);
        }
        catch (IOException e)
        {
            throw new FSWriteError(e, getPath());
        }
    }

    public CompressionMetadata open(long overrideLength)
    {
        if (overrideLength <= 0)
            overrideLength = uncompressedSize;
        return metadataWriter.open(overrideLength, chunkOffset);
    }

    @Override
    public DataPosition mark()
    {
        if (!buffer.hasRemaining())
            doFlush(0);
        return new CompressedFileWriterMark(chunkOffset, current(), buffer.position(), chunkCount + 1);
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Free disk space or expand the volume; Cassandra retries the failed flush after space is available
  2. Check the wrapped IOException cause in the log for the specific errno (ENOSPC/EIO/EBADF) and fix the underlying storage
  3. Verify filesystem is writable and permissions/ownership on the data directories are correct for the Cassandra user
  4. After disk recovery, validate/rebuild affected SSTables with nodetool scrub

Example fix

// before
# df -h /var/lib/cassandra -> 100% full, flush throws FSWriteError
// after
# expand volume or move data dirs; ensure free space
df -h /var/lib/cassandra
nodetool scrub ks tbl
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight checks before heavy writes
if (Files.getFileStore(Paths.get(dataDir)).getUsableSpace() < requiredBytes) throw new IllegalStateException("insufficient disk");
if (!Files.isWritable(Paths.get(dataDir))) throw new IllegalStateException("data dir not writable");

Try / catch

try {
    flushData();
} catch (FSWriteError e) {
    logger.error("Chunk write failed for {}", e.getPath(), e.getCause());
    // free disk / fix storage, then retry flush; Cassandra retries automatically on the next flush attempt
}

Prevention

When it happens

Trigger: flushData() -> writeChunk() when the disk is full (ENOSPC), the device returns EIO, the filesystem is read-only, or the channel was closed while writing compressed SSTable data during flush or compaction.

Common situations: Disk full during a large memtable flush; failed/remounted volumes in containers; quota-limited storage hitting capacity mid-write; concurrent closure of the channel after a disk swap.

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/74b3d3a935a66599. Report an issue: GitHub.