-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][broker]Fix chunked messages will be filtered by duplicating (#2…
…0948) ## Motivation Make the chunk message function work properly when deduplication is enabled. ## Modification ### Only check and store the sequence ID of the last chunk in a chunk message. For example: ```markdown Chunk-1 sequence ID: 0, chunk ID: 0, total chunk: 2 Chunk-2 sequence ID: 0, chunk ID: 1 Chunk-3 sequence ID: 1, chunk ID: 0 total chunk: 3 Chunk-4 sequence ID: 1, chunk ID: 1 Chunk-5 sequence ID: 1, chunk ID: 1 Chunk-6 sequence ID: 1, chunk ID: 2 ``` Only store check and store the sequence ID of Chunk-2 and Chunk-6. **Add a property in the publishContext to determine whether this chunk is the last chunk when persistent completely.** ```java publishContext.setProperty(IS_LAST_CHUNK, Boolean.FALSE); ``` ### Filter and ack duplicated chunks in a chunk message instead of discarding ctx. For example: ```markdown Chunk-1 sequence ID: 0, chunk ID: 0, msgID: 1:1 Chunk-2 sequence ID: 0, chunk ID: 1, msgID: 1:2 Chunk-3 sequence ID: 0, chunk ID: 2, msgID: 1:3 Chunk-4 sequence ID: 0, chunk ID: 1, msgID: 1:4 Chunk-5 sequence ID: 0, chunk ID: 2, msgID: 1:5 Chunk-6 sequence ID: 0, chunk ID: 3, msgID: 1:6 ``` We should filter and ack chunk-4 and chunk-5.
- Loading branch information
1 parent
792a98e
commit 608f760
Showing
4 changed files
with
198 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...-broker/src/test/java/org/apache/pulsar/client/impl/MessageChunkingDeduplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.impl; | ||
|
||
import static org.apache.pulsar.client.impl.MessageChunkingSharedTest.sendChunk; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertNull; | ||
import static org.testng.Assert.assertTrue; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.Cleanup; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.service.persistent.PersistentTopic; | ||
import org.apache.pulsar.client.api.Consumer; | ||
import org.apache.pulsar.client.api.Message; | ||
import org.apache.pulsar.client.api.Producer; | ||
import org.apache.pulsar.client.api.ProducerConsumerBase; | ||
import org.apache.pulsar.client.api.Schema; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
@Slf4j | ||
@Test(groups = "broker-impl") | ||
public class MessageChunkingDeduplicationTest extends ProducerConsumerBase { | ||
|
||
@BeforeClass | ||
@Override | ||
protected void setup() throws Exception { | ||
this.conf.setBrokerDeduplicationEnabled(true); | ||
super.internalSetup(); | ||
super.producerBaseSetup(); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
@Override | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Test | ||
public void testSendChunkMessageWithSameSequenceID() throws Exception { | ||
String topicName = "persistent://my-property/my-ns/testSendChunkMessageWithSameSequenceID"; | ||
String producerName = "test-producer"; | ||
@Cleanup | ||
Consumer<String> consumer = pulsarClient | ||
.newConsumer(Schema.STRING) | ||
.subscriptionName("test-sub") | ||
.topic(topicName) | ||
.subscribe(); | ||
@Cleanup | ||
Producer<String> producer = pulsarClient | ||
.newProducer(Schema.STRING) | ||
.producerName(producerName) | ||
.topic(topicName) | ||
.enableChunking(true) | ||
.enableBatching(false) | ||
.create(); | ||
int messageSize = 6000; // payload size in KB | ||
String message = "a".repeat(messageSize * 1000); | ||
producer.newMessage().value(message).sequenceId(10).send(); | ||
Message<String> msg = consumer.receive(10, TimeUnit.SECONDS); | ||
assertNotNull(msg); | ||
assertTrue(msg.getMessageId() instanceof ChunkMessageIdImpl); | ||
assertEquals(msg.getValue(), message); | ||
producer.newMessage().value(message).sequenceId(10).send(); | ||
msg = consumer.receive(3, TimeUnit.SECONDS); | ||
assertNull(msg); | ||
} | ||
|
||
@Test | ||
public void testDeduplicateChunksInSingleChunkMessages() throws Exception { | ||
String topicName = "persistent://my-property/my-ns/testDeduplicateChunksInSingleChunkMessage"; | ||
String producerName = "test-producer"; | ||
@Cleanup | ||
Consumer<String> consumer = pulsarClient | ||
.newConsumer(Schema.STRING) | ||
.subscriptionName("test-sub") | ||
.topic(topicName) | ||
.subscribe(); | ||
final PersistentTopic persistentTopic = (PersistentTopic) pulsar.getBrokerService() | ||
.getTopicIfExists(topicName).get().orElse(null); | ||
assertNotNull(persistentTopic); | ||
sendChunk(persistentTopic, producerName, 1, 0, 2); | ||
sendChunk(persistentTopic, producerName, 1, 1, 2); | ||
sendChunk(persistentTopic, producerName, 1, 1, 2); | ||
|
||
Message<String> message = consumer.receive(15, TimeUnit.SECONDS); | ||
assertEquals(message.getData().length, 2); | ||
|
||
sendChunk(persistentTopic, producerName, 2, 0, 3); | ||
sendChunk(persistentTopic, producerName, 2, 1, 3); | ||
sendChunk(persistentTopic, producerName, 2, 1, 3); | ||
sendChunk(persistentTopic, producerName, 2, 2, 3); | ||
message = consumer.receive(20, TimeUnit.SECONDS); | ||
assertEquals(message.getData().length, 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters