chia7712 commented on a change in pull request #8657:
URL: https://github.com/apache/kafka/pull/8657#discussion_r427435780



##########
File path: core/src/main/scala/kafka/coordinator/group/GroupCoordinator.scala
##########
@@ -369,6 +369,31 @@ class GroupCoordinator(val brokerId: Int,
     }
   }
 
+  /**
+   * try to complete produce, fetch and delete requests if the HW of partition 
is incremented. Otherwise, we try to complete
+   * only delayed fetch requests.
+   *
+   * Noted that this method may hold a lot of group lock so the caller should 
NOT hold any group lock
+   * in order to avoid deadlock
+   * @param topicPartitions topic partition and leaderHWIncremented
+   */
+  private[this] def completeDelayedRequests(topicPartitions: 
Map[TopicPartition, Boolean]): Unit =
+    topicPartitions.foreach {
+      case (tp, leaderHWIncremented) =>
+        if (leaderHWIncremented) 
groupManager.replicaManager.completeDelayedRequests(tp)
+        else groupManager.replicaManager.completeDelayedFetchRequests(tp)
+    }
+
+  /**
+   * complete the delayed join requests associated to input group keys.
+   *
+   * Noted that this method may hold a lot of group lock so the caller should 
NOT hold any group lock
+   * in order to avoid deadlock
+   * @param groupKeys group keys to complete
+   */
+  private[this] def completeDelayedJoinRequests(groupKeys: Set[GroupKey]): 
Unit =
+    groupKeys.foreach(joinPurgatory.checkAndComplete)

Review comment:
       > so when we complete an operation for group "foo," we won't complete 
for group "bar" incidentally. At least that is my understanding. If you look at 
DelayedOperationPurgatory.checkAndComplete, we only complete watchers for the 
passed key.
   
   You are totally right. My above comment is not clear. I added the comment to 
remind developers following code is dangerous.
   ```scala
   lock group_a
   completeDelayedJoinRequests for group_b (this line may produce deadlock if 
there is another thread which is holding lock of group_b and prepare to 
complete requests for group_a)
   release group_a
   ```
   Of course, the above code is nonexistent currently. I'm just worry that the 
deadlock is easy to produce in the future if we don't notice the lock issue.
   




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


Reply via email to