Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions core/src/main/scala/kafka/coordinator/group/GroupMetadata.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private[group] class GroupMetadata(val groupId: String, initialState: GroupState
leaderId = Some(member.memberId)

members.put(member.memberId, member)
member.supportedProtocols.foreach { case (protocol, _) => supportedProtocols(protocol) += 1 }
incSupportedProtocols(member)
member.awaitingJoinCallback = callback

if (member.isAwaitingJoin)
Expand All @@ -263,7 +263,7 @@ private[group] class GroupMetadata(val groupId: String, initialState: GroupState

def remove(memberId: String): Unit = {
members.remove(memberId).foreach { member =>
member.supportedProtocols.foreach { case (protocol, _) => supportedProtocols(protocol) -= 1 }
decSupportedProtocols(member)
if (member.isAwaitingJoin)
numMembersAwaitingJoin -= 1

Expand Down Expand Up @@ -426,6 +426,14 @@ private[group] class GroupMetadata(val groupId: String, initialState: GroupState
protocol
}

private def incSupportedProtocols(member: MemberMetadata): Unit = {
member.supportedProtocols.foreach { case (protocol, _) => supportedProtocols(protocol) += 1 }
}

private def decSupportedProtocols(member: MemberMetadata): Unit = {
member.supportedProtocols.foreach { case (protocol, _) => supportedProtocols(protocol) -= 1 }
}

private def candidateProtocols: Set[String] = {
// get the set of protocols that are commonly supported by all members
val numMembers = members.size
Expand All @@ -434,7 +442,7 @@ private[group] class GroupMetadata(val groupId: String, initialState: GroupState

def supportsProtocols(memberProtocolType: String, memberProtocols: Set[String]): Boolean = {
if (is(Empty))
!memberProtocolType.isEmpty && memberProtocols.nonEmpty
memberProtocolType.nonEmpty && memberProtocols.nonEmpty
else
protocolType.contains(memberProtocolType) && memberProtocols.exists(supportedProtocols(_) == members.size)
}
Expand Down Expand Up @@ -489,9 +497,9 @@ private[group] class GroupMetadata(val groupId: String, initialState: GroupState
def updateMember(member: MemberMetadata,
protocols: List[(String, Array[Byte])],
callback: JoinCallback): Unit = {
member.supportedProtocols.foreach { case (protocol, _) => supportedProtocols(protocol) -= 1 }
protocols.foreach { case (protocol, _) => supportedProtocols(protocol) += 1 }
decSupportedProtocols(member)
member.supportedProtocols = protocols
incSupportedProtocols(member)

if (callback != null && !member.isAwaitingJoin) {
numMembersAwaitingJoin += 1
Expand Down