ableegoldman commented on a change in pull request #11857:
URL: https://github.com/apache/kafka/pull/11857#discussion_r820600321
##########
File path:
streams/src/main/java/org/apache/kafka/streams/processor/internals/TopologyMetadata.java
##########
@@ -161,35 +161,47 @@ public void registerThread(final String threadName) {
public void unregisterThread(final String threadName) {
threadVersions.remove(threadName);
-
maybeNotifyTopologyVersionWaitersAndUpdateThreadsTopologyVersion(threadName);
+ maybeNotifyTopologyVersionListeners();
}
public TaskExecutionMetadata taskExecutionMetadata() {
return taskExecutionMetadata;
}
- public void
maybeNotifyTopologyVersionWaitersAndUpdateThreadsTopologyVersion(final String
threadName) {
+ public Set<String> updateThreadTopologyVersion(final String threadName) {
try {
- lock();
- final Iterator<TopologyVersionWaiters> iterator =
version.activeTopologyWaiters.listIterator();
- TopologyVersionWaiters topologyVersionWaiters;
+ version.topologyLock.lock();
threadVersions.put(threadName, topologyVersion());
+ return namedTopologiesView();
+ } finally {
+ version.topologyLock.unlock();
+ }
+ }
+
+ public void maybeNotifyTopologyVersionListeners() {
+ try {
+ lock();
+ final long minThreadVersion = getMinimumThreadVersion();
+ final Iterator<TopologyVersionListener> iterator =
version.activeTopologyUpdateListeners.listIterator();
+ TopologyVersionListener topologyVersionListener;
while (iterator.hasNext()) {
- topologyVersionWaiters = iterator.next();
- final long topologyVersionWaitersVersion =
topologyVersionWaiters.topologyVersion;
- if (topologyVersionWaitersVersion <=
threadVersions.get(threadName)) {
- if (threadVersions.values().stream().allMatch(t -> t >=
topologyVersionWaitersVersion)) {
- topologyVersionWaiters.future.complete(null);
- iterator.remove();
- log.info("All threads are now on topology version {}",
topologyVersionWaiters.topologyVersion);
- }
+ topologyVersionListener = iterator.next();
+ final long topologyVersionWaitersVersion =
topologyVersionListener.topologyVersion;
+ if (minThreadVersion >= topologyVersionWaitersVersion) {
Review comment:
I also refactored this slightly to optimize/clean up this method. It's
less about the optimization as we should generally not have too many threads
per KafkaStreams runtime, but I found it much easier to follow the logic by
computing the minimum version across all threads and then completing all
futures listening for the topology to be updated up to that version
--
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]