apache/cassandra · error · MarshalException

Too many bytes for comparator

Error message

Too many bytes for comparator

What it means

CompositeType's internal validateComparator is asked for the type of component i; when i is beyond the configured type list it throws this MarshalException. It means the serialized composite contains more components than the type definition allows, i.e. the data does not fit the schema.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/CompositeType.java:305

            V decoded = type.fromComparableBytes(accessor,
                                                 ByteSourceInverse.nextComponentSource(comparableBytes, separator),
                                                 version);
            buffers[i++] = decoded;

            lastEoc = ByteSourceInverse.getSignedByte(ByteSourceInverse.nextComponentSource(comparableBytes));
        }
        return build(accessor, isStatic, Arrays.copyOf(buffers, i), lastEoc);
    }

    protected ParsedComparator parseComparator(int i, String part)
    {
        return new StaticParsedComparator(types.get(i), part);
    }

    protected <V> AbstractType<?> validateComparator(int i, V value, ValueAccessor<V> accessor, int offset) throws MarshalException
    {
        if (i >= types.size())
            throw new MarshalException("Too many bytes for comparator");
        return types.get(i);
    }

    protected <V> int getComparatorSize(int i, V value, ValueAccessor<V> accessor, int offset)
    {
        return 0;
    }

    public ByteBuffer decompose(Object... objects)
    {
        assert objects.length == types.size() : String.format("Expected length %d but given %d", types.size(), objects.length);

        ByteBuffer[] serialized = new ByteBuffer[objects.length];
        for (int i = 0; i < objects.length; i++)
        {
            ByteBuffer buffer = ((AbstractType) types.get(i)).decompose(objects[i]);
            serialized[i] = buffer;
        }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Fix the schema so the type list covers all serialized components
  2. Rewrite/scrub SSTables that contain composites written under the old schema
  3. Inspect the offending values with sstabledump to confirm the component count
  4. Restore schema from backup if the change was accidental
Defensive patterns

Strategy: validation

Validate before calling

boolean fitsSchema(CompositeType ct, ByteBuffer composite) { int count = 0; /* decode component count and compare to ct.types.size() */ return count <= ct.types.size(); }

Try / catch

try { compositeType.validate(value); } catch (MarshalException e) { /* handle 'Too many bytes for comparator' as schema mismatch */ }

Prevention

When it happens

Trigger: Validating a composite value whose serialized form has more encoded components than types.size(); validation triggered on read/write of rows written under an older, wider comparator schema.

Common situations: Comparator redefinition after data was written; corruption or truncation of type metadata; manual SSTable manipulation.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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