Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public static void skipMessageMetadata(ByteBuf buffer) {
}

public static long getEntryTimestamp(ByteBuf headersAndPayloadWithBrokerEntryMetadata) throws IOException {
// get broker timestamp first if BrokerEntryMetadata is enabled with AppendBrokerTimestampMetadataInterceptor
// get broker timestamp first if exists
BrokerEntryMetadata brokerEntryMetadata =
Commands.parseBrokerEntryMetadataIfExist(headersAndPayloadWithBrokerEntryMetadata);
if (brokerEntryMetadata != null && brokerEntryMetadata.hasBrokerTimestamp()) {
Expand Down Expand Up @@ -1716,6 +1716,9 @@ public static ByteBuf addBrokerEntryMetadata(ByteBuf headerAndPayload,
interceptor.interceptWithNumberOfMessages(brokerEntryMetadata, numberOfMessages);
}
}
if (!brokerEntryMetadata.hasBrokerTimestamp()) {
brokerEntryMetadata.setBrokerTimestamp(System.currentTimeMillis());
}
Comment on lines +1719 to +1721

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The broker timestamp will be set in line:1702 if the AppendBrokerTimestampMetadataInterceptor is enabled. Is this PR wants to set the broker timestamp without AppendBrokerTimestampMetadataInterceptor enabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we can ensure that the AppendBrokerTimestampMetadataInterceptor cannot be disabled, this bug may always occur

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we can either make the AppendBrokerTimestampMetadataInterceptor enabled by default or remove the AppendBrokerTimestampMetadataInterceptor to always apply the broker timestamp.

Without this change, the broker timestamp will be enabled without AppendBrokerTimestampMetadataInterceptor. Essentially, we delete the functionality of the AppendBrokerTimestampMetadataInterceptor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


int brokerMetaSize = brokerEntryMetadata.getSerializedSize();
ByteBuf brokerMeta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import static org.apache.pulsar.common.protocol.Commands.serializeMetadataAndPayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -151,6 +153,26 @@ public void testAddBrokerEntryMetadata() throws Exception {
assertTrue(new String(content, StandardCharsets.UTF_8).endsWith(data));
}

@Test
public void testAlwaysSetBrokerTimestamp() {
int MOCK_BATCH_SIZE = 10;
String data = "test-message";
ByteBuf byteBuf = PulsarByteBufAllocator.DEFAULT.buffer(data.length(), data.length());
byteBuf.writeBytes(data.getBytes(StandardCharsets.UTF_8));
ByteBuf dataWithBrokerEntryMetadata =
Commands.addBrokerEntryMetadata(byteBuf, new HashSet<>(), MOCK_BATCH_SIZE);
BrokerEntryMetadata entryMetadata = Commands.parseBrokerEntryMetadataIfExist(dataWithBrokerEntryMetadata);
assertNotNull(entryMetadata);
assertTrue(entryMetadata.hasBrokerTimestamp());
long timestamp = entryMetadata.getBrokerTimestamp();
// add again, the timestamp should change
dataWithBrokerEntryMetadata =
Commands.addBrokerEntryMetadata(byteBuf, new HashSet<>(), MOCK_BATCH_SIZE);
entryMetadata = Commands.parseBrokerEntryMetadataIfExist(dataWithBrokerEntryMetadata);
assertNotNull(entryMetadata);
assertNotEquals(timestamp, entryMetadata.getBrokerTimestamp());
}

@Test
public void testSkipBrokerEntryMetadata() throws Exception {
String data = "test-message";
Expand Down