You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "RobertIndie (via GitHub)" <gi...@apache.org> on 2023/09/27 03:00:58 UTC

[GitHub] [pulsar-client-cpp] RobertIndie opened a new pull request, #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

RobertIndie opened a new pull request, #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321

   <!--
   ### Contribution Checklist
     
     - PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*. 
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   -->
   
   Fixes #320
   
   
   ### Motivation
   
   Currently, the consumer only acknowledges the last chunk message ID. This will lead to some messages not being acknowledged and the message backlog doesn't get cleaned up.
   
   ### Modifications
   
   Add the chunk message Id list into the ChunkedMessageIdImpl. When the consumer acknowledges a chunked message , it will acknowledge all message Ids in that list
   
   ### Verifying this change
   
   This change is already covered by existing tests.
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
   
   - [x] `doc-not-needed` 
   (Please explain why)
   
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1338367787


##########
lib/ConsumerImpl.cc:
##########
@@ -1165,6 +1164,9 @@ bool ConsumerImpl::isCumulativeAcknowledgementAllowed(ConsumerType consumerType)
 
 std::pair<MessageId, bool> ConsumerImpl::prepareIndividualAck(const MessageId& messageId) {
     auto messageIdImpl = Commands::getMessageIdImpl(messageId);
+    if (std::dynamic_pointer_cast<ChunkMessageIdImpl>(messageIdImpl)) {
+        return std::make_pair(messageId, true);

Review Comment:
   Why not fall through to the following if branch?
   
   ```c++
       auto batchedMessageIdImpl = std::dynamic_pointer_cast<BatchedMessageIdImpl>(messageIdImpl);
   
       auto batchSize = messageId.batchSize();
       if (!batchedMessageIdImpl || batchedMessageIdImpl->ackIndividual(messageId.batchIndex())) {
           consumerStatsBasePtr_->messageAcknowledged(ResultOk, CommandAck_AckType_Individual,
                                                      (batchSize > 0) ? batchSize : 1);
           unAckedMessageTrackerPtr_->remove(messageId);
           possibleSendToDeadLetterTopicMessages_.remove(messageId);
   ```
   
   We can check if it's a `ChunkmessageIdImpl` before returning so that we won't call `discardBatch` on a `ChunkmessageIdImpl`.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix] Fix consumer doesn't acknowledge all chunk message Ids [pulsar-client-cpp]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1349457311


##########
lib/ChunkMessageIdImpl.h:
##########
@@ -28,21 +28,21 @@ class ChunkMessageIdImpl;
 typedef std::shared_ptr<ChunkMessageIdImpl> ChunkMessageIdImplPtr;
 class ChunkMessageIdImpl : public MessageIdImpl, public std::enable_shared_from_this<ChunkMessageIdImpl> {
    public:
-    ChunkMessageIdImpl() : firstChunkMsgId_(std::make_shared<MessageIdImpl>()) {}
-
-    void setFirstChunkMessageId(const MessageId& msgId) { *firstChunkMsgId_ = *msgId.impl_; }
-
-    void setLastChunkMessageId(const MessageId& msgId) {
-        this->ledgerId_ = msgId.ledgerId();
-        this->entryId_ = msgId.entryId();
-        this->partition_ = msgId.partition();
+    explicit ChunkMessageIdImpl(std::vector<MessageId>&& chunkedMessageIds)
+        : chunkedMessageIds_(std::move(chunkedMessageIds)) {
+        auto lastChunkMsgId = chunkedMessageIds_.back();
+        this->ledgerId_ = lastChunkMsgId.ledgerId();
+        this->entryId_ = lastChunkMsgId.entryId();
+        this->partition_ = lastChunkMsgId.partition();
     }
 
-    std::shared_ptr<const MessageIdImpl> getFirstChunkMessageId() const { return firstChunkMsgId_; }
+    const std::vector<MessageId>& getChunkedMessageIds() const noexcept { return chunkedMessageIds_; }
+
+    std::vector<MessageId> moveChunkedMessageIds() noexcept { return std::move(chunkedMessageIds_); }

Review Comment:
   ```suggestion
   ```
   
   This method is never used.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1338381431


##########
lib/ProducerImpl.cc:
##########
@@ -912,10 +912,9 @@ bool ProducerImpl::ackReceived(uint64_t sequenceId, MessageId& rawMessageId) {
 
     if (op.chunkedMessageId) {
         // Handling the chunk message id.
-        if (op.chunkId == 0) {
-            op.chunkedMessageId->setFirstChunkMessageId(messageId);
-        } else if (op.chunkId == op.numChunks - 1) {
-            op.chunkedMessageId->setLastChunkMessageId(messageId);
+        op.chunkMessageIdList.push_back(messageId);
+        if (op.chunkId == op.numChunks - 1) {
+            op.chunkedMessageId->setChunkedMessageIds(std::move(op.chunkMessageIdList));
             messageId = op.chunkedMessageId->build();

Review Comment:
   BTW, this logic seems wrong? We create `OpSendMsgs` for each single chunk. It seems that `op.chunkMessageIdList` still has 1 item.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1338335895


##########
lib/ProducerImpl.cc:
##########
@@ -912,10 +912,9 @@ bool ProducerImpl::ackReceived(uint64_t sequenceId, MessageId& rawMessageId) {
 
     if (op.chunkedMessageId) {

Review Comment:
   It seems that `OpSendMsg::chunkedMessageId` field is not necessary. It's added just to indicate if the current `OpSendMsg` is related to a chunk. But `OpSendMsg::numChunks` can also be used for that.
   
   Without saving an empty `ChunkMessageIdImpl`, we can just merge `setChunkedMessageIds` to the current constructor:
   
   ```c++
       ChunkMessageIdImpl(std::vector<MessageId>&& chunkedMessageIds)
           : chunkedMessageIds_(std::move(chunkedMessageIds)) {
           auto lastChunkMsgId = chunkedMessageIds_.back();
           this->ledgerId_ = lastChunkMsgId.ledgerId();
           this->entryId_ = lastChunkMsgId.entryId();
           this->partition_ = lastChunkMsgId.partition();
       }
   ```
   
   After that, in `ConsumerImpl` we can write:
   
   ```c++
       ChunkMessageIdImplPtr chunkMsgId =
           std::make_shared<ChunkMessageIdImpl>(chunkedMsgCtx.moveChunkedMessageIds());
   ```
   
   and in `ProducerImpl`:
   
   ```c++
       if (op.numChunks > 1) {
           // Handling the chunk message id.
           op.chunkMessageIdList.push_back(messageId);
           if (op.chunkId == op.numChunks - 1) {
               auto chunkedMessageId = std::make_shared<ChunkMessageIdImpl>(std::move(op.chunkMessageIdList));
               messageId = chunkedMessageId->build();
           }
   ```



##########
lib/ChunkMessageIdImpl.h:
##########
@@ -30,19 +30,24 @@ class ChunkMessageIdImpl : public MessageIdImpl, public std::enable_shared_from_
    public:
     ChunkMessageIdImpl() : firstChunkMsgId_(std::make_shared<MessageIdImpl>()) {}
 
-    void setFirstChunkMessageId(const MessageId& msgId) { *firstChunkMsgId_ = *msgId.impl_; }
+    void setChunkedMessageIds(std::vector<MessageId>&& chunkedMessageIds) {
+        chunkedMessageIds_ = std::move(chunkedMessageIds);
+        auto lastChunkMsgId = chunkedMessageIds_.back();
+        this->ledgerId_ = lastChunkMsgId.ledgerId();
+        this->entryId_ = lastChunkMsgId.entryId();
+        this->partition_ = lastChunkMsgId.partition();
+    }
 
-    void setLastChunkMessageId(const MessageId& msgId) {
-        this->ledgerId_ = msgId.ledgerId();
-        this->entryId_ = msgId.entryId();
-        this->partition_ = msgId.partition();
+    std::shared_ptr<const MessageIdImpl> getFirstChunkMessageId() const {
+        return chunkedMessageIds_.front().impl_;
     }
 
-    std::shared_ptr<const MessageIdImpl> getFirstChunkMessageId() const { return firstChunkMsgId_; }
+    std::vector<MessageId> moveChunkedMessageIds() noexcept { return std::move(chunkedMessageIds_); }
 
     MessageId build() { return MessageId{std::dynamic_pointer_cast<MessageIdImpl>(shared_from_this())}; }
 
    private:
     std::shared_ptr<MessageIdImpl> firstChunkMsgId_;

Review Comment:
   This field becomes useless after having the `chunkedMessageIds_`.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1338358971


##########
lib/AckGroupingTracker.cc:
##########
@@ -42,6 +44,14 @@ void AckGroupingTracker::doImmediateAck(const MessageId& msgId, ResultCallback c
         }
         return;
     }
+    if (auto chunkMessageId =
+            std::dynamic_pointer_cast<ChunkMessageIdImpl>(Commands::getMessageIdImpl(msgId))) {
+        auto msgIdList = chunkMessageId->moveChunkedMessageIds();
+        doImmediateAck(std::set<MessageId>(std::make_move_iterator(msgIdList.begin()),
+                                           std::make_move_iterator(msgIdList.end())),

Review Comment:
   If the `ackType` is cumulative, we should acknowledge the last message id cumulatively instead of acknowledging all message ids individually.
   



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] shibd commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "shibd (via GitHub)" <gi...@apache.org>.
shibd commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1339471012


##########
lib/AckGroupingTracker.cc:
##########
@@ -84,29 +94,43 @@ void AckGroupingTracker::doImmediateAck(const std::set<MessageId>& msgIds, Resul
         return;
     }
 
+    std::set<MessageId> ackMsgIds;
+
+    for (const auto& msgId : msgIds) {
+        if (auto chunkMessageId =
+                std::dynamic_pointer_cast<ChunkMessageIdImpl>(Commands::getMessageIdImpl(msgId))) {
+            auto msgIdList = chunkMessageId->moveChunkedMessageIds();
+            doImmediateAck(std::set<MessageId>(std::make_move_iterator(msgIdList.begin()),
+                                               std::make_move_iterator(msgIdList.end())),
+                           callback);

Review Comment:
   +1 that will make the code more clear.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] BewareMyPower commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1338351228


##########
lib/AckGroupingTracker.cc:
##########
@@ -84,29 +94,43 @@ void AckGroupingTracker::doImmediateAck(const std::set<MessageId>& msgIds, Resul
         return;
     }
 
+    std::set<MessageId> ackMsgIds;
+
+    for (const auto& msgId : msgIds) {
+        if (auto chunkMessageId =
+                std::dynamic_pointer_cast<ChunkMessageIdImpl>(Commands::getMessageIdImpl(msgId))) {
+            auto msgIdList = chunkMessageId->moveChunkedMessageIds();
+            doImmediateAck(std::set<MessageId>(std::make_move_iterator(msgIdList.begin()),
+                                               std::make_move_iterator(msgIdList.end())),
+                           callback);

Review Comment:
   We should add `ChunkMessageIdImpl::chunkedMessageIds_` into the `ackMsgIds` instead of calling `doImmediateAck`.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] shibd commented on a diff in pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "shibd (via GitHub)" <gi...@apache.org>.
shibd commented on code in PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#discussion_r1339470300


##########
lib/AckGroupingTracker.cc:
##########
@@ -42,6 +44,14 @@ void AckGroupingTracker::doImmediateAck(const MessageId& msgId, ResultCallback c
         }
         return;
     }
+    if (auto chunkMessageId =
+            std::dynamic_pointer_cast<ChunkMessageIdImpl>(Commands::getMessageIdImpl(msgId))) {
+        auto msgIdList = chunkMessageId->moveChunkedMessageIds();
+        doImmediateAck(std::set<MessageId>(std::make_move_iterator(msgIdList.begin()),
+                                           std::make_move_iterator(msgIdList.end())),

Review Comment:
   +1 



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix] Fix consumer doesn't acknowledge all chunk message Ids [pulsar-client-cpp]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower merged PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-client-cpp] shibd commented on pull request #321: [fix] Fix consumer doesn't acknowledge all chunk message Ids

Posted by "shibd (via GitHub)" <gi...@apache.org>.
shibd commented on PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#issuecomment-1738390361

   BTW: This variable seems useless.
   
   https://github.com/apache/pulsar-client-cpp/blob/0ffad7b838c38ead258a52969fab302f22ccb976/lib/ConsumerImpl.h#L298


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix] Fix consumer doesn't acknowledge all chunk message Ids [pulsar-client-cpp]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on PR #321:
URL: https://github.com/apache/pulsar-client-cpp/pull/321#issuecomment-1746774082

   I will review this PR again after backing from the vacation in 6th Oct.


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org