{"record":{"id":"eceed99c2429f668","repo":"apache/cassandra","slug":"serialized-size-must-not-be-more-than-2gib","errorCode":null,"errorMessage":"Serialized size must not be more than 2GiB","messagePattern":"Serialized size must not be more than 2GiB","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cache/SerializingCache.java","lineNumber":73,"sourceCode":"                   .removalListener((key, mem, cause) -> {\n                       if (cause.wasEvicted()) {\n                           mem.unreference();\n                       }\n                   })\n                   .build();\n    }\n\n    public static <K, V> SerializingCache<K, V> create(long weightedCapacity, Weigher<K, RefCountedMemory> weigher, ISerializer<V> serializer)\n    {\n        return new SerializingCache<>(weightedCapacity, weigher, serializer);\n    }\n\n    public static <K, V> SerializingCache<K, V> create(long weightedCapacity, ISerializer<V> serializer)\n    {\n        return create(weightedCapacity, (key, value) -> {\n            long size = value.size();\n            if (size > Integer.MAX_VALUE) {\n                throw new IllegalArgumentException(\"Serialized size must not be more than 2GiB\");\n            }\n            return (int) size;\n        }, serializer);\n    }\n\n    private V deserialize(RefCountedMemory mem)\n    {\n        try\n        {\n            return serializer.deserialize(new MemoryInputStream(mem));\n        }\n        catch (IOException e)\n        {\n            logger.trace(\"Cannot fetch in memory data, we will fallback to read from disk \", e);\n            return null;\n        }\n    }\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cache/SerializingCache.java#L55-L91","documentation":"SerializingCache stores each deserialized value as one in-memory buffer whose length must fit in an int (Java array/buffer size limit). The create() overload validates the measured value size eagerly and throws IllegalArgumentException when a single serialized value exceeds Integer.MAX_VALUE (2GiB - 1 bytes). The cache simply cannot hold an individual entry larger than 2GiB.","triggerScenarios":"Calling SerializingCache.create(capacity, serializer) and then putting a value whose ISelfSerializingSubject.size() (via the default sizer lambda) returns more than Integer.MAX_VALUE.","commonSituations":"Caching very large blobs/rows (e.g. huge collections or chunked values aggregated into one entry); a custom serializer or sizer that returns a wrong (unbounded) size; 2GiB limit hit after migrating data that grew past the int limit.","solutions":["Ensure no single cached value exceeds 2GiB serialized; split it into smaller entries/keys.","Provide a custom size-measuring lambda to create() that bounds or correctly computes size and rejects oversized values earlier with a clearer message.","Validate value sizes before putting them into the cache.","Use a different storage mechanism (e.g. disk-backed store) for values larger than 2GiB."],"exampleFix":"// before\nlong size = value.size();\nif (size > Integer.MAX_VALUE) {\n    throw new IllegalArgumentException(\"Serialized size must not be more than 2GiB\");\n}\n// after\nlong size = value.size();\nif (size > Integer.MAX_VALUE) {\n    logger.warn(\"Skipping cache of oversized value ({} bytes); splitting or bypassing cache\", size);\n    return null; // handle null sizer result upstream instead of failing\n}","handlingStrategy":"validation","validationCode":"// validate value size before caching\nlong size = value.size();\nif (size > Integer.MAX_VALUE) {\n    throw new IllegalArgumentException(\"Value of \" + size + \" bytes exceeds 2GiB cache-entry limit\");\n}","typeGuard":"boolean cacheable(V v) { return v != null && v.size() <= Integer.MAX_VALUE; }","tryCatchPattern":"try {\n    cache.put(key, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"2GiB\")) {\n        // bypass cache or split value\n        storeDirectly(value);\n    } else throw e;\n}","preventionTips":["Keep individual cached values well under 2GiB serialized.","Split very large values into smaller keyed entries.","Provide a custom sizer lambda that rejects oversized values early.","Re-validate sizes after version upgrades or schema changes that grow values."],"tags":["cache","serialization","size-limit"],"backgroundTag":"payload-too-large","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}