use of org.apache.pulsar.broker.delayed.DelayedDeliveryTrackerFactory in project pulsar by apache.
the class BrokerService method closeAsync.
public CompletableFuture<Void> closeAsync() {
try {
log.info("Shutting down Pulsar Broker service");
// unloads all namespaces gracefully without disrupting mutually
unloadNamespaceBundlesGracefully();
// close replication clients
replicationClients.forEach((cluster, client) -> {
try {
client.shutdown();
} catch (Exception e) {
log.warn("Error shutting down repl client for cluster {}", cluster, e);
}
});
// close replication admins
clusterAdmins.forEach((cluster, admin) -> {
try {
admin.close();
} catch (Exception e) {
log.warn("Error shutting down repl admin for cluster {}", cluster, e);
}
});
// close entry filters
if (entryFilters != null) {
entryFilters.forEach((name, filter) -> {
try {
filter.close();
} catch (Exception e) {
log.warn("Error shutting down entry filter {}", name, e);
}
});
}
CompletableFuture<CompletableFuture<Void>> cancellableDownstreamFutureReference = new CompletableFuture<>();
log.info("Event loops shutting down gracefully...");
List<CompletableFuture<?>> shutdownEventLoops = new ArrayList<>();
shutdownEventLoops.add(shutdownEventLoopGracefully(acceptorGroup));
shutdownEventLoops.add(shutdownEventLoopGracefully(workerGroup));
for (EventLoopGroup group : protocolHandlersWorkerGroups) {
shutdownEventLoops.add(shutdownEventLoopGracefully(group));
}
CompletableFuture<Void> shutdownFuture = CompletableFuture.allOf(shutdownEventLoops.toArray(new CompletableFuture[0])).handle((v, t) -> {
if (t != null) {
log.warn("Error shutting down event loops gracefully", t);
} else {
log.info("Event loops shutdown completed.");
}
return null;
}).thenCompose(__ -> {
log.info("Continuing to second phase in shutdown.");
List<CompletableFuture<Void>> asyncCloseFutures = new ArrayList<>();
listenChannels.forEach(ch -> {
if (ch.isOpen()) {
asyncCloseFutures.add(closeChannel(ch));
}
});
if (interceptor != null) {
interceptor.close();
interceptor = null;
}
try {
authenticationService.close();
} catch (IOException e) {
log.warn("Error in closing authenticationService", e);
}
pulsarStats.close();
try {
delayedDeliveryTrackerFactory.close();
} catch (IOException e) {
log.warn("Error in closing delayedDeliveryTrackerFactory", e);
}
asyncCloseFutures.add(GracefulExecutorServicesShutdown.initiate().timeout(Duration.ofMillis((long) (GRACEFUL_SHUTDOWN_TIMEOUT_RATIO_OF_TOTAL_TIMEOUT * pulsar.getConfiguration().getBrokerShutdownTimeoutMs()))).shutdown(statsUpdater, inactivityMonitor, messageExpiryMonitor, compactionMonitor, consumedLedgersMonitor, backlogQuotaChecker, topicOrderedExecutor, topicPublishRateLimiterMonitor, brokerPublishRateLimiterMonitor, deduplicationSnapshotMonitor).handle());
CompletableFuture<Void> combined = FutureUtil.waitForAllAndSupportCancel(asyncCloseFutures);
cancellableDownstreamFutureReference.complete(combined);
combined.handle((v, t) -> {
if (t == null) {
log.info("Broker service completely shut down");
} else {
if (t instanceof CancellationException) {
log.warn("Broker service didn't complete gracefully. " + "Terminating Broker service.");
} else {
log.warn("Broker service shut down completed with exception", t);
}
}
return null;
});
return combined;
});
FutureUtil.whenCancelledOrTimedOut(shutdownFuture, () -> cancellableDownstreamFutureReference.thenAccept(future -> future.cancel(false)));
return shutdownFuture;
} catch (Exception e) {
return FutureUtil.failedFuture(e);
}
}
use of org.apache.pulsar.broker.delayed.DelayedDeliveryTrackerFactory in project pulsar by yahoo.
the class BrokerService method closeAsync.
public CompletableFuture<Void> closeAsync() {
try {
log.info("Shutting down Pulsar Broker service");
// unloads all namespaces gracefully without disrupting mutually
unloadNamespaceBundlesGracefully();
// close replication clients
replicationClients.forEach((cluster, client) -> {
try {
client.shutdown();
} catch (Exception e) {
log.warn("Error shutting down repl client for cluster {}", cluster, e);
}
});
// close replication admins
clusterAdmins.forEach((cluster, admin) -> {
try {
admin.close();
} catch (Exception e) {
log.warn("Error shutting down repl admin for cluster {}", cluster, e);
}
});
// close entry filters
if (entryFilters != null) {
entryFilters.forEach((name, filter) -> {
try {
filter.close();
} catch (Exception e) {
log.warn("Error shutting down entry filter {}", name, e);
}
});
}
CompletableFuture<CompletableFuture<Void>> cancellableDownstreamFutureReference = new CompletableFuture<>();
log.info("Event loops shutting down gracefully...");
List<CompletableFuture<?>> shutdownEventLoops = new ArrayList<>();
shutdownEventLoops.add(shutdownEventLoopGracefully(acceptorGroup));
shutdownEventLoops.add(shutdownEventLoopGracefully(workerGroup));
for (EventLoopGroup group : protocolHandlersWorkerGroups) {
shutdownEventLoops.add(shutdownEventLoopGracefully(group));
}
CompletableFuture<Void> shutdownFuture = CompletableFuture.allOf(shutdownEventLoops.toArray(new CompletableFuture[0])).handle((v, t) -> {
if (t != null) {
log.warn("Error shutting down event loops gracefully", t);
} else {
log.info("Event loops shutdown completed.");
}
return null;
}).thenCompose(__ -> {
log.info("Continuing to second phase in shutdown.");
List<CompletableFuture<Void>> asyncCloseFutures = new ArrayList<>();
listenChannels.forEach(ch -> {
if (ch.isOpen()) {
asyncCloseFutures.add(closeChannel(ch));
}
});
if (interceptor != null) {
interceptor.close();
interceptor = null;
}
try {
authenticationService.close();
} catch (IOException e) {
log.warn("Error in closing authenticationService", e);
}
pulsarStats.close();
try {
delayedDeliveryTrackerFactory.close();
} catch (IOException e) {
log.warn("Error in closing delayedDeliveryTrackerFactory", e);
}
asyncCloseFutures.add(GracefulExecutorServicesShutdown.initiate().timeout(Duration.ofMillis((long) (GRACEFUL_SHUTDOWN_TIMEOUT_RATIO_OF_TOTAL_TIMEOUT * pulsar.getConfiguration().getBrokerShutdownTimeoutMs()))).shutdown(statsUpdater, inactivityMonitor, messageExpiryMonitor, compactionMonitor, consumedLedgersMonitor, backlogQuotaChecker, topicOrderedExecutor, topicPublishRateLimiterMonitor.scheduler, brokerPublishRateLimiterMonitor.scheduler, deduplicationSnapshotMonitor).handle());
CompletableFuture<Void> combined = FutureUtil.waitForAllAndSupportCancel(asyncCloseFutures);
cancellableDownstreamFutureReference.complete(combined);
combined.handle((v, t) -> {
if (t == null) {
log.info("Broker service completely shut down");
} else {
if (t instanceof CancellationException) {
log.warn("Broker service didn't complete gracefully. " + "Terminating Broker service.");
} else {
log.warn("Broker service shut down completed with exception", t);
}
}
return null;
});
return combined;
});
FutureUtil.whenCancelledOrTimedOut(shutdownFuture, () -> cancellableDownstreamFutureReference.thenAccept(future -> future.cancel(false)));
return shutdownFuture;
} catch (Exception e) {
return FutureUtil.failedFuture(e);
}
}
use of org.apache.pulsar.broker.delayed.DelayedDeliveryTrackerFactory in project incubator-pulsar by apache.
the class BrokerService method closeAsync.
public CompletableFuture<Void> closeAsync() {
try {
log.info("Shutting down Pulsar Broker service");
// unloads all namespaces gracefully without disrupting mutually
unloadNamespaceBundlesGracefully();
// close replication clients
replicationClients.forEach((cluster, client) -> {
try {
client.shutdown();
} catch (Exception e) {
log.warn("Error shutting down repl client for cluster {}", cluster, e);
}
});
// close replication admins
clusterAdmins.forEach((cluster, admin) -> {
try {
admin.close();
} catch (Exception e) {
log.warn("Error shutting down repl admin for cluster {}", cluster, e);
}
});
// close entry filters
if (entryFilters != null) {
entryFilters.forEach((name, filter) -> {
try {
filter.close();
} catch (Exception e) {
log.warn("Error shutting down entry filter {}", name, e);
}
});
}
CompletableFuture<CompletableFuture<Void>> cancellableDownstreamFutureReference = new CompletableFuture<>();
log.info("Event loops shutting down gracefully...");
List<CompletableFuture<?>> shutdownEventLoops = new ArrayList<>();
shutdownEventLoops.add(shutdownEventLoopGracefully(acceptorGroup));
shutdownEventLoops.add(shutdownEventLoopGracefully(workerGroup));
for (EventLoopGroup group : protocolHandlersWorkerGroups) {
shutdownEventLoops.add(shutdownEventLoopGracefully(group));
}
CompletableFuture<Void> shutdownFuture = CompletableFuture.allOf(shutdownEventLoops.toArray(new CompletableFuture[0])).handle((v, t) -> {
if (t != null) {
log.warn("Error shutting down event loops gracefully", t);
} else {
log.info("Event loops shutdown completed.");
}
return null;
}).thenCompose(__ -> {
log.info("Continuing to second phase in shutdown.");
List<CompletableFuture<Void>> asyncCloseFutures = new ArrayList<>();
listenChannels.forEach(ch -> {
if (ch.isOpen()) {
asyncCloseFutures.add(closeChannel(ch));
}
});
if (interceptor != null) {
interceptor.close();
interceptor = null;
}
try {
authenticationService.close();
} catch (IOException e) {
log.warn("Error in closing authenticationService", e);
}
pulsarStats.close();
try {
delayedDeliveryTrackerFactory.close();
} catch (IOException e) {
log.warn("Error in closing delayedDeliveryTrackerFactory", e);
}
asyncCloseFutures.add(GracefulExecutorServicesShutdown.initiate().timeout(Duration.ofMillis((long) (GRACEFUL_SHUTDOWN_TIMEOUT_RATIO_OF_TOTAL_TIMEOUT * pulsar.getConfiguration().getBrokerShutdownTimeoutMs()))).shutdown(statsUpdater, inactivityMonitor, messageExpiryMonitor, compactionMonitor, consumedLedgersMonitor, backlogQuotaChecker, topicOrderedExecutor, topicPublishRateLimiterMonitor.scheduler, brokerPublishRateLimiterMonitor.scheduler, deduplicationSnapshotMonitor).handle());
CompletableFuture<Void> combined = FutureUtil.waitForAllAndSupportCancel(asyncCloseFutures);
cancellableDownstreamFutureReference.complete(combined);
combined.handle((v, t) -> {
if (t == null) {
log.info("Broker service completely shut down");
} else {
if (t instanceof CancellationException) {
log.warn("Broker service didn't complete gracefully. " + "Terminating Broker service.");
} else {
log.warn("Broker service shut down completed with exception", t);
}
}
return null;
});
return combined;
});
FutureUtil.whenCancelledOrTimedOut(shutdownFuture, () -> cancellableDownstreamFutureReference.thenAccept(future -> future.cancel(false)));
return shutdownFuture;
} catch (Exception e) {
return FutureUtil.failedFuture(e);
}
}
Aggregations