BewareMyPower commented on code in PR #15413:
URL: https://github.com/apache/pulsar/pull/15413#discussion_r867356067
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageKeyBasedContainer.java:
##########
@@ -49,37 +38,21 @@
*/
class BatchMessageKeyBasedContainer extends AbstractBatchMessageContainer {
- private Map<String, KeyedBatch> batches = new HashMap<>();
+ private final Map<String, BatchMessageContainerImpl> batches = new
HashMap<>();
@Override
public boolean add(MessageImpl<?> msg, SendCallback callback) {
if (log.isDebugEnabled()) {
log.debug("[{}] [{}] add message to batch, num messages in batch
so far is {}", topicName, producerName,
numMessagesInBatch);
}
- numMessagesInBatch++;
- currentBatchSizeBytes += msg.getDataBuffer().readableBytes();
String key = getKey(msg);
- KeyedBatch part = batches.get(key);
- if (part == null) {
- part = new KeyedBatch();
- part.addMsg(msg, callback);
- part.compressionType = compressionType;
- part.compressor = compressor;
- part.maxBatchSize = maxBatchSize;
- part.topicName = topicName;
- part.producerName = producerName;
- batches.putIfAbsent(key, part);
-
- if (msg.getMessageBuilder().hasTxnidMostBits() &&
currentTxnidMostBits == -1) {
- currentTxnidMostBits =
msg.getMessageBuilder().getTxnidMostBits();
- }
- if (msg.getMessageBuilder().hasTxnidLeastBits() &&
currentTxnidLeastBits == -1) {
- currentTxnidLeastBits =
msg.getMessageBuilder().getTxnidLeastBits();
- }
-
- } else {
- part.addMsg(msg, callback);
+ final BatchMessageContainerImpl batchMessageContainer =
batches.computeIfAbsent(key,
+ __ -> new BatchMessageContainerImpl(producer));
+ batchMessageContainer.add(msg, callback);
+ if (batchMessageContainer.isAdded()) {
Review Comment:
Yes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]