thetumbled commented on code in PR #21692:
URL: https://github.com/apache/pulsar/pull/21692#discussion_r1618136680


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java:
##########
@@ -1313,6 +1314,66 @@ public void 
testCheckInactiveSubscriptionsShouldNotDeleteCompactionCursor() thro
 
     }
 
+    @Test
+    public void testCheckInactiveSubscriptionWhenNoMessageToAck() throws 
Exception {
+        String namespace = "prop/testInactiveSubscriptionWhenNoMessageToAck";
+
+        try {
+            admin.namespaces().createNamespace(namespace);
+        } catch (PulsarAdminException.ConflictException e) {
+            // Ok.. (if test fails intermittently and namespace is already 
created)
+        }
+        // set enable subscription expiration.
+        admin.namespaces().setSubscriptionExpirationTime(namespace, 1);
+
+        String topic = "persistent://" + namespace + "/my-topic";
+        Producer<byte[]> producer = 
pulsarClient.newProducer().topic(topic).create();
+        producer.send("test".getBytes());
+        producer.close();
+
+        // create consumer to consume all messages
+        Consumer<byte[]> consumer = 
pulsarClient.newConsumer().topic(topic).subscriptionName("sub1")
+                
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest).subscribe();
+        consumer.acknowledge(consumer.receive());
+
+        Optional<Topic> topicOptional = 
pulsar.getBrokerService().getTopic(topic, true).get();
+        assertTrue(topicOptional.isPresent());
+        PersistentTopic persistentTopic = (PersistentTopic) 
topicOptional.get();
+
+        // wait for 1min, but consumer is still connected all the time.
+        // so subscription should not be deleted.
+        Thread.sleep(60000);
+        persistentTopic.checkInactiveSubscriptions();
+        assertTrue(persistentTopic.getSubscriptions().containsKey("sub1"));
+        PersistentSubscription sub = persistentTopic.getSubscription("sub1");
+
+        // shutdown pulsar ungracefully
+        // disable the updateLastActive method to simulate the ungraceful 
shutdown

Review Comment:
   We can't ensure that the updated timestamp is persisted in crash time. With 
this PR, we can fix most of the cases, as we update it every time broker do 
expiration check.
   But strictly speaking, we can't fix all the cases. If we always fail to 
persist the cursor info, the incorrect sub deletion occurs too.
   Incorrect deletion of subscription causes serious consequence, such as 
duplication or data lost. In my opinion, missing deletions are better than 
incorrect deletion, this is PR https://github.com/apache/pulsar/pull/22794 try 
to do.
   
   



-- 
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-unsubscr...@pulsar.apache.org

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

Reply via email to