Bug description
Transactional publishes currently put the transaction id on CommandSend, but the serialized MessageMetadata does not carry txnid_most_bits and txnid_least_bits for producer-created messages.
Because the broker-side transaction buffer uses the transaction id in message metadata to identify transactional entries, messages published inside a transaction can be treated as normal visible messages. In particular, after aborting the transaction, those messages may still be delivered to consumers.
Expected behavior
Messages published with ProducerMessage.Transaction should include the transaction id in MessageMetadata as well as in CommandSend, so aborted transaction messages remain invisible and are removed by the transaction buffer.
Actual behavior
The producer resolves the transaction id for send commands, but does not copy it into MessageMetadata for single-message sends or batch metadata.
Suggested fix
When a send request has a transaction:
- set
MessageMetadata.TxnidMostBits and MessageMetadata.TxnidLeastBits for single-message sends
- set the same fields on batch-level
MessageMetadata when the first message in a batch is transactional
- clear the batch transaction fields after flushing so a later non-transactional batch cannot inherit them
Bug description
Transactional publishes currently put the transaction id on
CommandSend, but the serializedMessageMetadatadoes not carrytxnid_most_bitsandtxnid_least_bitsfor producer-created messages.Because the broker-side transaction buffer uses the transaction id in message metadata to identify transactional entries, messages published inside a transaction can be treated as normal visible messages. In particular, after aborting the transaction, those messages may still be delivered to consumers.
Expected behavior
Messages published with
ProducerMessage.Transactionshould include the transaction id inMessageMetadataas well as inCommandSend, so aborted transaction messages remain invisible and are removed by the transaction buffer.Actual behavior
The producer resolves the transaction id for send commands, but does not copy it into
MessageMetadatafor single-message sends or batch metadata.Suggested fix
When a send request has a transaction:
MessageMetadata.TxnidMostBitsandMessageMetadata.TxnidLeastBitsfor single-message sendsMessageMetadatawhen the first message in a batch is transactional