[issue 447] double check message size when client enable compress#806
[issue 447] double check message size when client enable compress#806cocktail828 wants to merge 3 commits into
Conversation
pgier
left a comment
There was a problem hiding this comment.
LGTM, just had one in-line suggestion.
|
Hello, I think this problem may be resolved in #805 . |
update: "a short-circuit and will work here" Co-authored-by: Paul Gier <paul.gier@datastax.com>
|
|
||
| // if msg is too large | ||
| if len(payload) > int(p._getConn().GetMaxMessageSize()) { | ||
| if len(payload) > int(p._getConn().GetMaxMessageSize()) && |
There was a problem hiding this comment.
Seems that in this PR we do the compression twice when sending the message. The batch builder will do the compression here: https://github.com/apache/pulsar-client-go/blob/master/pulsar/internal/commands.go#L251
Could we move the compression from the batch builder to here?
There was a problem hiding this comment.
Yep, this modification just an translation the implement of https://github.com/apache/pulsar/blob/782132561ac9fc8430ae3ef12913999e5871d3d2/pulsar-client-cpp/lib/ProducerImpl.cc#L431.
It indeed do compress twice.
// Wire format
// [TOTAL_SIZE] [CMD_SIZE][CMD] [MAGIC_NUMBER][CHECKSUM] [PAYLOAD]
// |
// compressed or uncompressed {[METADATA_SIZE_0] [METADATA_0] [PAYLOAD_0]} ...
Acording to the wire format above, SDK cannot compress messages one by one but should compress the whole batchs together.
Another way to avoid 'twice-compress', I think is flushing batchs immediately before and after add big message to batchBuilder.
|
Is it possible to add some tests to verify it? |
Hi @Gleiphir2769, according to the implement of Java-Client, it should also check 'encryptedPayload' not only the payload in 'ProducerMessage'. |
You are right. In the Java Client it checks "encryptedPayload" in batching. But Java Client only checks the "encryptedPayload" before sending when batching enabled, which means it will not check |

Fixes #447
Motivation
Try to fix issue #447.
Modifications
Compress the payload when the payload is too bigger, and check whever the 'compressed payload' is still bigger than expected.