You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lhotari (via GitHub)" <gi...@apache.org> on 2024/04/25 20:15:48 UTC
[PR] [improve][broker] Close TopicPoliciesService to allow Pulsar broker graceful shutdown [pulsar]
lhotari opened a new pull request, #22589:
URL: https://github.com/apache/pulsar/pull/22589
### Motivation
There doesn't seem to be a proper handling for TopicPoliciesService shutdown.
This would be needed to allow the Pulsar broker to shutdown gracefully.
This also prevents memory leaks in tests. This problem was detected during the investigation of test OOMEs.
See #22588 for details.
### Modifications
- Add close method to TopicPoliciesService and implement it
- Use Pulsar's executor for the AsyncLoader in TopicPoliciesService
- make shutdown synchronous
- Improve the close method of SystemTopicTxnBufferSnapshotService
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
--
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-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][broker] Close TopicPoliciesService to allow Pulsar broker graceful shutdown [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #22589:
URL: https://github.com/apache/pulsar/pull/22589#discussion_r1581034618
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -110,11 +111,13 @@ public SystemTopicBasedTopicPoliciesService(PulsarService pulsarService) {
this.writerCaches = Caffeine.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)
.removalListener((namespaceName, writer, cause) -> {
- ((SystemTopicClient.Writer) writer).closeAsync().exceptionally(ex -> {
- log.error("[{}] Close writer error.", namespaceName, ex);
- return null;
- });
+ try {
+ ((SystemTopicClient.Writer) writer).close();
+ } catch (IOException e) {
Review Comment:
done
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicTxnBufferSnapshotService.java:
##########
@@ -142,8 +143,26 @@ private SystemTopicClient<T> getTransactionBufferSystemTopicClient(NamespaceName
public void close() throws Exception {
for (Map.Entry<NamespaceName, SystemTopicClient<T>> entry : clients.entrySet()) {
- entry.getValue().close();
+ try {
+ entry.getValue().close();
+ } catch (Exception e) {
+ log.error("Failed to close system topic client for namespace {}", entry.getKey(), e);
+ }
+ }
+ clients.clear();
+ for (Map.Entry<NamespaceName, ReferenceCountedWriter<T>> entry : refCountedWriterMap.entrySet()) {
+ CompletableFuture<SystemTopicClient.Writer<T>> future = entry.getValue().getFuture();
+ if (!future.isCompletedExceptionally()) {
+ future.thenAccept(writer -> {
+ try {
+ writer.close();
+ } catch (IOException e) {
Review Comment:
done
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -740,4 +743,21 @@ protected AsyncLoadingCache<NamespaceName, SystemTopicClient.Writer<PulsarEvent>
}
private static final Logger log = LoggerFactory.getLogger(SystemTopicBasedTopicPoliciesService.class);
+
+ @Override
+ public void close() throws Exception {
+ writerCaches.synchronous().invalidateAll();
+ readerCaches.values().forEach(future -> {
+ if (future != null && !future.isCompletedExceptionally()) {
+ future.thenAccept(reader -> {
+ try {
+ reader.close();
+ } catch (IOException e) {
Review Comment:
done
--
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-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][broker] Close TopicPoliciesService to allow Pulsar broker graceful shutdown [pulsar]
Posted by "heesung-sn (via GitHub)" <gi...@apache.org>.
heesung-sn commented on code in PR #22589:
URL: https://github.com/apache/pulsar/pull/22589#discussion_r1580122532
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -110,11 +111,13 @@ public SystemTopicBasedTopicPoliciesService(PulsarService pulsarService) {
this.writerCaches = Caffeine.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)
.removalListener((namespaceName, writer, cause) -> {
- ((SystemTopicClient.Writer) writer).closeAsync().exceptionally(ex -> {
- log.error("[{}] Close writer error.", namespaceName, ex);
- return null;
- });
+ try {
+ ((SystemTopicClient.Writer) writer).close();
+ } catch (IOException e) {
Review Comment:
Maybe catching `Exception` might be safer?
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicTxnBufferSnapshotService.java:
##########
@@ -142,8 +143,26 @@ private SystemTopicClient<T> getTransactionBufferSystemTopicClient(NamespaceName
public void close() throws Exception {
for (Map.Entry<NamespaceName, SystemTopicClient<T>> entry : clients.entrySet()) {
- entry.getValue().close();
+ try {
+ entry.getValue().close();
+ } catch (Exception e) {
+ log.error("Failed to close system topic client for namespace {}", entry.getKey(), e);
+ }
+ }
+ clients.clear();
+ for (Map.Entry<NamespaceName, ReferenceCountedWriter<T>> entry : refCountedWriterMap.entrySet()) {
+ CompletableFuture<SystemTopicClient.Writer<T>> future = entry.getValue().getFuture();
+ if (!future.isCompletedExceptionally()) {
+ future.thenAccept(writer -> {
+ try {
+ writer.close();
+ } catch (IOException e) {
Review Comment:
Maybe catching `Exception` might be safer?
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java:
##########
@@ -740,4 +743,21 @@ protected AsyncLoadingCache<NamespaceName, SystemTopicClient.Writer<PulsarEvent>
}
private static final Logger log = LoggerFactory.getLogger(SystemTopicBasedTopicPoliciesService.class);
+
+ @Override
+ public void close() throws Exception {
+ writerCaches.synchronous().invalidateAll();
+ readerCaches.values().forEach(future -> {
+ if (future != null && !future.isCompletedExceptionally()) {
+ future.thenAccept(reader -> {
+ try {
+ reader.close();
+ } catch (IOException e) {
Review Comment:
Maybe catching `Exception` might be safer?
--
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-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [improve][broker] Close TopicPoliciesService to allow Pulsar broker graceful shutdown [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari merged PR #22589:
URL: https://github.com/apache/pulsar/pull/22589
--
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-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org