You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ma...@apache.org on 2023/01/16 08:11:26 UTC

[pulsar] branch branch-2.9 updated (e310713be43 -> 8f05d251679)

This is an automated email from the ASF dual-hosted git repository.

mattisonchao pushed a change to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git


    from e310713be43 [improve][broker] Add ref count for sticky hash to optimize the performance of Key_Shared subscription (#19167)
     new 0475d4212ae [fix][broker] Support deleting partitioned topics with the keyword `-partition-` (#19230)
     new 8f05d251679 [improve][broker] Follow up #19230 to tighten the validation scope (#19234)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../pulsar/broker/admin/v2/PersistentTopics.java   |   7 +-
 .../persistent/MessageRedeliveryController.java    |   3 +-
 .../PartitionKeywordCompatibilityTest.java         | 104 +++++++++++++++++++++
 3 files changed, 111 insertions(+), 3 deletions(-)
 create mode 100644 pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java


[pulsar] 01/02: [fix][broker] Support deleting partitioned topics with the keyword `-partition-` (#19230)

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattisonchao pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 0475d4212ae53fbc62bc786c6cfa4974abc95103
Author: Qiang Zhao <ma...@apache.org>
AuthorDate: Sat Jan 14 11:55:18 2023 +0800

    [fix][broker] Support deleting partitioned topics with the keyword `-partition-` (#19230)
    
    (cherry picked from commit fc4bca6823282c4f5375e5d48552c1f0e114b5ee)
---
 .../pulsar/broker/admin/v2/PersistentTopics.java   |  2 +-
 .../persistent/MessageRedeliveryController.java    |  3 +-
 .../PartitionKeywordCompatibilityTest.java         | 77 ++++++++++++++++++++++
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
index c9c5ad7720c..e6bf99c4118 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
@@ -825,7 +825,7 @@ public class PersistentTopics extends PersistentTopicsBase {
             @ApiParam(value = "Delete the topic's schema storage")
             @QueryParam("deleteSchema") @DefaultValue("false") boolean deleteSchema) {
         try {
-            validatePartitionedTopicName(tenant, namespace, encodedTopic);
+            validateTopicName(tenant, namespace, encodedTopic);
             internalDeletePartitionedTopic(asyncResponse, authoritative, force, deleteSchema);
         } catch (WebApplicationException wae) {
             asyncResponse.resume(wae);
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageRedeliveryController.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageRedeliveryController.java
index e6febc722de..a8f6c14c537 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageRedeliveryController.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageRedeliveryController.java
@@ -46,8 +46,7 @@ public class MessageRedeliveryController {
         if (!allowOutOfOrderDelivery) {
             this.hashesToBeBlocked = ConcurrentLongLongPairHashMap
                     .newBuilder().concurrencyLevel(2).expectedItems(128).autoShrink(true).build();
-            this.hashesRefCount = ConcurrentLongLongHashMap
-                    .newBuilder().concurrencyLevel(2).expectedItems(128).autoShrink(true).build();
+            this.hashesRefCount = new ConcurrentLongLongHashMap(128, 2);
         } else {
             this.hashesToBeBlocked = null;
             this.hashesRefCount = null;
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
new file mode 100644
index 00000000000..58b9dcee628
--- /dev/null
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.service.persistent;
+
+
+import lombok.Cleanup;
+import org.apache.pulsar.broker.service.BrokerTestBase;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.SubscriptionType;
+import org.apache.pulsar.common.policies.data.AutoTopicCreationOverride;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import java.util.List;
+
+@Test
+public class PartitionKeywordCompatibilityTest extends BrokerTestBase {
+
+    @BeforeClass(alwaysRun = true)
+    @Override
+    protected void setup() throws Exception {
+        baseSetup();
+        setupDefaultTenantAndNamespace();
+    }
+
+    @AfterClass(alwaysRun = true)
+    @Override
+    protected void cleanup() throws Exception {
+        internalCleanup();
+    }
+
+    public void testAutoCreatePartitionTopicWithKeywordAndDeleteIt()
+            throws PulsarAdminException, PulsarClientException {
+        AutoTopicCreationOverride override = AutoTopicCreationOverride.builder()
+                .allowAutoTopicCreation(true)
+                .topicType("partitioned")
+                .defaultNumPartitions(1)
+                .build();
+        admin.namespaces().setAutoTopicCreation("public/default", override);
+        String topicName = "persistent://public/default/XXX-partition-0-dd";
+        @Cleanup
+        Consumer<byte[]> consumer = pulsarClient.newConsumer()
+                .topic(topicName)
+                .subscriptionName("sub-1")
+                .subscriptionType(SubscriptionType.Exclusive)
+                .subscribe();
+        List<String> topics = admin.topics().getList("public/default");
+        List<String> partitionedTopicList = admin.topics().getPartitionedTopicList("public/default");
+        Assert.assertTrue(topics.contains(topicName));
+        Assert.assertTrue(partitionedTopicList.contains(topicName));
+        consumer.close();
+        admin.topics().deletePartitionedTopic(topicName);
+        topics = admin.topics().getList("public/default");
+        partitionedTopicList = admin.topics().getPartitionedTopicList("public/default");
+        Assert.assertFalse(topics.contains(topicName));
+        Assert.assertFalse(partitionedTopicList.contains(topicName));
+    }
+}


[pulsar] 02/02: [improve][broker] Follow up #19230 to tighten the validation scope (#19234)

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattisonchao pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 8f05d2516795f779c8549da7f3b284ebc962098b
Author: Qiang Zhao <ma...@apache.org>
AuthorDate: Sun Jan 15 19:29:45 2023 +0800

    [improve][broker] Follow up #19230 to tighten the validation scope (#19234)
    
    ### Motivation
    This PR is following up #19230
    
    As @yuruguo mentioned https://github.com/apache/pulsar/pull/19230#issuecomment-1382865057, we can tighten the validation scope.
    
    I've checked the logic and found we have no way to create the partition topic with the `-partition-{index}` template. So we can righten the validation scope.
    
    I will keep working on the partition topic section and try to clarify the concept and logic. Plus, ensuring compatibility.
    
    ### Modifications
    
    - tighten the validation scope
    
    (cherry picked from commit 246c2701e5c43e02e9783c82d4d107d06b019951)
---
 .../pulsar/broker/admin/v2/PersistentTopics.java   |  5 ++++
 .../PartitionKeywordCompatibilityTest.java         | 27 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
index e6bf99c4118..e5e3c6d2712 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java
@@ -826,6 +826,11 @@ public class PersistentTopics extends PersistentTopicsBase {
             @QueryParam("deleteSchema") @DefaultValue("false") boolean deleteSchema) {
         try {
             validateTopicName(tenant, namespace, encodedTopic);
+            if (topicName.isPartitioned()) {
+                // There's no way to create the partition topic with `-partition-{index}`, So we can reject it.
+                throw new RestException(Response.Status.PRECONDITION_FAILED,
+                        "Partitioned Topic Name should not contain '-partition-'");
+            }
             internalDeletePartitionedTopic(asyncResponse, authoritative, force, deleteSchema);
         } catch (WebApplicationException wae) {
             asyncResponse.resume(wae);
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
index 58b9dcee628..fdf2eb29c5e 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PartitionKeywordCompatibilityTest.java
@@ -19,6 +19,7 @@
 package org.apache.pulsar.broker.service.persistent;
 
 
+import static org.testng.Assert.fail;
 import lombok.Cleanup;
 import org.apache.pulsar.broker.service.BrokerTestBase;
 import org.apache.pulsar.client.admin.PulsarAdminException;
@@ -74,4 +75,30 @@ public class PartitionKeywordCompatibilityTest extends BrokerTestBase {
         Assert.assertFalse(topics.contains(topicName));
         Assert.assertFalse(partitionedTopicList.contains(topicName));
     }
+
+    @Test
+    public void testDeletePartitionedTopicValidation() throws PulsarAdminException {
+        final String topicName = "persistent://public/default/testDeletePartitionedTopicValidation";
+        final String partitionKeywordTopic = "persistent://public/default/testDelete-partition-edTopicValidation";
+        final String partitionedTopic = "persistent://public/default/testDeletePartitionedTopicValidation-partition-0";
+        try {
+            admin.topics().deletePartitionedTopic(topicName);
+            fail("expect not found!");
+        } catch (PulsarAdminException.NotFoundException ex) {
+            //ok
+        }
+        try {
+            admin.topics().deletePartitionedTopic(partitionKeywordTopic);
+            fail("expect not found!");
+        } catch (PulsarAdminException.NotFoundException ex) {
+            //ok
+        }
+        try {
+            admin.topics().deletePartitionedTopic(partitionedTopic);
+            fail("expect illegal argument");
+        } catch (PulsarAdminException.PreconditionFailedException ex) {
+            Assert.assertTrue(ex.getMessage().contains("should not contain '-partition-'"));
+            // ok
+        }
+    }
 }