{"action":"created","comment":{"url":"https://api.github.com/repos/Shopify/sarama/pulls/comments/28154932","id":28154932,"diff_hunk":"@@ -304,9 +316,60 @@ func (client *client) GetOffset(topic string, partitionID int32, time int64) (in\n \treturn offset, err\n }\n \n+func (client *client) Coordinator(consumerGroup string) (*Broker, error) {\n+\tclient.lock.RLock()\n+\tcoordinator := client.coordinators[consumerGroup]\n+\tclient.lock.RUnlock()\n+\n+\tif coordinator == nil {\n+\t\tvar err error\n+\t\terr = client.RefreshCoordinator(consumerGroup)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\n+\t\tclient.lock.RLock()\n+\t\tcoordinator = client.coordinators[consumerGroup]\n+\t\tclient.lock.RUnlock()\n+\t}\n+\n+\t_ = coordinator.Open(client.conf)\n+\treturn coordinator, nil\n+}\n+\n+func (client *client) RefreshCoordinator(consumerGroup string) error {\n+\tcoordinator, err := client.getCoordinator(consumerGroup, client.conf.Metadata.Retry.Max)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tclient.lock.Lock()\n+\tclient.coordinators[consumerGroup] = client.registerBroker(coordinator)","path":"client.go","position":82,"original_position":82,"commit_id":"adf0ec5acd1f62e36d0747d043cca504800167b3","original_commit_id":"584629aebb39b379acdc1a45f4e088bcced0c45c","user":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=3","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"body":"I think this has better separation of concerns:\r\n\r\n- `Coordinator` only reads from cache.\r\n- `RefreshCoordinator` only writes to cache.\r\n- `getCoordinator` never touches the cache.\r\n\r\nI'd prefer this approach for metadata as well, except for the fact that it's a more complicated case: Metadata requests can return partially useful responses, while Coordinator responses are either good or bad.","created_at":"2015-04-10T15:37:10Z","updated_at":"2015-04-10T15:37:10Z","html_url":"https://github.com/Shopify/sarama/pull/411#discussion_r28154932","pull_request_url":"https://api.github.com/repos/Shopify/sarama/pulls/411","_links":{"self":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/comments/28154932"},"html":{"href":"https://github.com/Shopify/sarama/pull/411#discussion_r28154932"},"pull_request":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/411"}}},"pull_request":{"url":"https://api.github.com/repos/Shopify/sarama/pulls/411","id":32938904,"html_url":"https://github.com/Shopify/sarama/pull/411","diff_url":"https://github.com/Shopify/sarama/pull/411.diff","patch_url":"https://github.com/Shopify/sarama/pull/411.patch","issue_url":"https://api.github.com/repos/Shopify/sarama/issues/411","number":411,"state":"open","locked":false,"title":"Add Client.Coordinator() to retrieve the coordinating broker for a consumer group","user":{"login":"wvanbergen","id":15870,"avatar_url":"https://avatars.githubusercontent.com/u/15870?v=3","gravatar_id":"","url":"https://api.github.com/users/wvanbergen","html_url":"https://github.com/wvanbergen","followers_url":"https://api.github.com/users/wvanbergen/followers","following_url":"https://api.github.com/users/wvanbergen/following{/other_user}","gists_url":"https://api.github.com/users/wvanbergen/gists{/gist_id}","starred_url":"https://api.github.com/users/wvanbergen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wvanbergen/subscriptions","organizations_url":"https://api.github.com/users/wvanbergen/orgs","repos_url":"https://api.github.com/users/wvanbergen/repos","events_url":"https://api.github.com/users/wvanbergen/events{/privacy}","received_events_url":"https://api.github.com/users/wvanbergen/received_events","type":"User","site_admin":false},"body":"This is the first step towards consumer group offset management, and later full consumer group management in Kafka 0.8.3.\r\n\r\nCareful review of the 2 locks would be appreciated. Do we need to locks or can be just use the single lock for everything?\r\n\r\nExtracted from #379.\r\n\r\n@Shopify/kafka","created_at":"2015-04-09T09:30:56Z","updated_at":"2015-04-10T15:37:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b721d0d791b7c81747dbc553dd1b4debe3729672","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Shopify/sarama/pulls/411/commits","review_comments_url":"https://api.github.com/repos/Shopify/sarama/pulls/411/comments","review_comment_url":"https://api.github.com/repos/Shopify/sarama/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Shopify/sarama/issues/411/comments","statuses_url":"https://api.github.com/repos/Shopify/sarama/statuses/adf0ec5acd1f62e36d0747d043cca504800167b3","head":{"label":"Shopify:coordinator","ref":"coordinator","sha":"adf0ec5acd1f62e36d0747d043cca504800167b3","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":11206255,"name":"sarama","full_name":"Shopify/sarama","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/sarama","description":"Sarama is a Go library for Apache Kafka 0.8 ","fork":false,"url":"https://api.github.com/repos/Shopify/sarama","forks_url":"https://api.github.com/repos/Shopify/sarama/forks","keys_url":"https://api.github.com/repos/Shopify/sarama/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/sarama/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/sarama/teams","hooks_url":"https://api.github.com/repos/Shopify/sarama/hooks","issue_events_url":"https://api.github.com/repos/Shopify/sarama/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/sarama/events","assignees_url":"https://api.github.com/repos/Shopify/sarama/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/sarama/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/sarama/tags","blobs_url":"https://api.github.com/repos/Shopify/sarama/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/sarama/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/sarama/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/sarama/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/sarama/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/sarama/languages","stargazers_url":"https://api.github.com/repos/Shopify/sarama/stargazers","contributors_url":"https://api.github.com/repos/Shopify/sarama/contributors","subscribers_url":"https://api.github.com/repos/Shopify/sarama/subscribers","subscription_url":"https://api.github.com/repos/Shopify/sarama/subscription","commits_url":"https://api.github.com/repos/Shopify/sarama/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/sarama/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/sarama/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/sarama/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/sarama/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/sarama/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/sarama/merges","archive_url":"https://api.github.com/repos/Shopify/sarama/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/sarama/downloads","issues_url":"https://api.github.com/repos/Shopify/sarama/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/sarama/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/sarama/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/sarama/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/sarama/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/sarama/releases{/id}","created_at":"2013-07-05T18:52:38Z","updated_at":"2015-04-10T14:31:04Z","pushed_at":"2015-04-10T15:29:47Z","git_url":"git://github.com/Shopify/sarama.git","ssh_url":"git@github.com:Shopify/sarama.git","clone_url":"https://github.com/Shopify/sarama.git","svn_url":"https://github.com/Shopify/sarama","homepage":"http://shopify.github.io/sarama","size":7932,"stargazers_count":419,"watchers_count":419,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":72,"mirror_url":null,"open_issues_count":27,"forks":72,"open_issues":27,"watchers":419,"default_branch":"master"}},"base":{"label":"Shopify:master","ref":"master","sha":"fcf765a8b80c7b3a5ba1cb3bb9036261502b1ee8","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":11206255,"name":"sarama","full_name":"Shopify/sarama","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/sarama","description":"Sarama is a Go library for Apache Kafka 0.8 ","fork":false,"url":"https://api.github.com/repos/Shopify/sarama","forks_url":"https://api.github.com/repos/Shopify/sarama/forks","keys_url":"https://api.github.com/repos/Shopify/sarama/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/sarama/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/sarama/teams","hooks_url":"https://api.github.com/repos/Shopify/sarama/hooks","issue_events_url":"https://api.github.com/repos/Shopify/sarama/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/sarama/events","assignees_url":"https://api.github.com/repos/Shopify/sarama/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/sarama/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/sarama/tags","blobs_url":"https://api.github.com/repos/Shopify/sarama/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/sarama/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/sarama/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/sarama/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/sarama/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/sarama/languages","stargazers_url":"https://api.github.com/repos/Shopify/sarama/stargazers","contributors_url":"https://api.github.com/repos/Shopify/sarama/contributors","subscribers_url":"https://api.github.com/repos/Shopify/sarama/subscribers","subscription_url":"https://api.github.com/repos/Shopify/sarama/subscription","commits_url":"https://api.github.com/repos/Shopify/sarama/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/sarama/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/sarama/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/sarama/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/sarama/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/sarama/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/sarama/merges","archive_url":"https://api.github.com/repos/Shopify/sarama/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/sarama/downloads","issues_url":"https://api.github.com/repos/Shopify/sarama/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/sarama/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/sarama/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/sarama/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/sarama/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/sarama/releases{/id}","created_at":"2013-07-05T18:52:38Z","updated_at":"2015-04-10T14:31:04Z","pushed_at":"2015-04-10T15:29:47Z","git_url":"git://github.com/Shopify/sarama.git","ssh_url":"git@github.com:Shopify/sarama.git","clone_url":"https://github.com/Shopify/sarama.git","svn_url":"https://github.com/Shopify/sarama","homepage":"http://shopify.github.io/sarama","size":7932,"stargazers_count":419,"watchers_count":419,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":72,"mirror_url":null,"open_issues_count":27,"forks":72,"open_issues":27,"watchers":419,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/411"},"html":{"href":"https://github.com/Shopify/sarama/pull/411"},"issue":{"href":"https://api.github.com/repos/Shopify/sarama/issues/411"},"comments":{"href":"https://api.github.com/repos/Shopify/sarama/issues/411/comments"},"review_comments":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/411/comments"},"review_comment":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Shopify/sarama/pulls/411/commits"},"statuses":{"href":"https://api.github.com/repos/Shopify/sarama/statuses/adf0ec5acd1f62e36d0747d043cca504800167b3"}}}}