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 2018/04/05 00:22:33 UTC
[GitHub] merlimat commented on a change in pull request #1352: Delete inactive subscriptions automatically
merlimat commented on a change in pull request #1352: Delete inactive subscriptions automatically
URL: https://github.com/apache/incubator-pulsar/pull/1352#discussion_r179320757
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
##########
@@ -1410,6 +1412,29 @@ public void checkGC(int gcIntervalInSeconds) {
}
}
+ @Override
+ public void checkInactiveSubscriptions() {
+ long expirationTime = brokerService.pulsar().getConfiguration().getSubscriptionExpirationTimeMinutes() * 1000 * 60;
+ if (expirationTime <= 0) return;
+
+ subscriptions.forEach((subName, sub) -> {
+ if (sub.getNumberOfEntriesInBacklog() == 0) return;
+ sub.peekNthMessage(1).thenAccept(entry -> {
+ ByteBuf messageMetadataAndPayload = entry.getDataBuffer();
+ PulsarApi.MessageMetadata md = Commands.parseMessageMetadata(messageMetadataAndPayload);
+ if (System.currentTimeMillis() - md.getPublishTime() > expirationTime) {
+ sub.delete().thenAccept(v ->
+ log.info("[{}][{}] The subscription was deleted due to expiration", topic, subName));
+ }
+ messageMetadataAndPayload.clear();
Review comment:
the buffer needs to be released instead of cleared to go back into pool:
```java
messageMetadataAndPayload.clear();
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services