aloyszhang commented on a change in pull request #11014:
URL: https://github.com/apache/pulsar/pull/11014#discussion_r663089943



##########
File path: 
pulsar-client/src/test/java/org/apache/pulsar/client/impl/MessageImplTest.java
##########
@@ -450,10 +450,8 @@ public void 
testMessageBrokerAndEntryMetadataTimestampMissed() {
 
             CompositeByteBuf compositeByteBuf = 
PulsarByteBufAllocator.DEFAULT.compositeBuffer();
             compositeByteBuf.addComponents(true, brokerMeta, byteBuf);
-            MessageImpl messageWithEntryMetadata = 
MessageImpl.deserializeBrokerEntryMetaDataFirst(compositeByteBuf);
-            MessageImpl message = 
MessageImpl.deserializeSkipBrokerEntryMetaData(compositeByteBuf);
-            
message.setBrokerEntryMetadata(messageWithEntryMetadata.getBrokerEntryMetadata());
-            assertTrue(message.isExpired(100));
+            long entryTimestamp = 
MessageImpl.getEntryTimestamp(compositeByteBuf);

Review comment:
       fixed

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/MessageImpl.java
##########
@@ -269,31 +269,31 @@ public MessageImpl(String topic, String msgId, 
Map<String, String> properties,
         return msg;
     }
 
-    public static MessageImpl<byte[]> deserializeBrokerEntryMetaDataFirst(
-            ByteBuf headersAndPayloadWithBrokerEntryMetadata) throws 
IOException {
-        @SuppressWarnings("unchecked")
-        MessageImpl<byte[]> msg = (MessageImpl<byte[]>) RECYCLER.get();
-
-        msg.brokerEntryMetadata =
+    public static long getEntryTimestamp( ByteBuf 
headersAndPayloadWithBrokerEntryMetadata) throws IOException {
+        // get broker timestamp first if BrokerEntryMetadata is enabled with 
AppendBrokerTimestampMetadataInterceptor
+        BrokerEntryMetadata brokerEntryMetadata =
                 
Commands.parseBrokerEntryMetadataIfExist(headersAndPayloadWithBrokerEntryMetadata);
-
-        if (msg.brokerEntryMetadata != null) {
-            msg.msgMetadata.clear();
-            msg.payload = null;
-            msg.messageId = null;
-            msg.topic = null;
-            msg.cnx = null;
-            msg.properties = Collections.emptyMap();
-            return msg;
+        if (brokerEntryMetadata != null && 
brokerEntryMetadata.hasBrokerTimestamp()) {
+            return brokerEntryMetadata.getBrokerTimestamp();
+        }
+        // otherwise get the publish_time,
+        MessageImpl<byte[]> msg = (MessageImpl<byte[]>) RECYCLER.get();
+        try {
+            
Commands.parseMessageMetadata(headersAndPayloadWithBrokerEntryMetadata, 
msg.msgMetadata);
+            return msg.getPublishTime();
+        } finally {
+            // make sure msg can be recycled
+            msg.recycle();
         }
+    }
 
-        
Commands.parseMessageMetadata(headersAndPayloadWithBrokerEntryMetadata, 
msg.msgMetadata);
-        msg.payload = headersAndPayloadWithBrokerEntryMetadata;
-        msg.messageId = null;
-        msg.topic = null;
-        msg.cnx = null;
-        msg.properties = Collections.emptyMap();
-        return msg;
+    public static boolean isEntryExpired(int messageTTLInSeconds, long 
entryTimestamp) {
+        return messageTTLInSeconds != 0 &&
+                (System.currentTimeMillis() > entryTimestamp + 
TimeUnit.SECONDS.toMillis(messageTTLInSeconds));
+    }
+
+    public static boolean isEntryPublishedEarlierThan(long timestamp, long 
entryTimestamp) {

Review comment:
       fixed




-- 
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-unsubscr...@pulsar.apache.org

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


Reply via email to