Repository navigation
[fix][client] Support nack, ackTimeout redelivery and dlq for chunked messages - #604
Conversation
|
Just a heads up - I was testing out chunked messages from the C++ API today, and noticed that the |
@oversearch I don't have immediate plans to add chunk configuration support to However, I agree it makes sense to add these options — since Reader is internally backed by an exclusive consumer, the chunk-related parameters ( |
Updates the fork to apache/pulsar-client-cpp main at f71d7e9 (108 new upstream commits). The tree is identical to the fork commits rebased onto that main, branch `clickhouse-rebased-on-upstream-main` in groeneai/pulsar-client-cpp: - dropped, already upstream: 12d621f (backport of apache#441) and 931d125 (backport of apache#438); - adapted to upstream changes: the connection validator and the frame validation use the `Error` type of apache#579; the chunk validation, the chunk bookkeeping bounds and the redelivery of abandoned chunks are adapted to the `processMessageChunk` refactoring of apache#587 and apache#604. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation
Prior to this change, the C++ client did not properly handle chunked messages in the following scenarios:
ChunkMessageIdwas nacked, without expanding all chunk entries. The broker would only redeliver the last chunk entry, making it impossible for the consumer to reassemble the complete message.UnAckedMessageTrackercalleddiscardBatch()onChunkMessageIdImpl, which created a new plainMessageIdImpland lost all internal chunk entry information. When ack timeout triggered, the tracker could not expand chunk entries for redelivery.This aligns the C++ client behavior with the Go and Java clients, which already handle these scenarios correctly.
Modifications
lib/ConsumerImpl.ccnegativeAcknowledge()— When the MessageId is aChunkMessageIdImpl, expand all chunk entries viagetChunkedMessageIds()and add each one individually tonegativeAcksTracker_. This ensures the broker redelivers all chunks.redeliverMessages()— Before sendingRedeliverUnacknowledgedMessagesto the broker, expand anyChunkMessageIdImplin the input set into all its chunk entries. This is the path triggered by ack timeout.DLQ producer configuration — Enable
setChunkingEnabled(true)for the DLQ producer so that large messages can be correctly chunked when sent to the DLQ topic.lib/UnAckedMessageTrackerEnabled.ccadd()method — SkipdiscardBatch()forChunkMessageIdImpl.discardBatch()creates a new plainMessageIdImpl, which would lose thechunkedMessageIds_vector stored insideChunkMessageIdImpl. By preserving the original object, when ack timeout triggers and the MessageId is passed toredeliverMessages(), it can be dynamically cast back toChunkMessageIdImpland expanded into all chunk entries.remove()method — Apply the same logic asadd()to ensure consistent key lookup and removal from the tracker.tests/MessageChunkingTest.cctestNegativeAckChunkedMessage— Verifies that a chunked message can be correctly redelivered after nack (aligned with GoTestChunkAckAndNAckand JavatestNegativeAckChunkedMessage).testAckTimeoutChunkedMessage— Verifies that a chunked message can be correctly redelivered after ack timeout (aligned with JavatestLargeMessageAckTimeOut).testChunkedMessageDLQ— Verifies that a chunked message is correctly sent to the DLQ topic after exceedingmaxRedeliverCount, with complete message content and correctPROPERTY_ORIGIN_MESSAGE_IDandSYSTEM_PROPERTY_REAL_TOPICproperties.Design Details
Why skip
discardBatch()forChunkMessageIdImpl?discardBatch()creates a newMessageIdImplretaining onlyledgerId,entryId, andpartitionIndex, discardingbatchIndexandbatchSize. ForChunkMessageIdImpl(a subclass ofMessageIdImpl), this would also lose thechunkedMessageIds_vector that stores all chunk entry positions. Without this information, the client cannot expand chunk entries for redelivery when ack timeout fires.Note:
ChunkMessageIdImplalready hasbatchIndex = -1(chunked messages are not batched), so skippingdiscardBatch()does not affect the key normalization purpose (deduplicating batch sub-entries in the tracker).Broker perspective
The broker does not recognize chunk message semantics. Each chunk is an independent entry in the managed ledger. The client is responsible for expanding all chunk entries when requesting redelivery, so the broker can replay all positions belonging to the same chunked message.
Comparison with Go and Java clients
ChunkMessageIdImpl.chunkedMessageIds_unAckedChunkedMessageIdSequenceMapunAckChunksTrackernegativeAcknowledge()entryNegativeAcksTrackertimeoutNackID()entryredeliverMessages()UnAckedMessageTrackertimeout callbackdynamic_pointer_castcheckinstanceof ChunkMessageIdImplchecksetChunkingEnabled(true)chunkingEnabled(true)WithChunking(true)All three clients achieve the same result: expand all chunk entries and send them to the broker for complete redelivery.
Local workflow
geniusjoe#2
