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

[fix][broker] Fix updatePartitionedTopic when replication at ns level and topic policy is set #22971

Merged
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 @@ -35,7 +35,6 @@
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -458,8 +457,8 @@ protected CompletableFuture<Void> internalCreateNonPartitionedTopicAsync(boolean
Set<String> replicationClusters = policies.get().replication_clusters;
TopicPolicies topicPolicies =
pulsarService.getTopicPoliciesService().getTopicPoliciesIfExists(topicName);
if (topicPolicies != null) {
replicationClusters = new HashSet<>(topicPolicies.getReplicationClusters());
if (topicPolicies != null && topicPolicies.getReplicationClusters() != null) {
replicationClusters = topicPolicies.getReplicationClustersSet();
}
// Do check replicated clusters.
if (replicationClusters.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
import org.apache.pulsar.client.impl.ProducerImpl;
import org.apache.pulsar.client.impl.PulsarClientImpl;
import org.apache.pulsar.client.impl.conf.ProducerConfigurationData;
import org.apache.pulsar.common.policies.data.RetentionPolicies;
import org.apache.pulsar.common.policies.data.TopicStats;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.partition.PartitionedTopicMetadata;
import org.apache.pulsar.common.policies.data.RetentionPolicies;
import org.apache.pulsar.common.policies.data.TopicStats;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
import org.awaitility.Awaitility;
import org.awaitility.reflect.WhiteboxImpl;
import org.mockito.Mockito;
Expand Down Expand Up @@ -494,6 +494,29 @@ public void testPartitionedTopicLevelReplication() throws Exception {
admin2.topics().deletePartitionedTopic(topicName);
}

// https://github.com/apache/pulsar/issues/22967
@Test
public void testPartitionedTopicWithTopicPolicyAndNoReplicationClusters() throws Exception {
final String topicName = BrokerTestUtil.newUniqueName("persistent://" + replicatedNamespace + "/tp_");
admin1.topics().createPartitionedTopic(topicName, 2);
try {
admin1.topicPolicies().setMessageTTL(topicName, 5);
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
assertEquals(admin2.topics().getPartitionedTopicMetadata(topicName).partitions, 2);
});
admin1.topics().updatePartitionedTopic(topicName, 3, false);
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
assertEquals(admin2.topics().getPartitionedTopicMetadata(topicName).partitions, 3);
});
} finally {
// cleanup.
admin1.topics().deletePartitionedTopic(topicName, true);
if (!usingGlobalZK) {
admin2.topics().deletePartitionedTopic(topicName, true);
}
}
}

@Test
public void testPartitionedTopicLevelReplicationRemoteTopicExist() throws Exception {
final String topicName = BrokerTestUtil.newUniqueName("persistent://" + nonReplicatedNamespace + "/tp_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ protected void setConfigDefaults(ServiceConfiguration config, String clusterName
config.setEnableReplicatedSubscriptions(true);
config.setReplicatedSubscriptionsSnapshotFrequencyMillis(1000);
config.setLoadBalancerSheddingEnabled(false);
config.setForceDeleteNamespaceAllowed(true);
}

@Override
Expand All @@ -276,11 +277,11 @@ protected void cleanup() throws Exception {
if (!usingGlobalZK) {
admin2.namespaces().setNamespaceReplicationClusters(replicatedNamespace, Sets.newHashSet(cluster2));
}
admin1.namespaces().deleteNamespace(replicatedNamespace);
admin1.namespaces().deleteNamespace(nonReplicatedNamespace);
admin1.namespaces().deleteNamespace(replicatedNamespace, true);
admin1.namespaces().deleteNamespace(nonReplicatedNamespace, true);
if (!usingGlobalZK) {
admin2.namespaces().deleteNamespace(replicatedNamespace);
admin2.namespaces().deleteNamespace(nonReplicatedNamespace);
admin2.namespaces().deleteNamespace(replicatedNamespace, true);
admin2.namespaces().deleteNamespace(nonReplicatedNamespace, true);
}

// shutdown.
Expand Down
Loading