use of org.apache.kafka.common.InvalidRecordException in project kafka by apache.
the class EndTransactionMarker method deserializeValue.
static EndTransactionMarker deserializeValue(ControlRecordType type, ByteBuffer value) {
ensureTransactionMarkerControlType(type);
if (value.remaining() < CURRENT_END_TXN_MARKER_VALUE_SIZE)
throw new InvalidRecordException("Invalid value size found for end transaction marker. Must have " + "at least " + CURRENT_END_TXN_MARKER_VALUE_SIZE + " bytes, but found only " + value.remaining());
short version = value.getShort(0);
if (version < 0)
throw new InvalidRecordException("Invalid version found for end transaction marker: " + version + ". May indicate data corruption");
if (version > CURRENT_END_TXN_MARKER_VERSION)
log.debug("Received end transaction marker value version {}. Parsing as version {}", version, CURRENT_END_TXN_MARKER_VERSION);
int coordinatorEpoch = value.getInt(2);
return new EndTransactionMarker(type, coordinatorEpoch);
}
use of org.apache.kafka.common.InvalidRecordException in project kafka by apache.
the class DefaultRecord method readHeaders.
private static Header[] readHeaders(ByteBuffer buffer, int numHeaders) {
Header[] headers = new Header[numHeaders];
for (int i = 0; i < numHeaders; i++) {
int headerKeySize = ByteUtils.readVarint(buffer);
if (headerKeySize < 0)
throw new InvalidRecordException("Invalid negative header key size " + headerKeySize);
ByteBuffer headerKeyBuffer = buffer.slice();
headerKeyBuffer.limit(headerKeySize);
buffer.position(buffer.position() + headerKeySize);
ByteBuffer headerValue = null;
int headerValueSize = ByteUtils.readVarint(buffer);
if (headerValueSize >= 0) {
headerValue = buffer.slice();
headerValue.limit(headerValueSize);
buffer.position(buffer.position() + headerValueSize);
}
headers[i] = new RecordHeader(headerKeyBuffer, headerValue);
}
return headers;
}
use of org.apache.kafka.common.InvalidRecordException in project kafka by apache.
the class DefaultRecord method readFrom.
public static DefaultRecord readFrom(ByteBuffer buffer, long baseOffset, long baseTimestamp, int baseSequence, Long logAppendTime) {
int sizeOfBodyInBytes = ByteUtils.readVarint(buffer);
if (buffer.remaining() < sizeOfBodyInBytes)
throw new InvalidRecordException("Invalid record size: expected " + sizeOfBodyInBytes + " bytes in record payload, but instead the buffer has only " + buffer.remaining() + " remaining bytes.");
int totalSizeInBytes = ByteUtils.sizeOfVarint(sizeOfBodyInBytes) + sizeOfBodyInBytes;
return readFrom(buffer, totalSizeInBytes, sizeOfBodyInBytes, baseOffset, baseTimestamp, baseSequence, logAppendTime);
}
use of org.apache.kafka.common.InvalidRecordException in project kafka by apache.
the class SenderTest method testRecordErrorPropagatedToApplication.
@Test
public void testRecordErrorPropagatedToApplication() throws InterruptedException {
int recordCount = 5;
setup();
Map<Integer, FutureRecordMetadata> futures = new HashMap<>(recordCount);
for (int i = 0; i < recordCount; i++) {
futures.put(i, appendToAccumulator(tp0));
}
// send request
sender.runOnce();
assertEquals(1, client.inFlightRequestCount());
assertEquals(1, sender.inFlightBatches(tp0).size());
OffsetAndError offsetAndError = new OffsetAndError(-1L, Errors.INVALID_RECORD, Arrays.asList(new BatchIndexAndErrorMessage().setBatchIndex(0).setBatchIndexErrorMessage("0"), new BatchIndexAndErrorMessage().setBatchIndex(2).setBatchIndexErrorMessage("2"), new BatchIndexAndErrorMessage().setBatchIndex(3)));
client.respond(produceResponse(Collections.singletonMap(tp0, offsetAndError)));
sender.runOnce();
for (Map.Entry<Integer, FutureRecordMetadata> futureEntry : futures.entrySet()) {
FutureRecordMetadata future = futureEntry.getValue();
assertTrue(future.isDone());
KafkaException exception = TestUtils.assertFutureThrows(future, KafkaException.class);
Integer index = futureEntry.getKey();
if (index == 0 || index == 2) {
assertTrue(exception instanceof InvalidRecordException);
assertEquals(index.toString(), exception.getMessage());
} else if (index == 3) {
assertTrue(exception instanceof InvalidRecordException);
assertEquals(Errors.INVALID_RECORD.message(), exception.getMessage());
} else {
assertEquals(KafkaException.class, exception.getClass());
}
}
}
Aggregations