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


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/assignment/Graph.java:
##########
@@ -103,8 +104,24 @@ public String toString() {
         }
     }
 
-    private final SortedMap<V, SortedMap<V, Edge>> adjList = new TreeMap<>();
-    private final SortedSet<V> nodes = new TreeSet<>();
+    private class KeyComparator implements Comparator<V> {
+
+        @Override
+        public int compare(final V o1, final V o2) {
+            if (o1 == null) {

Review Comment:
   Do we plan to have different results returned under two different null 
cases? If not, maybe we can do 
   ```
   if (o1 == null || o2 == null) {
       return -1;
   }
   ```
   to simplify the condition.



##########
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:
   Maybe 'Graph should be residual graph to **remove** dummy source node' ?



-- 
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