poorbarcode commented on code in PR #24366:
URL: https://github.com/apache/pulsar/pull/24366#discussion_r2127081825
##########
pulsar-broker/src/main/java/org/apache/pulsar/client/impl/RawReaderImpl.java:
##########
@@ -137,6 +138,13 @@ static class RawConsumerImpl extends ConsumerImpl<byte[]> {
pendingRawReceives = new ConcurrentLinkedQueue<>();
}
+ protected boolean isUnrecoverableError(Throwable t) {
+ if (t instanceof PulsarClientException.ServiceNotReadyException) {
+ return false;
+ }
+ return super.isUnrecoverableError(t);
+ }
+
Review Comment:
- Added a new param named `retryOnRecoverableErrors`
- And added a new test named
`RawReaderTest.testReconnectsWhenServiceNotReady` to cover the case that the
raw-read continuously reconnects if `retryOnRecoverableErrors ` is `true`
##########
pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactionTest.java:
##########
@@ -2320,6 +2328,65 @@ public void testAcknowledgeWithReconnection() throws
Exception {
producer.close();
}
+ @Test(timeOut = 120 * 1000)
+ public void testConcurrentCompactionAndTopicDelete() throws Exception {
+ final String topicName =
newUniqueName("persistent://my-tenant/my-ns/tp");
+ admin.topics().createNonPartitionedTopic(topicName);
+ // Load up the topic.
+ Producer<String> producer =
pulsarClient.newProducer(Schema.STRING).topic(topicName).create();
+
+ // Inject a reading delay to the compaction task,
+ PersistentTopic persistentTopic =
+ (PersistentTopic)
pulsar.getBrokerService().getTopic(topicName, false).join().get();
+ ManagedLedgerImpl ml = (ManagedLedgerImpl)
persistentTopic.getManagedLedger();
+ ManagedCursor compactionCursor =
ml.openCursor(COMPACTION_SUBSCRIPTION);
+ ManagedCursor spyCompactionCursor = spy(compactionCursor);
+ CountDownLatch delayReadSignal = new CountDownLatch(1);
+ Answer answer = new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocationOnMock) throws
Throwable {
+ delayReadSignal.await();
+ return invocationOnMock.callRealMethod();
+ }
+ };
+ doAnswer(answer).when(spyCompactionCursor).asyncReadEntries(anyInt(),
+ any(AsyncCallbacks.ReadEntriesCallback.class), any(),
any(Position.class));
+ doAnswer(answer).when(spyCompactionCursor).asyncReadEntries(anyInt(),
anyLong(),
+ any(AsyncCallbacks.ReadEntriesCallback.class), any(),
any(Position.class));
+
doAnswer(answer).when(spyCompactionCursor).asyncReadEntriesOrWait(anyInt(),
anyLong(),
+ any(AsyncCallbacks.ReadEntriesCallback.class), any(),
any(Position.class));
+ ml.getCursors().removeCursor(COMPACTION_SUBSCRIPTION);
+ ml.getCursors().add(spyCompactionCursor, ml.getLastConfirmedEntry());
+
+ // Trigger a compaction task.
+ for (int i = 0; i < 2000; i++) {
+
producer.newMessage().key(String.valueOf(i)).value(String.valueOf(i)).send();
+ }
+ ConsumerImpl<String> consumer = (ConsumerImpl<String>)
pulsarClient.newConsumer(Schema.STRING)
+ .topic(topicName).readCompacted(true).subscriptionName("s1")
+
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
+ .subscribe();
+ persistentTopic.triggerCompaction();
+ Awaitility.await().untilAsserted(() -> {
+
assertEquals(persistentTopic.getSubscriptions().get(COMPACTION_SUBSCRIPTION).getConsumers().size(),
1);
+ });
+
+ // Since we injected a delay reading, the compaction task started and
not finish yet.
+ // Call topic deletion, they two tasks are concurrently executed.
+ producer.close();
+ consumer.close();
+ CompletableFuture<Void> deleteTopicFuture =
persistentTopic.deleteForcefully();
+
+ // Remove the injection after 3s.
+ Thread.sleep(3000);
+ delayReadSignal.countDown();
+
+ // Verify: topic deletion is successfully executed.
+ Awaitility.await().atMost(15, TimeUnit.SECONDS).untilAsserted(() -> {
+ assertTrue(deleteTopicFuture.isDone());
Review Comment:
Fixed
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]