{"record":{"id":"737a47efc92113a9","repo":"apache/cassandra","slug":"failed-to-get-file-block-size-in-s","errorCode":null,"errorMessage":"Failed to get file block size in %s","messagePattern":"Failed to get file block size in (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/FileUtils.java","lineNumber":783,"sourceCode":"        {\n            return false;\n        }\n        finally\n        {\n            if (testFile != null)\n                testFile.tryDelete();\n        }\n    }\n\n    public static int getFileBlockSize(File file)\n    {\n        try\n        {\n            return blockSize(file);\n        }\n        catch (IOException e)\n        {\n            throw new RuntimeException(\"Failed to get file block size in \" + file, e);\n        }\n    }\n\n    private static final ConcurrentHashMap<String, Integer> blockSizeByDirectory = new ConcurrentHashMap<>();\n\n    public static int getBlockSize(File directory)\n    {\n        return blockSizeByDirectory.computeIfAbsent(directory.absolutePath(), ignored -> probeBlockSize(directory));\n    }\n\n    private static int probeBlockSize(File directory)\n    {\n        File f = FileUtils.createTempFile(\"block-size-test\", \".tmp\", directory);\n        try\n        {\n            return blockSize(f);\n        }\n        catch (IOException e)","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/FileUtils.java#L765-L801","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the file exists and is readable before calling.","Inspect the wrapped IOException cause for the real errno.","Wrap the call in try/catch and fall back to a default block size (e.g. 4096)."],"exampleFix":"// before\nint bs = FileUtils.getFileBlockSize(file);\n\n// after\nint bs;\ntry {\n    bs = FileUtils.getFileBlockSize(file);\n} catch (RuntimeException e) {\n    logger.warn(\"Block size probe failed, defaulting to 4096\", e);\n    bs = 4096;\n}","handlingStrategy":"fallback","validationCode":"if (!file.exists() || !file.canRead()) return 4096; // default block size","typeGuard":"boolean probeable(File f) { return f != null && f.exists() && f.canRead(); }","tryCatchPattern":"try { return FileUtils.getFileBlockSize(file); } catch (RuntimeException e) { return 4096; }","preventionTips":["Default to 4096 when probing is optional tuning, not correctness.","Ensure files are not deleted concurrently while probing.","Verify platform/filesystem support for block-size probes."],"tags":["io","filesystem","native"],"backgroundTag":"file-read-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}