BewareMyPower commented on a change in pull request #14604:
URL: https://github.com/apache/pulsar/pull/14604#discussion_r832420382
##########
File path: pulsar-client-cpp/lib/ConsumerImpl.cc
##########
@@ -415,21 +411,40 @@ void ConsumerImpl::messageReceived(const
ClientConnectionPtr& cnx, const proto::
return;
}
}
-
+ std::shared_ptr<MessageId> chunkMessageId;
// Only a non-batched messages can be a chunk
if (!metadata.has_num_messages_in_batch() && isChunkedMessage) {
const auto& messageIdData = msg.message_id();
MessageId messageId(messageIdData.partition(),
messageIdData.ledgerid(), messageIdData.entryid(),
messageIdData.batch_index());
auto optionalPayload = processMessageChunk(payload, metadata,
messageId, messageIdData, cnx);
if (optionalPayload.is_present()) {
+ auto& chunkedMsgCtx =
chunkedMessageCache_.find(metadata.uuid())->second;
+ LOG_DEBUG("Chunked message completed chunkId: " <<
metadata.chunk_id()
+ << ",
ChunkedMessageCtx: " << chunkedMsgCtx
+ << ", sequenceId:
" << metadata.sequence_id());
+ if (chunkedMsgCtx.numChunks() > 0) {
+ auto firstMsgIdImplPtr =
chunkedMsgCtx.getChunkedMessageIds()[0].impl_;
+ auto lastMsgIdImplPtr =
+
chunkedMsgCtx.getChunkedMessageIds()[chunkedMsgCtx.numChunks() - 1].impl_;
+ chunkMessageId = std::make_shared<MessageId>(
+ MessageId(firstMsgIdImplPtr->partition_,
firstMsgIdImplPtr->ledgerId_,
+ firstMsgIdImplPtr->entryId_,
firstMsgIdImplPtr->batchIndex_),
+ MessageId(lastMsgIdImplPtr->partition_,
lastMsgIdImplPtr->ledgerId_,
+ lastMsgIdImplPtr->entryId_,
lastMsgIdImplPtr->batchIndex_));
+ }
+ chunkedMessageCache_.remove(metadata.uuid());
payload = optionalPayload.value();
} else {
return;
}
}
-
- Message m(msg, metadata, payload, partitionIndex_);
+ Message m;
+ if (chunkMessageId != nullptr) {
+ m = Message(*chunkMessageId, metadata, payload);
+ } else {
+ m = Message(msg, metadata, payload, partitionIndex_);
+ }
Review comment:
I think we can eliminate this overload constructor because it's a
private method, which can only be used internally.
```c++
Message(const proto::CommandMessage& msg, proto::MessageMetadata& data,
SharedBuffer& payload,
int32_t partition);
```
Instead, we can get a `MessageId` first and pass it to the `MessageId`'s
constructor.
```c++
const auto msgId = chunkMessageId ? (*chunkMessageId)
: MessageId(partitionIndex_,
msg.message_id().ledgerid(),
msg.message_id().entryid(), -1);
Message m(msgId, metadata, payload);
```
##########
File path: pulsar-client-cpp/lib/ConsumerImpl.cc
##########
@@ -415,21 +411,40 @@ void ConsumerImpl::messageReceived(const
ClientConnectionPtr& cnx, const proto::
return;
}
}
-
+ std::shared_ptr<MessageId> chunkMessageId;
// Only a non-batched messages can be a chunk
if (!metadata.has_num_messages_in_batch() && isChunkedMessage) {
const auto& messageIdData = msg.message_id();
MessageId messageId(messageIdData.partition(),
messageIdData.ledgerid(), messageIdData.entryid(),
messageIdData.batch_index());
auto optionalPayload = processMessageChunk(payload, metadata,
messageId, messageIdData, cnx);
if (optionalPayload.is_present()) {
+ auto& chunkedMsgCtx =
chunkedMessageCache_.find(metadata.uuid())->second;
+ LOG_DEBUG("Chunked message completed chunkId: " <<
metadata.chunk_id()
+ << ",
ChunkedMessageCtx: " << chunkedMsgCtx
+ << ", sequenceId:
" << metadata.sequence_id());
+ if (chunkedMsgCtx.numChunks() > 0) {
+ auto firstMsgIdImplPtr =
chunkedMsgCtx.getChunkedMessageIds()[0].impl_;
+ auto lastMsgIdImplPtr =
+
chunkedMsgCtx.getChunkedMessageIds()[chunkedMsgCtx.numChunks() - 1].impl_;
+ chunkMessageId = std::make_shared<MessageId>(
+ MessageId(firstMsgIdImplPtr->partition_,
firstMsgIdImplPtr->ledgerId_,
+ firstMsgIdImplPtr->entryId_,
firstMsgIdImplPtr->batchIndex_),
+ MessageId(lastMsgIdImplPtr->partition_,
lastMsgIdImplPtr->ledgerId_,
+ lastMsgIdImplPtr->entryId_,
lastMsgIdImplPtr->batchIndex_));
Review comment:
There is no need to convert two `MessageIdImpl`s to `MessageId`s and
then construct a new `MessageId`. We can achieve the same goal by:
```c++
chunkMessageId = std::make_shared<MessageId>();
chunkMessageId->impl_ =
std::make_shared<ChunkMessageIdImpl>(*firstMsgIdImplPtr,
*lastMsgIdImplPtr);
```
--
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]