Skip to content

[Issue 456] Support chunking for big messages. - #805

Merged
RobertIndie merged 44 commits into
apache:masterfrom
Gleiphir2769:chunking_issue_456
Oct 25, 2022
Merged

RobertIndie merged 44 commits into
apache:masterfrom
Gleiphir2769:chunking_issue_456

Conversation

@Gleiphir2769

@Gleiphir2769 Gleiphir2769 commented Jul 10, 2022 •

Copy link
Copy Markdown
Contributor

Contribution Checklist

Master Issue: #456

Motivation

Make pulsar go client support chunking to produce/consume big messages. The earlier implementation (#717) didn't take into account many details, so I decided to reimplement it.

Modifications

  • Add internalSingleSend to send message without batch because batch message will not be received by chunk.
  • Moved BlockIfQueueFull check from internalSendAsync to internalSend (canAddQueue) to ensure the normal block in chunking.
  • Make producer send big messages by chunking.
  • Add chunkedMsgCtxMap to store chunked messages meta and data.
  • Make consumer can obtain chunks and consume the big message.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Add TestProducerChunking to verify send big message by chunking.
  • Add message_chunking_test to verify message chunking.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? not yet

@zzzming zzzming left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on Java implementation, ConsumerImpl.java, Chunking also requires changes at the consumer side to be able to assembly chunks into the original message. Are you going to add support on the consumer side?

@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

Based on Java implementation, ConsumerImpl.java, Chunking also requires changes at the consumer side to be able to assembly chunks into the original message. Are you going to add support on the consumer side?

The consumer side implement is already planned. It will be commited in another PR.

…g of sequenceID generate; fix the bug where batch messages are compressed twice; add internal error handle, fix inaccurate PublishErrorsMsgTooLarge metric; fix the incorrect producer queueFullBlock
@Gleiphir2769 Gleiphir2769 changed the title [Issue 456] Support chunking to produce big messages. [Issue 456] Support chunking for big messages. Aug 6, 2022
@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

Based on Java implementation, ConsumerImpl.java, Chunking also requires changes at the consumer side to be able to assembly chunks into the original message. Are you going to add support on the consumer side?

Hi, the consumer side is implemented here. Looking forward to your review. @zzzming

Comment thread pulsar/producer.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/consumer.go Resolved
@Gleiphir2769

Gleiphir2769 commented Oct 16, 2022 •

Copy link
Copy Markdown
Contributor Author

This PR will be possible to fix this issue #447.

Comment thread pulsar/consumer_partition.go Resolved
@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@nodece nodece left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR seems to have made improvements unrelated to chunking, if so, I suggest you make a new PR to improve.

Comment thread pulsar/consumer_impl.go

if mid.consumer != nil {
return mid.Ack()
if err := c.checkMsgIDPartition(msgID); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed covert the msgID from the MessageID to the trackingMessageID type, I'm not sure if we need this.

Why not use messageID(), what did I miss?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trackingMessageID does not records chunking infomation.

For example, Ack() a big message need to ack all the chunks of it. Using trackingMessageID can not figure out which chunk (messageId) need to be ack.

trackingMessageID is designed to tracking batch messages so it shoud not be the messageId type accepted by the method exposed by partitionConsumer. I think the better way would be to accept MessageID as the messageId type in partitionConsumer methods. However, only the necessary interfaces have been modified (Ack, NAck and Seed) for the least changes

Comment thread pulsar/consumer_impl.go Resolved
Comment thread pulsar/consumer_impl.go Resolved
Comment thread pulsar/consumer_partition.go Resolved
}
msgSize := uint32(len(payload))
return bc.numMessages+1 <= bc.maxMessages && bc.buffer.ReadableBytes()+msgSize <= uint32(bc.maxBatchSize)
expectedSize := bc.buffer.ReadableBytes() + msgSize

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this code(170-174).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L171 compared the bc.buffer.ReadableBytes() + msgSize with bc.maxMessageSize and the original code does not.

It used to make sure that one batch size does not exceed the maxMessageSize. It's a part of correctly calculation whether the message is too large.

By the way, the compare code is too long to be inline.

@nodece nodece Oct 24, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but using inline looks like more clear, so like:

return bc.numMessages+1 <= bc.maxMessages && expectedSize <= uint32(bc.maxBatchSize) && expectedSize <= bc.maxMessageSize

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nodece This PR introduces the maxMessageSize. I think these changes should be related to this PR.

@Gleiphir2769 Gleiphir2769 Oct 24, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but using inline looks like more clear, so like:

return bc.numMessages+1 <= bc.maxMessages && expectedSize <= uint32(bc.maxBatchSize) && expectedSize <= bc.maxMessageSize

Done, thx.

Comment thread pulsar/producer_partition.go Resolved
@nodece
nodece requested review from merlimat and wolfstudy October 24, 2022 09:50
@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@maraiskruger1980

Copy link
Copy Markdown
Contributor

Does the chunking work on shared subscription introduced in Pulsar 2.11?

@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

Does the chunking work on shared subscription introduced in Pulsar 2.11

Hi @maraiskruger1980, This PR is finished when pulsar 2.11 has not been released. So it doesn't support shared subscription chunking.

I think I can take some time on it. Welcome to follow the progress.

@maraiskruger1980

Copy link
Copy Markdown
Contributor

That will be great if it can support shared subscription

@Gleiphir2769

Copy link
Copy Markdown
Contributor Author

That will be great if it can support shared subscription

Hi @maraiskruger1980. After I checked, it does no limit in consumer when subscription is shared. Which means you can safely consume chunking messages in shared subscribtion if your pulsar version >= 2.11.

RobertIndie pushed a commit that referenced this pull request Jun 29, 2026
…tion tests (#1511)

Master Issue: apache/pulsar#21048

Related Issue: #805

### Motivation

In the Java SDK (PR apache/pulsar#21048), the DLQ/RLQ producers are hardcoded with
`enableBatching(false).enableChunking(true)` to ensure large chunked messages can be forwarded to DLQ/RLQ
topics successfully.

However, in the Go SDK, the DLQ/RLQ producers are created using `DLQPolicy.ProducerOptions`, which defaults
to a zero-value `ProducerOptions{}` (i.e., `EnableChunking: false`, `DisableBatching: false`). This means
that if a producer sends a chunked message larger than the broker's `maxMessageSize`, and the consumer is
configured with DLQ/RLQ, the DLQ/RLQ producer will fail to forward the message because it cannot chunk it.

We considered automatically enabling chunking in the DLQ/RLQ producers when the user has not explicitly
configured `ProducerOptions`. However, since `EnableChunking` and `DisableBatching` are both `bool` fields
with a zero value of `false`, there is no way to distinguish between:
- The user intentionally setting them to `false` (meaning "I don't want chunking")
- The user not configuring them at all (meaning "I didn't think about it")

Automatically overriding these values would break backward compatibility for users who explicitly set
`EnableChunking: false`. Therefore, instead of changing the default behavior, we add documentation to
guide users to enable chunking in `DLQPolicy.ProducerOptions` when using chunked messages with DLQ/RLQ.

### Modifications

- Added a note to the `EnableChunking` field documentation in `ProducerOptions` (`producer.go`) explaining
  that when chunking is enabled and the consumer uses DLQ/RLQ, it is recommended to also enable chunking
  in `DLQPolicy.ProducerOptions`.
- Added a note to the `DLQPolicy.ProducerOptions` field documentation (`consumer.go`) explaining that if
  the messages being consumed were produced with chunking enabled, it is recommended to also enable chunking
  here. This helps in decoupled producer/consumer scenarios where the consumer developer may not be aware
  of the producer's chunking configuration.
- Added `TestChunkReconsumeLater` integration test to verify chunked messages (5MB, exceeding broker
  maxMessageSize) can be sent to the retry topic via `ReconsumeLater` and routed to DLQ after exceeding
  max retries, when `DLQPolicy.ProducerOptions` has chunking enabled.
- Added `TestChunkDLQWithNack` integration test to verify chunked messages (5MB) are routed to DLQ
  after exceeding max redelivery count via `Nack`, when `DLQPolicy.ProducerOptions` has chunking enabled.

### Verifying this change

This change added tests and can be verified as follows:

- Added `TestChunkReconsumeLater`: sends a 5MB chunked message, verifies it flows through retry topic
  via `ReconsumeLater` and eventually lands in DLQ after exceeding `MaxDeliveries`.
- Added `TestChunkDLQWithNack`: sends a 5MB chunked message, verifies it is routed to DLQ after
  exceeding max redelivery count via `Nack`, with original properties preserved.

Both tests use payloads larger than broker `maxMessageSize` (~1MB) to ensure that DLQ/RLQ producers
**must** have chunking enabled to successfully forward messages. Without chunking enabled in
`DLQPolicy.ProducerOptions`, these tests would timeout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants