{"action":"closed","issue":{"url":"https://api.github.com/repos/Shopify/sarama/issues/694","repository_url":"https://api.github.com/repos/Shopify/sarama","labels_url":"https://api.github.com/repos/Shopify/sarama/issues/694/labels{/name}","comments_url":"https://api.github.com/repos/Shopify/sarama/issues/694/comments","events_url":"https://api.github.com/repos/Shopify/sarama/issues/694/events","html_url":"https://github.com/Shopify/sarama/issues/694","id":164007965,"number":694,"title":"source code question for \"consumer.go\"","user":{"login":"WanliTian","id":2391020,"avatar_url":"https://avatars.githubusercontent.com/u/2391020?v=3","gravatar_id":"","url":"https://api.github.com/users/WanliTian","html_url":"https://github.com/WanliTian","followers_url":"https://api.github.com/users/WanliTian/followers","following_url":"https://api.github.com/users/WanliTian/following{/other_user}","gists_url":"https://api.github.com/users/WanliTian/gists{/gist_id}","starred_url":"https://api.github.com/users/WanliTian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WanliTian/subscriptions","organizations_url":"https://api.github.com/users/WanliTian/orgs","repos_url":"https://api.github.com/users/WanliTian/repos","events_url":"https://api.github.com/users/WanliTian/events{/privacy}","received_events_url":"https://api.github.com/users/WanliTian/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Shopify/sarama/labels/consumer","name":"consumer","color":"006b75"},{"url":"https://api.github.com/repos/Shopify/sarama/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-06T06:34:44Z","updated_at":"2016-07-06T11:42:33Z","closed_at":"2016-07-06T11:42:33Z","body":"why not remove brokerConsumers' `wait` channel just like this:\r\n\r\n```go\r\n\r\nfunc (bc *brokerConsumer) subscriptionManager() {\r\n\tvar buffer []*partitionConsumer\r\n\r\n\t// The subscriptionManager constantly accepts new subscriptions on `input` (even when the main subscriptionConsumer\r\n\t// goroutine is in the middle of a network request) and batches it up. The main worker goroutine picks\r\n\t// up a batch of new subscriptions between every network request by reading from `newSubscriptions`, so we give\r\n\t// it nil if no new subscriptions are available. We also write to `wait` only when new subscriptions is available,\r\n\t// so the main goroutine can block waiting for work if it has none.\r\n\tfor {\r\n\t\tif len(buffer) > 0 {\r\n\t\t\tselect {\r\n\t\t\tcase event, ok := <-bc.input:\r\n\t\t\t\tif !ok {\r\n\t\t\t\t\tgoto done\r\n\t\t\t\t}\r\n\t\t\t\tbuffer = append(buffer, event)\r\n\t\t\tcase bc.newSubscriptions <- buffer:\r\n\t\t\t\tbuffer = nil\r\n//\t\t\tcase bc.wait <- none{}:\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tselect {\r\n\t\t\tcase event, ok := <-bc.input:\r\n\t\t\t\tif !ok {\r\n\t\t\t\t\tgoto done\r\n\t\t\t\t}\r\n\t\t\t\tbuffer = append(buffer, event)\r\n//\t\t\tcase bc.newSubscriptions <- nil:\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\ndone:\r\n//\tclose(bc.wait)\r\n\tif len(buffer) > 0 {\r\n\t\tbc.newSubscriptions <- buffer\r\n\t}\r\n\tclose(bc.newSubscriptions)\r\n}\r\n\r\nfunc (bc *brokerConsumer) subscriptionConsumer() {\r\n//\t<-bc.wait // wait for our first piece of work\r\n\r\n\t// the subscriptionConsumer ensures we will get nil right away if no new subscriptions is available\r\n\tfor newSubscriptions := range bc.newSubscriptions {\r\n\t\tbc.updateSubscriptions(newSubscriptions)\r\n\r\n\t\tif len(bc.subscriptions) == 0 {\r\n\t\t\t// We're about to be shut down or we're about to receive more subscriptions.\r\n\t\t\t// Either way, the signal just hasn't propagated to our goroutine yet.\r\n//\t\t\t<-bc.wait\r\n\t\t\tcontinue\r\n\t\t}\r\n\r\n\t\tresponse, err := bc.fetchNewMessages()\r\n\r\n\t\tif err != nil {\r\n\t\t\tLogger.Printf(\"consumer/broker/%d disconnecting due to error processing FetchRequest: %s\\n\", bc.broker.ID(), err)\r\n\t\t\tbc.abort(err)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tbc.acks.Add(len(bc.subscriptions))\r\n\t\tfor child := range bc.subscriptions {\r\n\t\t\tchild.feeder <- response\r\n\t\t}\r\n\t\tbc.acks.Wait()\r\n\t\tbc.handleResponses()\r\n\t}\r\n}\r\n\r\n```"}}
{"actor":{"display_login":"eapache"}}