dengziming commented on code in PR #9766: URL: https://github.com/apache/kafka/pull/9766#discussion_r1979277342
########## clients/src/main/java/org/apache/kafka/common/record/EndTransactionMarker.java: ########## @@ -95,32 +76,35 @@ public int hashCode() { private static void ensureTransactionMarkerControlType(ControlRecordType type) { if (type != ControlRecordType.COMMIT && type != ControlRecordType.ABORT) - throw new IllegalArgumentException("Invalid control record type for end transaction marker" + type); + throw new IllegalArgumentException("Invalid control record type for end transaction marker " + type); } public static EndTransactionMarker deserialize(Record record) { ControlRecordType type = ControlRecordType.parse(record.key()); return deserializeValue(type, record.value()); } + // Visible for testing 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) + short version = value.getShort(); + if (version < EndTxnMarker.LOWEST_SUPPORTED_VERSION) throw new InvalidRecordException("Invalid version found for end transaction marker: " + version + ". May indicate data corruption"); - if (version > CURRENT_END_TXN_MARKER_VERSION) + if (version > EndTxnMarker.HIGHEST_SUPPORTED_VERSION) log.debug("Received end transaction marker value version {}. Parsing as version {}", version, - CURRENT_END_TXN_MARKER_VERSION); + EndTxnMarker.HIGHEST_SUPPORTED_VERSION); + EndTxnMarker marker = new EndTxnMarker(new ByteBufferAccessor(value), version); Review Comment: Oh, you are so careful about this, though it seems obscure, I agree with you that we should indeed use EndTxnMarker.HIGHEST_SUPPORTED_VERSION. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org