{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/43704097","id":43704097,"diff_hunk":"@@ -0,0 +1,939 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package kafka.coordinator\n+\n+import java.util.concurrent.locks.ReentrantReadWriteLock\n+\n+import kafka.utils.CoreUtils._\n+import org.apache.kafka.common.protocol.Errors\n+import org.apache.kafka.common.protocol.types.{ArrayOf, Struct, Schema, Field}\n+import org.apache.kafka.common.protocol.types.Type.STRING\n+import org.apache.kafka.common.protocol.types.Type.INT32\n+import org.apache.kafka.common.protocol.types.Type.INT64\n+import org.apache.kafka.common.protocol.types.Type.BYTES\n+import org.apache.kafka.common.utils.Utils\n+\n+import kafka.utils._\n+import kafka.common._\n+import kafka.message._\n+import kafka.log.FileMessageSet\n+import kafka.metrics.KafkaMetricsGroup\n+import kafka.common.TopicAndPartition\n+import kafka.tools.MessageFormatter\n+import kafka.api.ProducerResponseStatus\n+import kafka.server.ReplicaManager\n+\n+import scala.collection._\n+import java.io.PrintStream\n+import java.nio.ByteBuffer\n+import java.util.concurrent.atomic.AtomicBoolean\n+import java.util.concurrent.{CountDownLatch, TimeUnit}\n+\n+import com.yammer.metrics.core.Gauge\n+\n+class GroupMetadataManager(val brokerId: Int,\n+                           val config: OffsetConfig,\n+                           replicaManager: ReplicaManager,\n+                           zkUtils: ZkUtils,\n+                           scheduler: Scheduler) extends Logging with KafkaMetricsGroup {\n+\n+  /* offsets cache */\n+  private val offsetsCache = new Pool[GroupTopicPartition, OffsetAndMetadata]\n+\n+  /* group metadata cache */\n+  private val groupsCache = new Pool[String, GroupMetadata]\n+\n+  /* partitions of consumer groups that are being loaded, its lock should be always called BEFORE the group lock if needed */\n+  private val loadingPartitions: mutable.Set[Int] = mutable.Set()\n+\n+  /* partitions of consumer groups that are assigned, using the same loading partition lock */\n+  private val ownedPartitions: mutable.Set[Int] = mutable.Set()\n+\n+  /* lock for expiring stale offsets, it should be always called BEFORE the group lock if needed */\n+  private val offsetExpireLock = new ReentrantReadWriteLock()\n+\n+  /* lock for removing offsets of a range partition, it should be always called BEFORE the group lock if needed */\n+  private val offsetRemoveLock = new ReentrantReadWriteLock()","path":"core/src/main/scala/kafka/coordinator/GroupMetadataManager.scala","position":71,"original_position":71,"commit_id":"8ca6ed2370f13f9db20eb23776ab862fe5ec843b","original_commit_id":"8ca6ed2370f13f9db20eb23776ab862fe5ec843b","user":{"login":"junrao","id":132330,"avatar_url":"https://avatars.githubusercontent.com/u/132330?v=3","gravatar_id":"","url":"https://api.github.com/users/junrao","html_url":"https://github.com/junrao","followers_url":"https://api.github.com/users/junrao/followers","following_url":"https://api.github.com/users/junrao/following{/other_user}","gists_url":"https://api.github.com/users/junrao/gists{/gist_id}","starred_url":"https://api.github.com/users/junrao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junrao/subscriptions","organizations_url":"https://api.github.com/users/junrao/orgs","repos_url":"https://api.github.com/users/junrao/repos","events_url":"https://api.github.com/users/junrao/events{/privacy}","received_events_url":"https://api.github.com/users/junrao/received_events","type":"User","site_admin":false},"body":"Do we need this lock? getOffsets() seems to already support the case when the offset is not present.","created_at":"2015-11-03T00:34:30Z","updated_at":"2015-11-03T00:34:30Z","html_url":"https://github.com/apache/kafka/pull/386#discussion_r43704097","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/386","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/43704097"},"html":{"href":"https://github.com/apache/kafka/pull/386#discussion_r43704097"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/386"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/386","id":49213914,"html_url":"https://github.com/apache/kafka/pull/386","diff_url":"https://github.com/apache/kafka/pull/386.diff","patch_url":"https://github.com/apache/kafka/pull/386.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/386","number":386,"state":"open","locked":false,"title":"KAFKA-2017: Persist Group Metadata and Assignment before Responding","user":{"login":"guozhangwang","id":10729597,"avatar_url":"https://avatars.githubusercontent.com/u/10729597?v=3","gravatar_id":"","url":"https://api.github.com/users/guozhangwang","html_url":"https://github.com/guozhangwang","followers_url":"https://api.github.com/users/guozhangwang/followers","following_url":"https://api.github.com/users/guozhangwang/following{/other_user}","gists_url":"https://api.github.com/users/guozhangwang/gists{/gist_id}","starred_url":"https://api.github.com/users/guozhangwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guozhangwang/subscriptions","organizations_url":"https://api.github.com/users/guozhangwang/orgs","repos_url":"https://api.github.com/users/guozhangwang/repos","events_url":"https://api.github.com/users/guozhangwang/events{/privacy}","received_events_url":"https://api.github.com/users/guozhangwang/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-29T23:24:33Z","updated_at":"2015-11-03T00:34:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2405e68899052e560d768fa8d82c2ae5b980a3df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/386/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/386/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/386/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/8ca6ed2370f13f9db20eb23776ab862fe5ec843b","head":{"label":"guozhangwang:K2017","ref":"K2017","sha":"8ca6ed2370f13f9db20eb23776ab862fe5ec843b","user":{"login":"guozhangwang","id":10729597,"avatar_url":"https://avatars.githubusercontent.com/u/10729597?v=3","gravatar_id":"","url":"https://api.github.com/users/guozhangwang","html_url":"https://github.com/guozhangwang","followers_url":"https://api.github.com/users/guozhangwang/followers","following_url":"https://api.github.com/users/guozhangwang/following{/other_user}","gists_url":"https://api.github.com/users/guozhangwang/gists{/gist_id}","starred_url":"https://api.github.com/users/guozhangwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guozhangwang/subscriptions","organizations_url":"https://api.github.com/users/guozhangwang/orgs","repos_url":"https://api.github.com/users/guozhangwang/repos","events_url":"https://api.github.com/users/guozhangwang/events{/privacy}","received_events_url":"https://api.github.com/users/guozhangwang/received_events","type":"User","site_admin":false},"repo":{"id":39164613,"name":"kafka","full_name":"guozhangwang/kafka","owner":{"login":"guozhangwang","id":10729597,"avatar_url":"https://avatars.githubusercontent.com/u/10729597?v=3","gravatar_id":"","url":"https://api.github.com/users/guozhangwang","html_url":"https://github.com/guozhangwang","followers_url":"https://api.github.com/users/guozhangwang/followers","following_url":"https://api.github.com/users/guozhangwang/following{/other_user}","gists_url":"https://api.github.com/users/guozhangwang/gists{/gist_id}","starred_url":"https://api.github.com/users/guozhangwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guozhangwang/subscriptions","organizations_url":"https://api.github.com/users/guozhangwang/orgs","repos_url":"https://api.github.com/users/guozhangwang/repos","events_url":"https://api.github.com/users/guozhangwang/events{/privacy}","received_events_url":"https://api.github.com/users/guozhangwang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/guozhangwang/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/guozhangwang/kafka","forks_url":"https://api.github.com/repos/guozhangwang/kafka/forks","keys_url":"https://api.github.com/repos/guozhangwang/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guozhangwang/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guozhangwang/kafka/teams","hooks_url":"https://api.github.com/repos/guozhangwang/kafka/hooks","issue_events_url":"https://api.github.com/repos/guozhangwang/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/guozhangwang/kafka/events","assignees_url":"https://api.github.com/repos/guozhangwang/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/guozhangwang/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/guozhangwang/kafka/tags","blobs_url":"https://api.github.com/repos/guozhangwang/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guozhangwang/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guozhangwang/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/guozhangwang/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guozhangwang/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/guozhangwang/kafka/languages","stargazers_url":"https://api.github.com/repos/guozhangwang/kafka/stargazers","contributors_url":"https://api.github.com/repos/guozhangwang/kafka/contributors","subscribers_url":"https://api.github.com/repos/guozhangwang/kafka/subscribers","subscription_url":"https://api.github.com/repos/guozhangwang/kafka/subscription","commits_url":"https://api.github.com/repos/guozhangwang/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/guozhangwang/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/guozhangwang/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/guozhangwang/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/guozhangwang/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/guozhangwang/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guozhangwang/kafka/merges","archive_url":"https://api.github.com/repos/guozhangwang/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guozhangwang/kafka/downloads","issues_url":"https://api.github.com/repos/guozhangwang/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/guozhangwang/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/guozhangwang/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/guozhangwang/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guozhangwang/kafka/labels{/name}","releases_url":"https://api.github.com/repos/guozhangwang/kafka/releases{/id}","created_at":"2015-07-15T22:40:38Z","updated_at":"2015-10-14T21:53:20Z","pushed_at":"2015-11-02T19:52:06Z","git_url":"git://github.com/guozhangwang/kafka.git","ssh_url":"git@github.com:guozhangwang/kafka.git","clone_url":"https://github.com/guozhangwang/kafka.git","svn_url":"https://github.com/guozhangwang/kafka","homepage":null,"size":26038,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"e0ca8fdd7cf3fcc51a5a1152eacdf585434052d8","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":2211243,"name":"kafka","full_name":"apache/kafka","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","created_at":"2011-08-15T18:06:16Z","updated_at":"2015-11-02T19:51:10Z","pushed_at":"2015-11-03T00:33:04Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":42172,"stargazers_count":2152,"watchers_count":2152,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1267,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":99,"forks":1267,"open_issues":99,"watchers":2152,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/386"},"html":{"href":"https://github.com/apache/kafka/pull/386"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/386"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/386/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/386/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/386/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/8ca6ed2370f13f9db20eb23776ab862fe5ec843b"}}}}