You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by sh...@apache.org on 2023/05/30 04:23:33 UTC

[pulsar-client-cpp] branch support-parse-broker-metadata updated (0c4823d -> 25410c4)

This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a change to branch support-parse-broker-metadata
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git


 discard 0c4823d  [consumer] Support parse broker metadata
     new 25410c4  [consumer] Support parse broker metadata

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0c4823d)
            \
             N -- N -- N   refs/heads/support-parse-broker-metadata (25410c4)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 lib/ProducerImpl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[pulsar-client-cpp] 01/01: [consumer] Support parse broker metadata

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch support-parse-broker-metadata
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git

commit 25410c49dc6e332a512b788081f2fef179960a15
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Tue May 30 11:31:11 2023 +0800

    [consumer] Support parse broker metadata
---
 lib/ClientConnection.cc | 26 ++++++++++++++++++++++++--
 lib/Commands.h          |  1 +
 lib/ProducerImpl.h      |  1 +
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/lib/ClientConnection.cc b/lib/ClientConnection.cc
index 72b9c8e..ac0e847 100644
--- a/lib/ClientConnection.cc
+++ b/lib/ClientConnection.cc
@@ -679,11 +679,32 @@ void ClientConnection::processIncomingBuffer() {
         if (incomingCmd.type() == BaseCommand::MESSAGE) {
             // Parse message metadata and extract payload
             proto::MessageMetadata msgMetadata;
+            proto::BrokerEntryMetadata brokerEntryMetadata;
 
             // read checksum
             uint32_t remainingBytes = frameSize - (cmdSize + 4);
             bool isChecksumValid = verifyChecksum(incomingBuffer_, remainingBytes, incomingCmd);
 
+            auto readerIndex = incomingBuffer_.readerIndex();
+            if (incomingBuffer_.readUnsignedShort() == Commands::magicBrokerEntryMetadata) {
+                // broker entry metadata is present
+                uint32_t brokerEntryMetadataSize = incomingBuffer_.readUnsignedInt();
+                if (!brokerEntryMetadata.ParseFromArray(incomingBuffer_.data(), brokerEntryMetadataSize)) {
+                    LOG_ERROR(cnxString_ << "[consumer id " << incomingCmd.message().consumer_id()  //
+                                         << ", message ledger id "
+                                         << incomingCmd.message().message_id().ledgerid()  //
+                                         << ", entry id " << incomingCmd.message().message_id().entryid()
+                                         << "] Error parsing broker entry metadata");
+                    close();
+                    return;
+                }
+
+                incomingBuffer_.consume(brokerEntryMetadataSize);
+                remainingBytes -= (2 + 4 + brokerEntryMetadataSize);
+            } else {
+                incomingBuffer_.setReaderIndex(readerIndex);
+            }
+
             uint32_t metadataSize = incomingBuffer_.readUnsignedInt();
             if (!msgMetadata.ParseFromArray(incomingBuffer_.data(), metadataSize)) {
                 LOG_ERROR(cnxString_ << "[consumer id " << incomingCmd.message().consumer_id()  //
@@ -701,7 +722,7 @@ void ClientConnection::processIncomingBuffer() {
             uint32_t payloadSize = remainingBytes;
             SharedBuffer payload = SharedBuffer::copy(incomingBuffer_.data(), payloadSize);
             incomingBuffer_.consume(payloadSize);
-            handleIncomingMessage(incomingCmd.message(), isChecksumValid, msgMetadata, payload);
+            handleIncomingMessage(incomingCmd.message(), isChecksumValid, brokerEntryMetadata, msgMetadata, payload);
         } else {
             handleIncomingCommand(incomingCmd);
         }
@@ -710,7 +731,7 @@ void ClientConnection::processIncomingBuffer() {
         // We still have 1 to 3 bytes from the next frame
         assert(incomingBuffer_.readableBytes() < sizeof(uint32_t));
 
-        // Restart with a new buffer and copy the the few bytes at the beginning
+        // Restart with a new buffer and copy the few bytes at the beginning
         incomingBuffer_ = SharedBuffer::copyFrom(incomingBuffer_, DefaultBufferSize);
 
         // At least we need to read 4 bytes to have the complete frame size
@@ -782,6 +803,7 @@ void ClientConnection::handleActiveConsumerChange(const proto::CommandActiveCons
 }
 
 void ClientConnection::handleIncomingMessage(const proto::CommandMessage& msg, bool isChecksumValid,
+                                             proto::BrokerEntryMetadata brokerEntryMetadata,
                                              proto::MessageMetadata& msgMetadata, SharedBuffer& payload) {
     LOG_DEBUG(cnxString_ << "Received a message from the server for consumer: " << msg.consumer_id());
 
diff --git a/lib/Commands.h b/lib/Commands.h
index 65a6406..45a7c44 100644
--- a/lib/Commands.h
+++ b/lib/Commands.h
@@ -79,6 +79,7 @@ class Commands {
     };
 
     const static uint16_t magicCrc32c = 0x0e01;
+    const static uint16_t magicBrokerEntryMetadata = 0x0e02;
     const static int checksumSize = 4;
 
     static SharedBuffer newConnect(const AuthenticationPtr& authentication, const std::string& logicalAddress,
diff --git a/lib/ProducerImpl.h b/lib/ProducerImpl.h
index b041f47..ed39082 100644
--- a/lib/ProducerImpl.h
+++ b/lib/ProducerImpl.h
@@ -57,6 +57,7 @@ class TopicName;
 struct OpSendMsg;
 
 namespace proto {
+class BrokerEntryMetadata;
 class MessageMetadata;
 }  // namespace proto