kumaab commented on code in PR #1231:
URL: https://github.com/apache/ranger/pull/1231#discussion_r3992621771
##########
audit-server/audit-dispatcher/dispatcher-common/src/main/java/org/apache/ranger/audit/dispatcher/kafka/AuditDispatcherBase.java:
##########
@@ -205,16 +218,44 @@ protected void startDispatcherWorkers() {
for (int i = 0; i < dispatcherThreadCount; i++) {
String workerId = getDispatcherName().toLowerCase() + "-worker-" +
i;
- DispatcherWorker worker = createDispatcherWorker(workerId, new
ArrayList<>());
- dispatcherWorkers.put(workerId, worker);
- dispatcherThreadPool.submit(worker);
-
- LOG.info("Started {} dispatcher worker '{}' - will process ANY
appId assigned by Kafka", getDispatcherName(), workerId);
+ startWorker(workerId);
}
LOG.info("<== AuditDispatcherBase.startDispatcherWorkers(): All {}
workers started in SUBSCRIBE mode", dispatcherThreadCount);
}
+ private void startWorker(String workerId) {
+ DispatcherWorker worker = createDispatcherWorker(workerId, new
ArrayList<>());
+ dispatcherWorkers.put(workerId, worker);
+ Future<?> future = dispatcherThreadPool.submit(worker);
+ workerFutures.put(workerId, future);
+ LOG.info("Started {} dispatcher worker '{}' - will process ANY appId
assigned by Kafka", getDispatcherName(), workerId);
+ }
+
+ private void monitorAndRestartWorkers() {
+ if (!running.get()) {
+ return;
+ }
+
+ for (Map.Entry<String, Future<?>> entry : workerFutures.entrySet()) {
+ String workerId = entry.getKey();
+ Future<?> future = entry.getValue();
+
+ if (future.isDone()) {
+ LOG.warn("Worker '{}' has terminated unexpectedly. Attempting
to restart...", workerId);
+ try {
+ // Remove the dead worker
+ dispatcherWorkers.remove(workerId);
+ // Start a new worker with the same ID
+ startWorker(workerId);
+ LOG.info("Successfully restarted worker '{}'", workerId);
Review Comment:
It may be helpful to add the number of restarts happened so far, to help
with diagnostics.
--
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]