{"action":"created","comment":{"url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/comments/81321751","pull_request_review_id":2307616,"id":81321751,"diff_hunk":"@@ -120,27 +135,160 @@ func (t *Topic) parsePartitions(value []byte) (PartitionList, error) {\n \treturn result, nil\n }\n \n+// marshalPartitions turns a PartitionList into the JSON representation\n+// to be stored in Zookeeper.\n+func (t *Topic) marshalPartitions(partitions PartitionList) ([]byte, error) {\n+\ttm := topicMetadata{Version: 1, Partitions: make(map[string][]int32, len(partitions))}\n+\tfor _, part := range partitions {\n+\t\ttm.Partitions[fmt.Sprintf(\"%d\", part.ID)] = part.Replicas\n+\t}\n+\treturn json.Marshal(tm)\n+}\n+\n+// generatePartitionAssignments creates a partition list for a topic. The primary replica for\n+// each partition is assigned in a round-robin fashion starting at a random broker.\n+// Additional replicas are assigned to subsequent brokers to ensure there is no overlap\n+func (t *Topic) generatePartitionAssignments(brokers []int32, partitionCount int, replicationFactor int) (PartitionList, error) {\n+\tif partitionCount <= 0 {\n+\t\treturn nil, ErrInvalidPartitionCount\n+\t}\n+\tif replicationFactor <= 0 || len(brokers) < replicationFactor {\n+\t\treturn nil, ErrInvalidReplicationFactor\n+\t}\n+\n+\tresult := make(PartitionList, partitionCount)\n+\n+\tbrokerCount := len(brokers)\n+\tbrokerIdx := rand.Intn(brokerCount)\n+\n+\tfor p := 0; p < partitionCount; p++ {\n+\t\tpartition := &Partition{topic: t, ID: int32(p), Replicas: make([]int32, replicationFactor)}\n+\n+\t\t// assign primary to the current broker and all\n+\t\t// other replicas to subsequent brokers\n+\t\tfor r := 0; r < replicationFactor; r++ {\n+\t\t\tpartition.Replicas[r] = brokers[(brokerIdx+r)%brokerCount]\n+\t\t}\n+\n+\t\tresult[p] = partition\n+\t\tbrokerIdx = (brokerIdx + 1) % brokerCount\n+\t}","path":"topic_metadata.go","position":116,"original_position":116,"commit_id":"87ea48e810d321ba5be9ea0594d0c60958a70ba2","original_commit_id":"87ea48e810d321ba5be9ea0594d0c60958a70ba2","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":"Maybe this is a simpler, and more random way to get a useful list of broker IDs:\r\n\r\n``` go\r\nbrokerIndices = rand.Perm(len(brokers))[0:replicationFactor]\r\nfor r := 0; r < replicationFactor; r++ {\r\n  partition.Replicas[r] = brokers[brokerIndices[r]]\r\n}\r\n```\r\n\r\nMakes for simpler logic, and should give a even spread on a large amount of partitions. Feel free to disagree with this.","created_at":"2016-09-30T11:27:30Z","updated_at":"2016-09-30T11:30:50Z","html_url":"https://github.com/wvanbergen/kazoo-go/pull/25#discussion_r81321751","pull_request_url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/comments/81321751"},"html":{"href":"https://github.com/wvanbergen/kazoo-go/pull/25#discussion_r81321751"},"pull_request":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25","id":87456681,"html_url":"https://github.com/wvanbergen/kazoo-go/pull/25","diff_url":"https://github.com/wvanbergen/kazoo-go/pull/25.diff","patch_url":"https://github.com/wvanbergen/kazoo-go/pull/25.patch","issue_url":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/25","number":25,"state":"open","locked":false,"title":"Create and delete topics","user":{"login":"F21","id":2263040,"avatar_url":"https://avatars.githubusercontent.com/u/2263040?v=3","gravatar_id":"","url":"https://api.github.com/users/F21","html_url":"https://github.com/F21","followers_url":"https://api.github.com/users/F21/followers","following_url":"https://api.github.com/users/F21/following{/other_user}","gists_url":"https://api.github.com/users/F21/gists{/gist_id}","starred_url":"https://api.github.com/users/F21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/F21/subscriptions","organizations_url":"https://api.github.com/users/F21/orgs","repos_url":"https://api.github.com/users/F21/repos","events_url":"https://api.github.com/users/F21/events{/privacy}","received_events_url":"https://api.github.com/users/F21/received_events","type":"User","site_admin":false},"body":"Trying to carry #20.","created_at":"2016-09-30T08:53:56Z","updated_at":"2016-09-30T11:34:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dba4a1d40f2f8e4940469bc1606562938a42bf33","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25/commits","review_comments_url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25/comments","review_comment_url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/25/comments","statuses_url":"https://api.github.com/repos/wvanbergen/kazoo-go/statuses/87ea48e810d321ba5be9ea0594d0c60958a70ba2","head":{"label":"F21:create-delete-topics","ref":"create-delete-topics","sha":"87ea48e810d321ba5be9ea0594d0c60958a70ba2","user":{"login":"F21","id":2263040,"avatar_url":"https://avatars.githubusercontent.com/u/2263040?v=3","gravatar_id":"","url":"https://api.github.com/users/F21","html_url":"https://github.com/F21","followers_url":"https://api.github.com/users/F21/followers","following_url":"https://api.github.com/users/F21/following{/other_user}","gists_url":"https://api.github.com/users/F21/gists{/gist_id}","starred_url":"https://api.github.com/users/F21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/F21/subscriptions","organizations_url":"https://api.github.com/users/F21/orgs","repos_url":"https://api.github.com/users/F21/repos","events_url":"https://api.github.com/users/F21/events{/privacy}","received_events_url":"https://api.github.com/users/F21/received_events","type":"User","site_admin":false},"repo":{"id":69650262,"name":"kazoo-go","full_name":"F21/kazoo-go","owner":{"login":"F21","id":2263040,"avatar_url":"https://avatars.githubusercontent.com/u/2263040?v=3","gravatar_id":"","url":"https://api.github.com/users/F21","html_url":"https://github.com/F21","followers_url":"https://api.github.com/users/F21/followers","following_url":"https://api.github.com/users/F21/following{/other_user}","gists_url":"https://api.github.com/users/F21/gists{/gist_id}","starred_url":"https://api.github.com/users/F21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/F21/subscriptions","organizations_url":"https://api.github.com/users/F21/orgs","repos_url":"https://api.github.com/users/F21/repos","events_url":"https://api.github.com/users/F21/events{/privacy}","received_events_url":"https://api.github.com/users/F21/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/F21/kazoo-go","description":"Go library to access Kafka metadata in Zookeeper","fork":true,"url":"https://api.github.com/repos/F21/kazoo-go","forks_url":"https://api.github.com/repos/F21/kazoo-go/forks","keys_url":"https://api.github.com/repos/F21/kazoo-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/F21/kazoo-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/F21/kazoo-go/teams","hooks_url":"https://api.github.com/repos/F21/kazoo-go/hooks","issue_events_url":"https://api.github.com/repos/F21/kazoo-go/issues/events{/number}","events_url":"https://api.github.com/repos/F21/kazoo-go/events","assignees_url":"https://api.github.com/repos/F21/kazoo-go/assignees{/user}","branches_url":"https://api.github.com/repos/F21/kazoo-go/branches{/branch}","tags_url":"https://api.github.com/repos/F21/kazoo-go/tags","blobs_url":"https://api.github.com/repos/F21/kazoo-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/F21/kazoo-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/F21/kazoo-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/F21/kazoo-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/F21/kazoo-go/statuses/{sha}","languages_url":"https://api.github.com/repos/F21/kazoo-go/languages","stargazers_url":"https://api.github.com/repos/F21/kazoo-go/stargazers","contributors_url":"https://api.github.com/repos/F21/kazoo-go/contributors","subscribers_url":"https://api.github.com/repos/F21/kazoo-go/subscribers","subscription_url":"https://api.github.com/repos/F21/kazoo-go/subscription","commits_url":"https://api.github.com/repos/F21/kazoo-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/F21/kazoo-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/F21/kazoo-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/F21/kazoo-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/F21/kazoo-go/contents/{+path}","compare_url":"https://api.github.com/repos/F21/kazoo-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/F21/kazoo-go/merges","archive_url":"https://api.github.com/repos/F21/kazoo-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/F21/kazoo-go/downloads","issues_url":"https://api.github.com/repos/F21/kazoo-go/issues{/number}","pulls_url":"https://api.github.com/repos/F21/kazoo-go/pulls{/number}","milestones_url":"https://api.github.com/repos/F21/kazoo-go/milestones{/number}","notifications_url":"https://api.github.com/repos/F21/kazoo-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/F21/kazoo-go/labels{/name}","releases_url":"https://api.github.com/repos/F21/kazoo-go/releases{/id}","deployments_url":"https://api.github.com/repos/F21/kazoo-go/deployments","created_at":"2016-09-30T08:48:21Z","updated_at":"2016-09-30T08:48:22Z","pushed_at":"2016-09-30T11:26:51Z","git_url":"git://github.com/F21/kazoo-go.git","ssh_url":"git@github.com:F21/kazoo-go.git","clone_url":"https://github.com/F21/kazoo-go.git","svn_url":"https://github.com/F21/kazoo-go","homepage":"http://godoc.org/github.com/wvanbergen/kazoo-go","size":57,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wvanbergen:master","ref":"master","sha":"968957352185472eacb69215fa3dbfcfdbac1096","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},"repo":{"id":34906971,"name":"kazoo-go","full_name":"wvanbergen/kazoo-go","owner":{"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},"private":false,"html_url":"https://github.com/wvanbergen/kazoo-go","description":"Go library to access Kafka metadata in Zookeeper","fork":false,"url":"https://api.github.com/repos/wvanbergen/kazoo-go","forks_url":"https://api.github.com/repos/wvanbergen/kazoo-go/forks","keys_url":"https://api.github.com/repos/wvanbergen/kazoo-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wvanbergen/kazoo-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wvanbergen/kazoo-go/teams","hooks_url":"https://api.github.com/repos/wvanbergen/kazoo-go/hooks","issue_events_url":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/events{/number}","events_url":"https://api.github.com/repos/wvanbergen/kazoo-go/events","assignees_url":"https://api.github.com/repos/wvanbergen/kazoo-go/assignees{/user}","branches_url":"https://api.github.com/repos/wvanbergen/kazoo-go/branches{/branch}","tags_url":"https://api.github.com/repos/wvanbergen/kazoo-go/tags","blobs_url":"https://api.github.com/repos/wvanbergen/kazoo-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wvanbergen/kazoo-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wvanbergen/kazoo-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/wvanbergen/kazoo-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wvanbergen/kazoo-go/statuses/{sha}","languages_url":"https://api.github.com/repos/wvanbergen/kazoo-go/languages","stargazers_url":"https://api.github.com/repos/wvanbergen/kazoo-go/stargazers","contributors_url":"https://api.github.com/repos/wvanbergen/kazoo-go/contributors","subscribers_url":"https://api.github.com/repos/wvanbergen/kazoo-go/subscribers","subscription_url":"https://api.github.com/repos/wvanbergen/kazoo-go/subscription","commits_url":"https://api.github.com/repos/wvanbergen/kazoo-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/wvanbergen/kazoo-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/wvanbergen/kazoo-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/wvanbergen/kazoo-go/contents/{+path}","compare_url":"https://api.github.com/repos/wvanbergen/kazoo-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wvanbergen/kazoo-go/merges","archive_url":"https://api.github.com/repos/wvanbergen/kazoo-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wvanbergen/kazoo-go/downloads","issues_url":"https://api.github.com/repos/wvanbergen/kazoo-go/issues{/number}","pulls_url":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls{/number}","milestones_url":"https://api.github.com/repos/wvanbergen/kazoo-go/milestones{/number}","notifications_url":"https://api.github.com/repos/wvanbergen/kazoo-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wvanbergen/kazoo-go/labels{/name}","releases_url":"https://api.github.com/repos/wvanbergen/kazoo-go/releases{/id}","deployments_url":"https://api.github.com/repos/wvanbergen/kazoo-go/deployments","created_at":"2015-05-01T14:37:30Z","updated_at":"2016-09-25T04:09:29Z","pushed_at":"2016-09-30T11:27:02Z","git_url":"git://github.com/wvanbergen/kazoo-go.git","ssh_url":"git@github.com:wvanbergen/kazoo-go.git","clone_url":"https://github.com/wvanbergen/kazoo-go.git","svn_url":"https://github.com/wvanbergen/kazoo-go","homepage":"http://godoc.org/github.com/wvanbergen/kazoo-go","size":102,"stargazers_count":35,"watchers_count":35,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":25,"mirror_url":null,"open_issues_count":11,"forks":25,"open_issues":11,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25"},"html":{"href":"https://github.com/wvanbergen/kazoo-go/pull/25"},"issue":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/25"},"comments":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/wvanbergen/kazoo-go/statuses/87ea48e810d321ba5be9ea0594d0c60958a70ba2"}}}}
{"actor":{"display_login":"wvanbergen"}}