Denovo1998 commented on code in PR #25555:
URL: https://github.com/apache/pulsar/pull/25555#discussion_r3234882929


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Producer.java:
##########
@@ -208,8 +208,13 @@ public boolean isSuccessorTo(Producer other) {
 
     public void publishMessage(long producerId, long sequenceId, ByteBuf 
headersAndPayload, int batchSize,
             boolean isChunked, boolean isMarker, Position position) {
-        if (checkAndStartPublish(producerId, sequenceId, headersAndPayload, 
batchSize, position)) {
-            publishMessageToTopic(headersAndPayload, sequenceId, batchSize, 
isChunked, isMarker, position);
+        MessagePublishContext messagePublishContext =
+                MessagePublishContext.get(this, sequenceId, 
headersAndPayload.readableBytes(),
+                        batchSize, isChunked, System.nanoTime(), isMarker, 
position, isSupportsReplDedupByLidAndEid());
+        if (checkAndStartPublish(producerId, sequenceId, headersAndPayload, 
position, messagePublishContext)) {
+            publishMessageToTopic(headersAndPayload, messagePublishContext);
+        } else {
+            messagePublishContext.recycle();

Review Comment:
   A related lifecycle optimization: after topic.publishMessage(...) / 
topic.publishTxnMessage(...) returns, the cached MessageMetadata appears no 
longer needed by the current publish flow. PersistentTopic consumes it 
synchronously for max-delivery-delay validation and deduplication before 
asyncAddEntry/transaction append. The later async completion path and 
messageProduced interceptor don't receive headersAndPayload, so keeping the 
parsed MessageMetadata attached to MessagePublishContext until recycle extends 
its lifetime to the full in-flight write duration.
   
   If we add clearMessageMetadata() for the interceptor correctness issue 
above, it would be useful to also clear it after the topic publish call 
returns, preferably in a finally block, so high-throughput or high-latency 
writes don't retain parsed metadata objects longer than necessary.



-- 
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]

Reply via email to