apache / apache/pulsar-client-go

Transactional publishes do not set txn id in MessageMetadata

Open
#1,498 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
745
Forks
389
Avg merge
3d 20h
Merged PRs (30d)
3

Description

## 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

Contributor guide

Open the contributing guide

Research direction

Start in the producer send path where CommandSend and MessageMetadata are built, following ProducerMessage.Transaction for single-message and batch sends. Check the existing producer transaction tests or add focused coverage for metadata propagation and batch state. Done means transactional metadata carries both transaction-id parts, aborted messages stay invisible, and later non-transactional batches do not inherit the id.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.