Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

Master issue: #87

Motivation

To support batch index acknowledgment, we must provide a method to get the batch size of a batched message ID.

Modifications

Instead of adding another overload constructor to MessageId, this PR adds a MessageIdBuilder class to construct the MessageId in a more elegant way.

The original constructor is counterintuitive because the partition index is the 1st argument.

explicit MessageId(int32_t partition, int64_t ledgerId, int64_t entryId, int32_t batchIndex);

Therefore, this PR marks it as deprecated and replace all invocations of it with the MessageIdBuilder usages.

To verify the MessageId::batchSize(), the following tests are modified:

  • BatchMessageTest.testBatchSizeInBytes: the batch size is always 2 because of the batchingMaxAllowedSizeInBytes config.
  • MessageChunkingTest.testEndToEnd: the batch size field is not set
    (default: 0) because batching is disabled.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

Master issue: apache#87

### Motivation

To support batch index acknowledgment, we must provide a method to get
the batch size of a batched message ID.

### Modifications

Instead of adding another overload constructor to `MessageId`, this PR
adds a `MessageIdBuilder` class to construct the `MessageId` in a more
elegant way.

The original constructor is counterintuitive because the partition
index is the 1st argument.

https://github.com/apache/pulsar-client-cpp/blob/74ef1a01f5c7a4604d251de6d040c433f9bbf56b/include/pulsar/MessageId.h#L47

Therefore, this PR marks it as deprecated and replace all invocations of
it with the `MessageIdBuilder` usages.

To verify the `MessageId::batchSize()`, the following tests are
modified:
- `BatchMessageTest.testBatchSizeInBytes`: the batch size is always 2
  because of the `batchingMaxAllowedSizeInBytes` config.
- `MessageChunkingTest.testEndToEnd`: the batch size field is not set
  (default: 0) because batching is disabled.
@BewareMyPower BewareMyPower added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 7, 2022
@BewareMyPower BewareMyPower added this to the 3.1.0 milestone Nov 7, 2022
@BewareMyPower BewareMyPower self-assigned this Nov 7, 2022
@BewareMyPower
Copy link
Contributor Author

@BewareMyPower
Copy link
Contributor Author

@merlimat @RobertIndie @Demogorgon314 PTAL. Though I opened a discussion here and reached a concensus that Java's MessageId is an opaque, the MessageId in C++ is still constructable from application side.

This PR mainly changes the construction from

// partition: 1, ledger: 2, entry: 3, batch index: 4
MessageId id(1, 2, 3, 4);

to

auto id = MessageIdBuilder().ledgerId(2).entryId(3).partition(1).batchIndex(4).build();

And support batch_size field.

@RobertIndie RobertIndie merged commit 1721e00 into apache:main Nov 14, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/message-id-batch-size branch December 4, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants