Skip to content

[fix][broker] Fix can not delete namespace by force - #18307

Merged
Technoboy- merged 7 commits into
apache:masterfrom
liangyepianzhou:xiangying/fix/broker/deletenamespace
Nov 21, 2022
Merged

[fix][broker] Fix can not delete namespace by force#18307
Technoboy- merged 7 commits into
apache:masterfrom
liangyepianzhou:xiangying/fix/broker/deletenamespace

Conversation

@liangyepianzhou

Copy link
Copy Markdown
Contributor

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

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

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: liangyepianzhou#8

### 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 snapshot and clearing topic policies.
2. fix flaky test testCreateTransactionSystemTopic.
Test failed due to cleaning up after class.
### Modification
1. Delete normal topic and then delete system topic.
2. The system topic is not need to clean up topic policies.
@codecov-commenter

codecov-commenter commented Nov 3, 2022

Copy link
Copy Markdown

Codecov Report

Merging #18307 (a5ef7a3) into master (67d9d63) will increase coverage by 6.73%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #18307      +/-   ##
============================================
+ Coverage     40.29%   47.02%   +6.73%     
- Complexity     8685    10369    +1684     
============================================
  Files           687      692       +5     
  Lines         67441    67779     +338     
  Branches       7225     7260      +35     
============================================
+ Hits          27175    31876    +4701     
+ Misses        37257    32322    -4935     
- Partials       3009     3581     +572     
Flag Coverage Δ
unittests 47.02% <87.50%> (+6.73%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...che/bookkeeper/mledger/impl/ManagedCursorImpl.java 36.87% <0.00%> (-0.03%) ⬇️
...pache/pulsar/broker/admin/impl/NamespacesBase.java 62.80% <100.00%> (-1.10%) ⬇️
...sar/broker/service/persistent/PersistentTopic.java 61.66% <100.00%> (-0.09%) ⬇️
.../apache/pulsar/broker/loadbalance/LoadManager.java 61.11% <0.00%> (-16.67%) ⬇️
.../apache/pulsar/broker/admin/impl/PackagesBase.java 54.12% <0.00%> (-13.77%) ⬇️
...tent/NonPersistentDispatcherMultipleConsumers.java 40.74% <0.00%> (-12.35%) ⬇️
...apache/pulsar/broker/service/TopicListService.java 42.62% <0.00%> (-12.30%) ⬇️
...pulsar/broker/service/PulsarCommandSenderImpl.java 71.72% <0.00%> (-6.29%) ⬇️
...rg/apache/pulsar/broker/web/PulsarWebResource.java 53.79% <0.00%> (-4.66%) ⬇️
...oker/service/schema/SchemaRegistryServiceImpl.java 60.66% <0.00%> (-4.21%) ⬇️
... and 207 more

@liangyepianzhou

liangyepianzhou commented Nov 3, 2022

Copy link
Copy Markdown
Contributor Author

@Technoboy- Why the namespace should not be deleted here?

public void testDeleteNamespaceBeforeCommit() throws Exception {
final String topic = NAMESPACE1 + "/testDeleteTopicBeforeCommit";
PulsarClient pulsarClient = this.pulsarClient;
Transaction tnx = pulsarClient.newTransaction()
.withTransactionTimeout(60, TimeUnit.SECONDS)
.build().get();
long txnIdMostBits = ((TransactionImpl) tnx).getTxnIdMostBits();
long txnIdLeastBits = ((TransactionImpl) tnx).getTxnIdLeastBits();
Assert.assertTrue(txnIdMostBits > -1);
Assert.assertTrue(txnIdLeastBits > -1);
@Cleanup
Producer<byte[]> outProducer = pulsarClient
.newProducer()
.topic(topic)
.sendTimeout(0, TimeUnit.SECONDS)
.enableBatching(false)
.create();
String content = "Hello Txn";
outProducer.newMessage(tnx).value(content.getBytes(UTF_8)).send();
try {
deleteNamespaceGraceFully(NAMESPACE1, true);
} catch (Exception ignore) {}
tnx.commit().get();
}

@poorbarcode poorbarcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. left some comments.

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.

Can we add a test for this case?

@Technoboy-

Copy link
Copy Markdown
Contributor

@mattisonchao Could you help review this?

}

@Test
public void testDeleteNamespaceBeforeCommit() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@liangyepianzhou liangyepianzhou Nov 16, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Technoboy-

Technoboy- commented Nov 18, 2022

Copy link
Copy Markdown
Contributor

@Technoboy- Why the namespace should not be deleted here?

public void testDeleteNamespaceBeforeCommit() throws Exception {
final String topic = NAMESPACE1 + "/testDeleteTopicBeforeCommit";
PulsarClient pulsarClient = this.pulsarClient;
Transaction tnx = pulsarClient.newTransaction()
.withTransactionTimeout(60, TimeUnit.SECONDS)
.build().get();
long txnIdMostBits = ((TransactionImpl) tnx).getTxnIdMostBits();
long txnIdLeastBits = ((TransactionImpl) tnx).getTxnIdLeastBits();
Assert.assertTrue(txnIdMostBits > -1);
Assert.assertTrue(txnIdLeastBits > -1);
@Cleanup
Producer<byte[]> outProducer = pulsarClient
.newProducer()
.topic(topic)
.sendTimeout(0, TimeUnit.SECONDS)
.enableBatching(false)
.create();
String content = "Hello Txn";
outProducer.newMessage(tnx).value(content.getBytes(UTF_8)).send();
try {
deleteNamespaceGraceFully(NAMESPACE1, true);
} catch (Exception ignore) {}
tnx.commit().get();
}

Should be related with #14991. There is one case that the test did not coverage after discuss then. So add this test. Do you remember the case ? @codelipenghui @congbobo184 @mattisonchao

@Technoboy-
Technoboy- merged commit 6c9ff8f into apache:master Nov 21, 2022
@codelipenghui

Copy link
Copy Markdown
Contributor

@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.

@nicoloboschi

Copy link
Copy Markdown
Contributor

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 ?

@liangyepianzhou

Copy link
Copy Markdown
Contributor Author

@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.

nicoloboschi added a commit to datastax/pulsar that referenced this pull request Dec 7, 2022
nicoloboschi added a commit to datastax/pulsar that referenced this pull request Dec 7, 2022
congbobo184 pushed a commit that referenced this pull request Dec 8, 2022
…space by force) (#18803)

### Motivation
Cherry-pick #18307 for release 2.9.4.

### Modifications

Cherry-pick #18307 for release 2.9.4.
liangyepianzhou added a commit that referenced this pull request Dec 9, 2022
…e by force (#18307) (#18826)

### Motivation
Cherry-pick (#18307) to release 2.11.1.
### Modifications

Cherry-pick (#18307) to release 2.11.1.
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Dec 9, 2022
lifepuzzlefun pushed a commit to lifepuzzlefun/pulsar that referenced this pull request Jan 10, 2023
@liangyepianzhou
liangyepianzhou deleted the xiangying/fix/broker/deletenamespace branch February 27, 2023 03:27
@liangyepianzhou liangyepianzhou added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 1, 2023
@Technoboy-

Copy link
Copy Markdown
Contributor

Cherry-picked by #18826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants