rhauch commented on a change in pull request #10822:
URL: https://github.com/apache/kafka/pull/10822#discussion_r655683692
##########
File path:
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java
##########
@@ -1592,6 +1731,28 @@ public void onSessionKeyUpdate(SessionKey sessionKey) {
}
}
}
+
+ @Override
+ public void onRestartRequest(RestartRequest request) {
+ log.info("Received and enqueuing {}", request);
+
+ synchronized (DistributedHerder.this) {
+ String connectorName = request.connectorName();
+ //preserve the highest impact request
+ if (pendingRestartRequests.containsKey(connectorName)) {
+ RestartRequest existingRequest =
pendingRestartRequests.get(connectorName);
+ if (request.compareTo(existingRequest) > 0) {
+ log.debug("Overwriting existing {} and enqueuing the
higher impact {}", existingRequest, request);
+ pendingRestartRequests.put(connectorName, request);
+ } else {
+ log.debug("Preserving existing higher impact {} and
ignoring incoming {}", existingRequest, request);
+ }
+ } else {
+ pendingRestartRequests.put(connectorName, request);
+ }
Review comment:
If we were to change `pendingRestartRequests` to a `ConcurrentMap`, then
we could use the `compute(...)` functionality that actually would work even if
we removed the synchronization. I wonder if this is a bit more readable (even
though strictly speaking we don't need concurrent access). WDYT?
```
pendingRestartRequests.compute(connectorName, (k, existing)
-> {
if (existing == null || request.compareTo(existing) > 0)
{
log.debug("Overwriting existing {} and enqueuing the
higher impact {}", existing, request);
return request;
}
log.debug("Preserving existing higher impact {} and
ignoring incoming {}", existing, request);
return existing;
});
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]