lihaosky commented on code in PR #14696:
URL: https://github.com/apache/kafka/pull/14696#discussion_r1382016189


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/assignment/Graph.java:
##########
@@ -200,13 +219,40 @@ public Graph<V> residualGraph() {
         return residualGraph;
     }
 
+    private void addDummySourceNode(final Graph<V> residualGraph) {
+        if (!residualGraph.isResidualGraph) {
+            throw new IllegalStateException("Graph should be residual graph to 
add dummy source node");
+        }
+
+        // Add a dummy null node connected to every existing node with 
residual flow 1 and cost 0
+        // Then try to find negative cylce starting using dummy node as source 
node. Since there's no
+        // path from original nodes to null node, negative cycles must be 
within original nodes.
+        final TreeMap<V, Edge> destMap = new TreeMap<>();
+        for (final V node : residualGraph.nodes) {
+            final Edge edge = new Edge(node, 1, 0, 1, 0);
+            destMap.put(node, edge);
+        }
+        residualGraph.adjList.put(null, destMap);
+        residualGraph.nodes.add(null);
+    }
+
+    private void removeDummySourceNode(final Graph<V> residualGraph) {
+        if (!residualGraph.isResidualGraph) {
+            throw new IllegalStateException("Graph should be residual graph to 
add dummy source node");

Review Comment:
   Good catch!



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to