apache/cassandra · error · RuntimeException

Failed to get file block size in

Error message

Failed to get file block size in %s

What it means

getFileBlockSize(File) throws RuntimeException wrapping an IOException from the native blockSize(file) probe. It reports 'Failed to get file block size in <file>' and indicates the filesystem stat/st_blksize query failed — e.g. the file does not exist or is inaccessible on platforms supporting the probe.

Solutions

  1. Check the file exists and is readable before calling.
  2. Inspect the wrapped IOException cause for the real errno.
  3. Wrap the call in try/catch and fall back to a default block size (e.g. 4096).

Example fix

// before
int bs = FileUtils.getFileBlockSize(file);

// after
int bs;
try {
    bs = FileUtils.getFileBlockSize(file);
} catch (RuntimeException e) {
    logger.warn("Block size probe failed, defaulting to 4096", e);
    bs = 4096;
}
Defensive patterns

Strategy: fallback

Validate before calling

if (!file.exists() || !file.canRead()) return 4096; // default block size

Type guard

boolean probeable(File f) { return f != null && f.exists() && f.canRead(); }

Try / catch

try { return FileUtils.getFileBlockSize(file); } catch (RuntimeException e) { return 4096; }

Prevention

When it happens

Trigger: Calling FileUtils.getFileBlockSize on a file that cannot be stat'ed: nonexistent path, deleted-while-probing file, or permission-denied; also on platforms where the native probe is unsupported/failing.

Common situations: Probing block size for compaction/writer tuning on a file removed concurrently by compaction/cleanup; wrong data directory configuration; running on a filesystem or platform lacking the probe.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

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

        {
            return false;
        }
        finally
        {
            if (testFile != null)
                testFile.tryDelete();
        }
    }

    public static int getFileBlockSize(File file)
    {
        try
        {
            return blockSize(file);
        }
        catch (IOException e)
        {
            throw new RuntimeException("Failed to get file block size in " + file, e);
        }
    }

    private static final ConcurrentHashMap<String, Integer> blockSizeByDirectory = new ConcurrentHashMap<>();

    public static int getBlockSize(File directory)
    {
        return blockSizeByDirectory.computeIfAbsent(directory.absolutePath(), ignored -> probeBlockSize(directory));
    }

    private static int probeBlockSize(File directory)
    {
        File f = FileUtils.createTempFile("block-size-test", ".tmp", directory);
        try
        {
            return blockSize(f);
        }
        catch (IOException e)

View on GitHub (pinned to 88fd0f6a0e)