apache/cassandra · error · IllegalArgumentException

Unable to allocate %s

Error message

Unable to allocate %s

What it means

serialize() measures a value's serialized size via the configured ISerializer and allocates a RefCountedMemory buffer of that exact size. If serializer.serializedSize(value) reports more than Integer.MAX_VALUE bytes, no int-length buffer can exist, so it throws IllegalArgumentException('Unable to allocate <size>'). This is the check on the serializer-provided path (error [92] is the lambda-sizer path).

Source

Thrown at src/java/org/apache/cassandra/cache/SerializingCache.java:96

    private V deserialize(RefCountedMemory mem)
    {
        try
        {
            return serializer.deserialize(new MemoryInputStream(mem));
        }
        catch (IOException e)
        {
            logger.trace("Cannot fetch in memory data, we will fallback to read from disk ", e);
            return null;
        }
    }

    private RefCountedMemory serialize(V value)
    {
        long serializedSize = serializer.serializedSize(value);
        if (serializedSize > Integer.MAX_VALUE)
            throw new IllegalArgumentException(String.format("Unable to allocate %s", FBUtilities.prettyPrintMemory(serializedSize)));

        RefCountedMemory freeableMemory;
        try
        {
            freeableMemory = new RefCountedMemory(serializedSize);
        }
        catch (OutOfMemoryError e)
        {
            return null;
        }

        try
        {
            serializer.serialize(value, new WrappedDataOutputStreamPlus(new MemoryOutputStream(freeableMemory)));
        }
        catch (IOException e)
        {
            freeableMemory.unreference();

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Reduce the size of values put into the cache so each serializes under 2GiB.
  2. Fix or validate the ISerializer so serializedSize matches real content and never exceeds Integer.MAX_VALUE.
  3. Check value size before put() and bypass the cache for oversized entries.
  4. Store oversized data outside the cache (direct I/O / disk) and cache only references or metadata.

Example fix

// before
long serializedSize = serializer.serializedSize(value);
if (serializedSize > Integer.MAX_VALUE)
    throw new IllegalArgumentException(String.format("Unable to allocate %s", FBUtilities.prettyPrintMemory(serializedSize)));
// after
long serializedSize = serializer.serializedSize(value);
if (serializedSize > Integer.MAX_VALUE) {
    logger.warn("Value too large for cache ({}); bypassing cache", FBUtilities.prettyPrintMemory(serializedSize));
    return null;
}
Defensive patterns

Strategy: validation

Validate before calling

// check serialized size before put
long serializedSize = serializer.serializedSize(value);
if (serializedSize > Integer.MAX_VALUE || serializedSize < 0) {
    throw new IllegalArgumentException("Serializer reports invalid size: " + serializedSize);
}

Type guard

boolean cacheable(V v, ISerializer<V> s) { long n = s.serializedSize(v); return n >= 0 && n <= Integer.MAX_VALUE; }

Try / catch

try {
    cache.put(key, value);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unable to allocate")) {
        bypassCache(value); // too large for cache
    } else throw e;
}

Prevention

When it happens

Trigger: Putting a value into a SerializingCache when serializer.serializedSize(value) returns a value > Integer.MAX_VALUE; a serializer that mis-measures (returns huge/negative-wrapping sizes) also lands here.

Common situations: Caching rows with very large cells/collections exceeding 2GiB serialized; buggy custom ISerializer whose serializedSize disagrees with actual content; values that grew across version upgrades beyond the int limit.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


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