-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] The topic might reference a closed ledger #22739
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1007,6 +1007,9 @@ public CompletableFuture<Optional<Topic>> getTopic(final TopicName topicName, bo | |
| CompletableFuture<Optional<Topic>> topicFuture = topics.get(topicName.toString()); | ||
| if (topicFuture != null) { | ||
| if (topicFuture.isCompletedExceptionally() | ||
| && FutureUtil.getException(topicFuture).get().equals(FAILED_TO_LOAD_TOPIC_TIMEOUT_EXCEPTION)) { | ||
| return FutureUtil.failedFuture(FAILED_TO_LOAD_TOPIC_TIMEOUT_EXCEPTION); | ||
|
Comment on lines
+1010
to
+1011
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to suggest to follow the solution from this PR #22283
The existing code has mixed them which will introduce contention for the get topic operation. Now, we checked the topic load timeout exception, but don't know how many others we also need to check.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with these points. Actually, I tried do that: https://github.com/shibd/pulsar/pull/38/files But, I got some tests that not pass, So, I used this short-term solution. I'm going to continue to look into it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new solution refer to this PR: #22860 |
||
| } else if (topicFuture.isCompletedExceptionally() | ||
| || (topicFuture.isDone() && !topicFuture.getNow(Optional.empty()).isPresent())) { | ||
| // Exceptional topics should be recreated. | ||
| topics.remove(topicName.toString(), topicFuture); | ||
|
|
@@ -1744,6 +1747,7 @@ public void openLedgerComplete(ManagedLedger ledger, Object ctx) { | |
| + " topic", topic, FutureUtil.getException(topicFuture)); | ||
| executor().submit(() -> { | ||
| persistentTopic.close().whenComplete((ignore, ex) -> { | ||
| topics.remove(topic, topicFuture); | ||
| if (ex != null) { | ||
| log.warn("[{}] Get an error when closing topic.", | ||
| topic, ex); | ||
|
|
@@ -1760,6 +1764,7 @@ public void openLedgerComplete(ManagedLedger ledger, Object ctx) { | |
| + " Removing topic from topics list {}, {}", topic, ex); | ||
| executor().submit(() -> { | ||
| persistentTopic.close().whenComplete((ignore, closeEx) -> { | ||
| topics.remove(topic, topicFuture); | ||
| if (closeEx != null) { | ||
| log.warn("[{}] Get an error when closing topic.", | ||
| topic, closeEx); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,10 @@ | |
| package org.apache.pulsar.broker.service; | ||
|
|
||
| import static org.apache.pulsar.broker.BrokerTestUtil.newUniqueName; | ||
| import static org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.retryStrategically; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doAnswer; | ||
| import static org.mockito.Mockito.spy; | ||
| import static org.testng.Assert.assertEquals; | ||
| import static org.testng.Assert.assertNotEquals; | ||
| import static org.testng.Assert.assertNotNull; | ||
| import static org.testng.Assert.assertNull; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
@@ -1434,13 +1432,6 @@ public void testCleanupTopic() throws Exception { | |
| // Ok | ||
| } | ||
|
|
||
| final CompletableFuture<Optional<Topic>> timedOutTopicFuture = topicFuture; | ||
| // timeout topic future should be removed from cache | ||
| retryStrategically((test) -> pulsar1.getBrokerService().getTopic(topicName, false) != timedOutTopicFuture, 5, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit test assumes a manager ledger that can never be completed to mock topic create timeout, which does not make sense in a production scenario. Remove this assertion, and add an assertion afterward: |
||
| 1000); | ||
|
|
||
| assertNotEquals(timedOutTopicFuture, pulsar1.getBrokerService().getTopics().get(topicName)); | ||
|
|
||
| try { | ||
| Consumer<byte[]> consumer = client1.newConsumer().topic(topicName).subscriptionType(SubscriptionType.Shared) | ||
| .subscriptionName("my-subscriber-name").subscribeAsync().get(100, TimeUnit.MILLISECONDS); | ||
|
|
@@ -1452,6 +1443,12 @@ public void testCleanupTopic() throws Exception { | |
| ManagedLedgerImpl ml = (ManagedLedgerImpl) mlFactory.open(topicMlName + "-2"); | ||
| mlFuture.complete(ml); | ||
|
|
||
| // Once ml is created, topic should be removed due timeout. | ||
| Awaitility.await().ignoreExceptions().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { | ||
| assertNull(pulsar1.getBrokerService().getTopics().get(topicName)); | ||
| }); | ||
|
|
||
| // Re-create topic will success. | ||
| Consumer<byte[]> consumer = client1.newConsumer().topic(topicName).subscriptionName("my-subscriber-name") | ||
| .subscriptionType(SubscriptionType.Shared).subscribeAsync() | ||
| .get(2 * topicLoadTimeoutSeconds, TimeUnit.SECONDS); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.