{"record":{"id":"da28e39452b34eae","repo":"apache/cassandra","slug":"compression-failed-da28e3","errorCode":null,"errorMessage":"Compression failed","messagePattern":"Compression failed","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/compress/ZstdDictionaryCompressor.java","lineNumber":210,"sourceCode":"    {\n        if (dictionary == null)\n        {\n            super.compress(input, output);\n            return;\n        }\n\n        try\n        {\n            // Zstd compressors expect only direct bytebuffer. See ZstdCompressorBase.preferredBufferType and supports\n            int compressedSize = (int) Zstd.compressDirectByteBufferFastDict(output, output.position(), output.limit() - output.position(),\n                                                                             input, input.position(), input.limit() - input.position(),\n                                                                             dictionary.dictionaryForCompression(compressionLevel()));\n            output.position(output.position() + compressedSize);\n            input.position(input.limit());\n        }\n        catch (Exception e)\n        {\n            throw new IOException(\"Compression failed\", e);\n        }\n    }\n\n    @VisibleForTesting\n    ZstdCompressionDictionary dictionary()\n    {\n        return dictionary;\n    }\n\n    @VisibleForTesting\n    public static void invalidateCache()\n    {\n        instancePerDict.invalidateAll();\n        instancePerDict.cleanUp();\n    }\n}\n","sourceCodeStart":192,"sourceCodeEnd":227,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/compress/ZstdDictionaryCompressor.java#L192-L227","documentation":"Thrown by ZstdDictionaryCompressor.compress when the Zstd JNI compression call (with or without a dictionary) throws an exception. It wraps the low-level failure into an IOException, aborting the chunk compression. Causes include a null/invalid dictionary, insufficient output buffer space, or a JNI-level error.","triggerScenarios":"Calling compress(ByteBuffer input, ByteBuffer output) (or the byte[] variant) when the output buffer has less remaining space than Zstd.compressBound(inputLength), or the loaded dictionary fails to initialize for compression (e.g. null dictionary with dictionary compression expected, or corrupted dictionary file).","commonSituations":"Sizing the compressed output buffer too small; dictionary training file corrupt or truncated; compression level out of accepted range; resource exhaustion in the Zstd context pool.","solutions":["Check the wrapped cause via getCause() for the underlying Zstd error","Ensure the output buffer has at least Zstd.compressBound(inputLength) bytes remaining","Verify the dictionary file exists, is a valid Zstd dictionary, and matches the configured compression parameters","Retest with a lower compression level or without a dictionary to isolate the cause"],"exampleFix":"// before\nByteBuffer out = ByteBuffer.allocate(input.remaining());\ncompressor.compress(input, out);\n// after\nByteBuffer out = ByteBuffer.allocate((int) Zstd.compressBound(input.remaining()));\ncompressor.compress(input, out);","handlingStrategy":"try-catch","validationCode":"if (output.remaining() < Zstd.compressBound(input.remaining())) throw new IllegalArgumentException(\"compressed output buffer too small\");","typeGuard":"null","tryCatchPattern":"try { compressor.compress(input, output); } catch (IOException e) { logger.error(\"zstd compress failed\", e.getCause()); throw e; }","preventionTips":["Always size compressed buffers with Zstd.compressBound","Validate the dictionary file loads (non-null, valid format) at startup","Pin compression parameters (level, dictionary) consistently across writer and reader","Test compression with empty and max-size chunks in unit tests"],"tags":["io","zstd","compression"],"backgroundTag":"file-write-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}