You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/11/02 14:59:51 UTC

[GitHub] [pulsar] liangyepianzhou opened a new pull request, #18307: [fix][broker] Fix can not delete namespace by force

liangyepianzhou opened a new pull request, #18307:
URL: https://github.com/apache/pulsar/pull/18307

   ### Motivation
   1. When we delete a namespace by force if the __transaction_buffer_snapshot and __change_events be deleted first, and then the deleting of the normal topic will be failed at clearing the snapshot and clearing topic policies.
   2. fix flaky test testCreateTransactionSystemTopic. Test failed due to cleaning up after class.
   ### Modification
   1. Delete the normal topic and then delete the system topic.
   2. The system topic does not need to clean up topic policies.
   
   For modification 2, there is a supported error msg. 
   ![16673984912850](https://user-images.githubusercontent.com/55571188/199523972-390247ab-a6e2-40a5-a328-b6815f78494e.jpg)
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. Please attach the local preview screenshots (run `sh start.sh` at `pulsar/site2/website`) to your PR description, or else your PR might not get merged. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: https://github.com/liangyepianzhou/pulsar/pull/8


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- merged pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
Technoboy- merged PR #18307:
URL: https://github.com/apache/pulsar/pull/18307


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1341016138

   @nicoloboschi If they use the topic of topic policy. Then the fix has to be contained in the broker. 
   There is also a problem that the topic of topic policy cannot be successfully deleted.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1319501321

   > @Technoboy- Why the namespace should not be deleted here?
   > 
   > https://github.com/apache/pulsar/blob/d54c2cb5f04bfb15e8b8896f49faa81130b70c29/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java#L93-L119
   
   Should be related with https://github.com/apache/pulsar/pull/14991.  There is one case that the test did not coverage after discuss then. So add this test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1012557646


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -1207,7 +1207,14 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions,
                         brokerService.deleteTopicAuthenticationWithRetry(topic, deleteTopicAuthenticationFuture, 5);
 
                         deleteTopicAuthenticationFuture.thenCompose(__ -> deleteSchema())
-                                .thenCompose(__ -> deleteTopicPolicies())
+                                .thenCompose(__ -> {
+                                    if (!this.getBrokerService().getPulsar().getBrokerService()

Review Comment:
   ` __transaction_buffer_snapshot` is also not requiring policies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1013547281


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -218,38 +218,47 @@ protected CompletableFuture<Void> internalDeleteNamespaceAsync(boolean force) {
                          }))
                 .thenCompose(topics -> {
                     List<String> allTopics = topics.get(0);
+                    ArrayList<String> copyAllTopics = new ArrayList<>();

Review Comment:
   `copyAllTopics` -> `allUserCreatedTopics`
   `copyAllPartitionTopics` -> `allUserCreatedPartitionTopics`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codelipenghui commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1330710684

   @liangyepianzhou Could you please help push a PR to fix branch-2.10, branch-2.9, and branch-2.11? I tried to cherry-pick it directly, but it looks like there are many conflicts. It's better to create a PR to get more eyes on the change to release branches.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1455337814

   Cherry-picked by https://github.com/apache/pulsar/pull/18826


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codecov-commenter commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1301584528

   # [Codecov](https://codecov.io/gh/apache/pulsar/pull/18307?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#18307](https://codecov.io/gh/apache/pulsar/pull/18307?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3eee361) into [master](https://codecov.io/gh/apache/pulsar/commit/2e878e8aac869bc4500e9d32e5c78bfc5c86614b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2e878e8) will **increase** coverage by `30.74%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/pulsar/pull/18307/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/pulsar/pull/18307?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@              Coverage Diff              @@
   ##             master   #18307       +/-   ##
   =============================================
   + Coverage     40.04%   70.79%   +30.74%     
   + Complexity     8625      438     -8187     
   =============================================
     Files           687       26      -661     
     Lines         67436     2246    -65190     
     Branches       7221      245     -6976     
   =============================================
   - Hits          27007     1590    -25417     
   + Misses        37411      483    -36928     
   + Partials       3018      173     -2845     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | unittests | `70.79% <ø> (+30.74%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/pulsar/pull/18307?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...pache/pulsar/broker/admin/impl/NamespacesBase.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi9pbXBsL05hbWVzcGFjZXNCYXNlLmphdmE=) | | |
   | [...sar/broker/service/persistent/PersistentTopic.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL3BlcnNpc3RlbnQvUGVyc2lzdGVudFRvcGljLmphdmE=) | | |
   | [...chema/generic/ProtobufNativeRecordBuilderImpl.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL3NjaGVtYS9nZW5lcmljL1Byb3RvYnVmTmF0aXZlUmVjb3JkQnVpbGRlckltcGwuamF2YQ==) | | |
   | [...roker/systopic/TopicPoliciesSystemTopicClient.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zeXN0b3BpYy9Ub3BpY1BvbGljaWVzU3lzdGVtVG9waWNDbGllbnQuamF2YQ==) | | |
   | [...rcegroup/ResourceGroupNamespaceConfigListener.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9yZXNvdXJjZWdyb3VwL1Jlc291cmNlR3JvdXBOYW1lc3BhY2VDb25maWdMaXN0ZW5lci5qYXZh) | | |
   | [...g/apache/pulsar/broker/admin/impl/TenantsBase.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi9pbXBsL1RlbmFudHNCYXNlLmphdmE=) | | |
   | [...sar/broker/resourcegroup/ResourceGroupService.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9yZXNvdXJjZWdyb3VwL1Jlc291cmNlR3JvdXBTZXJ2aWNlLmphdmE=) | | |
   | [.../java/org/apache/pulsar/broker/admin/v3/Sinks.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9hZG1pbi92My9TaW5rcy5qYXZh) | | |
   | [...lsar/client/impl/schema/NativeAvroBytesSchema.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL3NjaGVtYS9OYXRpdmVBdnJvQnl0ZXNTY2hlbWEuamF2YQ==) | | |
   | [...e/HashRangeExclusiveStickyKeyConsumerSelector.java](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWJyb2tlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2Jyb2tlci9zZXJ2aWNlL0hhc2hSYW5nZUV4Y2x1c2l2ZVN0aWNreUtleUNvbnN1bWVyU2VsZWN0b3IuamF2YQ==) | | |
   | ... and [653 more](https://codecov.io/gh/apache/pulsar/pull/18307/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1024004437


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java:
##########
@@ -89,35 +89,6 @@ public void produceAndCommitTest() throws Exception {
         produceTest(true);
     }
 
-    @Test
-    public void testDeleteNamespaceBeforeCommit() throws Exception {

Review Comment:
   This test is strange. The expected behavior is the namespace can be deleted by force when 
    there are transactions are used to send a message. But the test is executed in the opposite logic.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1024004437


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java:
##########
@@ -89,35 +89,6 @@ public void produceAndCommitTest() throws Exception {
         produceTest(true);
     }
 
-    @Test
-    public void testDeleteNamespaceBeforeCommit() throws Exception {

Review Comment:
   This test is strange. The expected behavior is the namespace can be deleted by force when 
    there are transactions used to send a message. But the test is executed in the opposite logic.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1013561593


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -218,38 +218,47 @@ protected CompletableFuture<Void> internalDeleteNamespaceAsync(boolean force) {
                          }))
                 .thenCompose(topics -> {
                     List<String> allTopics = topics.get(0);
+                    ArrayList<String> copyAllTopics = new ArrayList<>();
                     List<String> allPartitionedTopics = topics.get(1);
-                    if (!force) {
-                        boolean hasNonSystemTopic = false;
-                        for (String topic : allTopics) {
-                            if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
-                                hasNonSystemTopic = true;
-                                break;
-                            }
+                    ArrayList<String> copyAllPartitionTopics = new ArrayList<>();
+                    boolean hasNonSystemTopic = false;
+                    List<String> allSystemTopics = new ArrayList<>();
+                    List<String> allPartitionedSystemTopics = new ArrayList<>();
+                    for (String topic : allTopics) {
+                        if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
+                            hasNonSystemTopic = true;
+                            copyAllTopics.add(topic);
+                        } else {
+                            allSystemTopics.add(topic);
                         }
-                        if (!hasNonSystemTopic) {
-                            for (String topic : allPartitionedTopics) {
-                                if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
-                                    hasNonSystemTopic = true;
-                                    break;
-                                }
-                            }
+                    }
+                    for (String topic : allPartitionedTopics) {
+                        if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
+                            hasNonSystemTopic = true;
+                            copyAllPartitionTopics.add(topic);
+                        } else {
+                            allPartitionedSystemTopics.add(topic);
                         }
-
+                    }
+                    if (!force) {
                         if (hasNonSystemTopic) {
                             throw new RestException(Status.CONFLICT, "Cannot delete non empty namespace");
                         }
                     }
                     return namespaceResources().setPoliciesAsync(namespaceName, old -> {
                         old.deleted = true;
                         return  old;
-                    }).thenCompose(__ -> {
-                        return internalDeleteTopicsAsync(allTopics);
-                    }).thenCompose(__ -> {
-                        return internalDeletePartitionedTopicsAsync(allPartitionedTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeleteTopicsAsync(copyAllTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeletePartitionedTopicsAsync(copyAllPartitionTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeleteTopicsAsync(allSystemTopics);
+                    }).thenCompose(ignore__ -> {
+                        return internalDeletePartitionedTopicsAsync(allPartitionedSystemTopics);

Review Comment:
   In fact, deleting the namespace in TransactionTest is just like this, there are systemtopic[`__change_event`, `__transaction_buffer_snapshot`] and normal topic[`test`, `testDeleteNamespaceAfterUsedTransaction`] in the namespace.
   But you are right, we can add `assertTrue` to make it clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- closed pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
Technoboy- closed pull request #18307: [fix][broker] Fix can not delete namespace by force
URL: https://github.com/apache/pulsar/pull/18307


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] liangyepianzhou commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
liangyepianzhou commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1301601333

   @Technoboy-  Why the namespace should not be deleted here.
   https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java#L116


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
poorbarcode commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1012483348


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -1207,7 +1207,14 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions,
                         brokerService.deleteTopicAuthenticationWithRetry(topic, deleteTopicAuthenticationFuture, 5);
 
                         deleteTopicAuthenticationFuture.thenCompose(__ -> deleteSchema())
-                                .thenCompose(__ -> deleteTopicPolicies())
+                                .thenCompose(__ -> {
+                                    if (!this.getBrokerService().getPulsar().getBrokerService()

Review Comment:
   Is only the system topic `__change_event` not required policies?



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java:
##########
@@ -231,7 +232,7 @@ public void testCreateTransactionSystemTopic() throws Exception {
 
         // getList does not include transaction system topic
         List<String> list = admin.topics().getList(NAMESPACE1);
-        assertEquals(list.size(), 2);
+        assertEquals(list.size(), 1);

Review Comment:
   Seems we don't care how many topics here, suggestion `assertFalse(list.isEmpty())`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] Technoboy- commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1306824090

   @mattisonchao Could you help review this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] poorbarcode commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
poorbarcode commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1013556251


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -1207,7 +1207,14 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions,
                         brokerService.deleteTopicAuthenticationWithRetry(topic, deleteTopicAuthenticationFuture, 5);
 
                         deleteTopicAuthenticationFuture.thenCompose(__ -> deleteSchema())
-                                .thenCompose(__ -> deleteTopicPolicies())
+                                .thenCompose(__ -> {
+                                    if (!this.getBrokerService().getPulsar().getBrokerService()

Review Comment:
   I think about it carefully, and now it's reasonable(even if other system topics have policies). Because:
   
   - Deleting `__change_event` deletes all the policies for the topic.
   - Except for deleting the namespace, no other situation will delete `__change_event`.
   
   Should we add some code-comment and a test for this?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -218,38 +218,47 @@ protected CompletableFuture<Void> internalDeleteNamespaceAsync(boolean force) {
                          }))
                 .thenCompose(topics -> {
                     List<String> allTopics = topics.get(0);
+                    ArrayList<String> copyAllTopics = new ArrayList<>();
                     List<String> allPartitionedTopics = topics.get(1);
-                    if (!force) {
-                        boolean hasNonSystemTopic = false;
-                        for (String topic : allTopics) {
-                            if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
-                                hasNonSystemTopic = true;
-                                break;
-                            }
+                    ArrayList<String> copyAllPartitionTopics = new ArrayList<>();
+                    boolean hasNonSystemTopic = false;
+                    List<String> allSystemTopics = new ArrayList<>();
+                    List<String> allPartitionedSystemTopics = new ArrayList<>();
+                    for (String topic : allTopics) {
+                        if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
+                            hasNonSystemTopic = true;
+                            copyAllTopics.add(topic);
+                        } else {
+                            allSystemTopics.add(topic);
                         }
-                        if (!hasNonSystemTopic) {
-                            for (String topic : allPartitionedTopics) {
-                                if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
-                                    hasNonSystemTopic = true;
-                                    break;
-                                }
-                            }
+                    }
+                    for (String topic : allPartitionedTopics) {
+                        if (!pulsar().getBrokerService().isSystemTopic(TopicName.get(topic))) {
+                            hasNonSystemTopic = true;
+                            copyAllPartitionTopics.add(topic);
+                        } else {
+                            allPartitionedSystemTopics.add(topic);
                         }
-
+                    }
+                    if (!force) {
                         if (hasNonSystemTopic) {
                             throw new RestException(Status.CONFLICT, "Cannot delete non empty namespace");
                         }
                     }
                     return namespaceResources().setPoliciesAsync(namespaceName, old -> {
                         old.deleted = true;
                         return  old;
-                    }).thenCompose(__ -> {
-                        return internalDeleteTopicsAsync(allTopics);
-                    }).thenCompose(__ -> {
-                        return internalDeletePartitionedTopicsAsync(allPartitionedTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeleteTopicsAsync(copyAllTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeletePartitionedTopicsAsync(copyAllPartitionTopics);
+                    }).thenCompose(ignore -> {
+                        return internalDeleteTopicsAsync(allSystemTopics);
+                    }).thenCompose(ignore__ -> {
+                        return internalDeletePartitionedTopicsAsync(allPartitionedSystemTopics);

Review Comment:
   We should add a separate test: Delete namespaces that contain both system topic and non-system topic, preferably with topics ordered like this `[__change_event, non-system-topic]`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] nicoloboschi commented on pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
nicoloboschi commented on PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#issuecomment-1340985531

   In case you want to delete the namespace and this fix is not on the broker, the workaround is to manually delete the topics in the namespace created by the users and then trigger the namespace deletion again, right @liangyepianzhou ?  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codelipenghui commented on a diff in pull request #18307: [fix][broker] Fix can not delete namespace by force

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #18307:
URL: https://github.com/apache/pulsar/pull/18307#discussion_r1023989216


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionProduceTest.java:
##########
@@ -89,35 +89,6 @@ public void produceAndCommitTest() throws Exception {
         produceTest(true);
     }
 
-    @Test
-    public void testDeleteNamespaceBeforeCommit() throws Exception {

Review Comment:
   Why we should delete the entire test?
   If the expected behavior is the transaction is not allowed to commit. We can just change the test to check the expected exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org