forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose consumer names after the mark delete position for the Key_Shar…
…ed subscription (apache#8545) ### Motivation 1. Expose consumer names after the mark delete position for the Key_Shared subscription. 2. Remove the consumer from the recenlyJoinedConsumer depends on the valid next position of the next position. Previously, we use the position.nextPosition to decide to remove the consumer from the recenlyJoinedConsumer but this will lead to consumers can't be deleted property. For example, if ledger rollover and the mark delete position is the last position of the old ledger and the max read position is the first position of the new ledger, In this situation, we should remove the consumer from the recenlyJoinedConsumer but in fact, it will stay in the recenlyJoinedConsumer because the max read position always greater than the `markDeletePosition.nextPosition`. So we should get the valid next position for the mark delete position. Related to apache#8499
- Loading branch information
1 parent
67f544c
commit 6867262
Showing
7 changed files
with
153 additions
and
17 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
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
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
94 changes: 94 additions & 0 deletions
94
pulsar-broker/src/test/java/org/apache/pulsar/broker/stats/SubscriptionStatsTest.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,94 @@ | ||
/** | ||
* 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.broker.stats; | ||
|
||
import lombok.Cleanup; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.client.admin.PulsarAdminException; | ||
import org.apache.pulsar.client.api.Consumer; | ||
import org.apache.pulsar.client.api.Producer; | ||
import org.apache.pulsar.client.api.ProducerConsumerBase; | ||
import org.apache.pulsar.client.api.PulsarClientException; | ||
import org.apache.pulsar.client.api.SubscriptionType; | ||
import org.apache.pulsar.common.policies.data.TopicStats; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.UUID; | ||
|
||
@Slf4j | ||
public class SubscriptionStatsTest extends ProducerConsumerBase { | ||
|
||
@BeforeClass | ||
@Override | ||
protected void setup() throws Exception { | ||
super.internalSetup(); | ||
super.producerBaseSetup(); | ||
} | ||
|
||
@AfterClass | ||
@Override | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Test | ||
public void testConsumersAfterMarkDelete() throws PulsarClientException, PulsarAdminException { | ||
final String topicName = "persistent://my-property/my-ns/testConsumersAfterMarkDelete-" | ||
+ UUID.randomUUID().toString(); | ||
final String subName = "my-sub"; | ||
|
||
Consumer<byte[]> consumer1 = pulsarClient.newConsumer() | ||
.topic(topicName) | ||
.receiverQueueSize(10) | ||
.subscriptionName(subName) | ||
.subscriptionType(SubscriptionType.Key_Shared) | ||
.subscribe(); | ||
|
||
Producer<byte[]> producer = pulsarClient.newProducer() | ||
.topic(topicName) | ||
.create(); | ||
|
||
final int messages = 100; | ||
for (int i = 0; i < messages; i++) { | ||
producer.send(String.valueOf(i).getBytes()); | ||
} | ||
|
||
// Receive by do not ack the message, so that the next consumer can added to the recentJoinedConsumer of the dispatcher. | ||
consumer1.receive(); | ||
|
||
Consumer<byte[]> consumer2 = pulsarClient.newConsumer() | ||
.topic(topicName) | ||
.receiverQueueSize(10) | ||
.subscriptionName(subName) | ||
.subscriptionType(SubscriptionType.Key_Shared) | ||
.subscribe(); | ||
|
||
TopicStats stats = admin.topics().getStats(topicName); | ||
Assert.assertEquals(stats.subscriptions.size(), 1); | ||
Assert.assertEquals(stats.subscriptions.entrySet().iterator().next().getValue() | ||
.consumersAfterMarkDeletePosition.size(), 1); | ||
|
||
consumer1.close(); | ||
consumer2.close(); | ||
producer.close(); | ||
} | ||
} |
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