apache/cassandra · error · MarshalException
Not enough bytes to read a vector<
Error message
Not enough bytes to read a vector<%s, %d>
What it means
VectorType's unpack reads 'dimension' fixed-length elements from the buffer; if fewer bytes remain than one element's fixed length for any element, it throws this MarshalException. The serialized form of a fixed-length vector must contain exactly dimension elements of elementSize bytes each.
Solutions
- Verify the input buffer size equals or exceeds dimension * elementType.valueLengthIfFixed() before unpacking
- Confirm the vector column dimension matches the data as written (did not change since write)
- Scrub/repair affected SSTables if storage data is truncated; restore from backup if corruption is confirmed
Example fix
// before
if (buffer.remaining() < dimension * elementSize) throw new IllegalArgumentException("truncated vector");
vectorType.unpack(buffer);
// after
int elementSize = elementType.valueLengthIfFixed();
if (buffer.remaining() < dimension * elementSize) throw new IllegalArgumentException("truncated vector");
vectorType.unpack(buffer); Defensive patterns
Strategy: validation
Validate before calling
if (buffer.remaining() < dimension * elementType.valueLengthIfFixed()) throw new IllegalArgumentException("truncated vector payload"); Try / catch
try { vectorType.unpack(buffer); } catch (MarshalException e) { log.error("cannot unpack vector: {}", e.getMessage()); return null; } Prevention
- Validate payload length before deserialization
- Keep schema dimension stable; migrate data when it changes
- Scrub/repair storage if truncation is observed repeatedly
When it happens
Trigger: unpack called on a buffer shorter than dimension * elementLength (elementLength > 0, i.e. fixed-length element types like int/float); truncated values from storage or network; dimension increased in schema while old data remains short.
Common situations: Truncated SSTable/commit-log data; schema dimension mismatch after ALTER of vector dimension; hand-crafted buffers in tests; partial reads from a custom transport.
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
- Invalid empty vector value
- Not enough bytes to read a + getCollectionName()
- Not enough bytes to read a
- Unexpected extraneous bytes after value
- Attempted to add float vector of dimension
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/011cd5507b6b6b24.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/VectorType.java:474
return rc;
offset += elementLength;
}
return 0;
}
@Override
public <V> List<V> unpack(V buffer, ValueAccessor<V> accessor)
{
if (isNull(buffer, accessor))
return null;
List<V> result = new ArrayList<>(dimension);
int offset = 0;
int elementLength = elementType.valueLengthIfFixed();
for (int i = 0; i < dimension; i++)
{
if (accessor.sizeFromOffset(buffer, offset) < elementLength)
throw new MarshalException(String.format("Not enough bytes to read a vector<%s, %d>", elementType.asCQL3Type(), dimension));
V bb = accessor.slice(buffer, offset, elementLength);
offset += elementLength;
elementSerializer.validate(bb, accessor);
result.add(bb);
}
checkConsumedFully(buffer, accessor, offset);
return result;
}
@Override
public <V> V pack(List<V> value, ValueAccessor<V> accessor)
{
if (value == null)
rejectNullOrEmptyValue();
check(value);View on GitHub (pinned to 88fd0f6a0e)