Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] System topic writer/reader connection not counted. #18369

Merged
merged 8 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -439,6 +439,9 @@ private PublishRate publishRateInBroker(ServiceConfiguration config) {
}

protected boolean isProducersExceeded() {
if (isSystemTopic()) {
Technoboy- marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
Integer maxProducers = topicPolicies.getMaxProducersPerTopic().get();
if (maxProducers > 0 && maxProducers <= producers.size()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3314,6 +3314,9 @@ public MessageDeduplication getMessageDeduplication() {
}

private boolean checkMaxSubscriptionsPerTopicExceed(String subscriptionName) {
if (isSystemTopic()) {
return false;
}
//Existing subscriptions are not affected
if (StringUtils.isNotEmpty(subscriptionName) && getSubscription(subscriptionName) != null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import lombok.Cleanup;
import org.apache.bookkeeper.mledger.LedgerOffloader;
import org.apache.bookkeeper.mledger.ManagedLedgerConfig;
Expand All @@ -52,6 +55,8 @@
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.naming.TopicVersion;
import org.apache.pulsar.common.policies.data.BacklogQuota;
import org.apache.pulsar.common.policies.data.DispatchRate;
import org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy;
import org.apache.pulsar.common.policies.data.TenantInfo;
import org.apache.pulsar.common.policies.data.TenantInfoImpl;
import org.apache.pulsar.common.util.FutureUtil;
Expand Down Expand Up @@ -260,4 +265,61 @@ private void testSetBacklogCausedCreatingProducerFailure() throws Exception {
Assert.fail("failed to create producer");
}
}

@Test
private void testSystemTopicNotCheckExceed() throws Exception {
Technoboy- marked this conversation as resolved.
Show resolved Hide resolved
final String ns = "prop/ns-test";
final String topic = ns + "/topic-1";

admin.namespaces().createNamespace(ns, 2);
admin.topics().createPartitionedTopic(String.format("persistent://%s", topic), 1);

admin.topicPolicies().setMaxConsumers(topic, 1);
NamespaceEventsSystemTopicFactory systemTopicFactory = new NamespaceEventsSystemTopicFactory(pulsarClient);
TopicPoliciesSystemTopicClient systemTopicClientForNamespace = systemTopicFactory
.createTopicPoliciesSystemTopicClient(NamespaceName.get(ns));
SystemTopicClient.Reader reader1 = systemTopicClientForNamespace.newReader();
SystemTopicClient.Reader reader2 = systemTopicClientForNamespace.newReader();

admin.topicPolicies().setMaxProducers(topic, 1);
AtomicInteger successCount = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(3);
new Thread(() -> {
Technoboy- marked this conversation as resolved.
Show resolved Hide resolved
try {
admin.topicPolicies().setCompactionThreshold(topic, 1L);
successCount.incrementAndGet();
} catch (PulsarAdminException ignore) {
} finally {
latch.countDown();
}
}).start();
new Thread(() -> {
try {
admin.topicPolicies().setSchemaCompatibilityStrategy(topic,
SchemaCompatibilityStrategy.ALWAYS_COMPATIBLE);
successCount.incrementAndGet();
} catch (PulsarAdminException ignore) {
} finally {
latch.countDown();
}
}).start();
new Thread(() -> {
try {
admin.topicPolicies().setDispatchRate(topic, DispatchRate.builder()
.ratePeriodInSecond(1).build());
successCount.incrementAndGet();
} catch (PulsarAdminException ignore) {
} finally {
latch.countDown();
}
}).start();
latch.await();
Assert.assertEquals(3, successCount.get());
Assert.assertTrue(reader1.hasMoreEvents());
Assert.assertNotNull(reader1.readNext());
Assert.assertTrue(reader2.hasMoreEvents());
Assert.assertNotNull(reader2.readNext());
reader1.close();
reader2.close();
}
}