{"action":"created","comment":{"url":"https://api.github.com/repos/citusdata/pg_shard/pulls/comments/39858264","id":39858264,"diff_hunk":"@@ -227,27 +238,71 @@ WARNING:  could not create shard on \"adeadhost:5432\"\n \\set VERBOSITY default\n SELECT storage, min_value, max_value FROM pgs_distribution_metadata.shard\n \tWHERE relation_id = 'foreign_table_to_distribute'::regclass\n-\tORDER BY (min_value COLLATE \"C\") ASC;\n+\tORDER BY (min_value::integer) ASC;\n  storage |  min_value  |  max_value  \n ---------+-------------+-------------\n- f       | -1073741828 | -805306374\n- f       | -1342177283 | -1073741829\n- f       | -1610612738 | -1342177284\n- f       | -1879048193 | -1610612739\n- f       | -2147483648 | -1879048194\n- f       | -268435463  | -9\n- f       | -536870918  | -268435464\n- f       | -8          | 268435446\n- f       | -805306373  | -536870919\n- f       | 1073741812  | 1342177266\n- f       | 1342177267  | 1610612721\n- f       | 1610612722  | 1879048176\n- f       | 1879048177  | 2147483647\n- f       | 268435447   | 536870901\n- f       | 536870902   | 805306356\n- f       | 805306357   | 1073741811\n+ f       | -2147483648 | -1879048193\n+ f       | -1879048192 | -1610612737\n+ f       | -1610612736 | -1342177281\n+ f       | -1342177280 | -1073741825\n+ f       | -1073741824 | -805306369\n+ f       | -805306368  | -536870913\n+ f       | -536870912  | -268435457\n+ f       | -268435456  | -1\n+ f       | 0           | 268435455\n+ f       | 268435456   | 536870911\n+ f       | 536870912   | 805306367\n+ f       | 805306368   | 1073741823\n+ f       | 1073741824  | 1342177279\n+ f       | 1342177280  | 1610612735\n+ f       | 1610612736  | 1879048191\n+ f       | 1879048192  | 2147483647\n (16 rows)\n \n+-- test shard creation using weird shard count\n+CREATE TABLE weird_shard_count\n+(\n+\tname text,\n+\tid bigint\n+);\n+\\set VERBOSITY terse\n+SELECT master_create_distributed_table('weird_shard_count', 'id');\n+ master_create_distributed_table \n+---------------------------------\n+ \n+(1 row)\n+\n+SELECT master_create_worker_shards('weird_shard_count', 7, 1);\n+WARNING:  Connection failed to adeadhost:5432\n+WARNING:  could not create shard on \"adeadhost:5432\"\n+WARNING:  Connection failed to adeadhost:5432\n+WARNING:  could not create shard on \"adeadhost:5432\"\n+WARNING:  Connection failed to adeadhost:5432\n+WARNING:  could not create shard on \"adeadhost:5432\"\n+WARNING:  Connection failed to adeadhost:5432\n+WARNING:  could not create shard on \"adeadhost:5432\"\n+ master_create_worker_shards \n+-----------------------------\n+ \n+(1 row)\n+\n+\\set VERBOSITY default\n+-- pg_shard ensures all shards are roughly the same size\n+SELECT max_value::integer-min_value::integer AS shard_size","path":"test/expected/05-create_shards.out","position":127,"original_position":127,"commit_id":"49bb672b95f6f16d48fbe97ea90b2eebf7b213fc","original_commit_id":"49bb672b95f6f16d48fbe97ea90b2eebf7b213fc","user":{"login":"onderkalaci","id":7829470,"avatar_url":"https://avatars.githubusercontent.com/u/7829470?v=3","gravatar_id":"","url":"https://api.github.com/users/onderkalaci","html_url":"https://github.com/onderkalaci","followers_url":"https://api.github.com/users/onderkalaci/followers","following_url":"https://api.github.com/users/onderkalaci/following{/other_user}","gists_url":"https://api.github.com/users/onderkalaci/gists{/gist_id}","starred_url":"https://api.github.com/users/onderkalaci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onderkalaci/subscriptions","organizations_url":"https://api.github.com/users/onderkalaci/orgs","repos_url":"https://api.github.com/users/onderkalaci/repos","events_url":"https://api.github.com/users/onderkalaci/events{/privacy}","received_events_url":"https://api.github.com/users/onderkalaci/received_events","type":"User","site_admin":false},"body":"should we add white space: `max_value::integer-min_value::integer AS shard_size` =>\r\n  `max_value::integer - min_value::integer AS shard_size`","created_at":"2015-09-18T14:10:39Z","updated_at":"2015-09-18T14:10:39Z","html_url":"https://github.com/citusdata/pg_shard/pull/145#discussion_r39858264","pull_request_url":"https://api.github.com/repos/citusdata/pg_shard/pulls/145","_links":{"self":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/comments/39858264"},"html":{"href":"https://github.com/citusdata/pg_shard/pull/145#discussion_r39858264"},"pull_request":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/145"}}},"pull_request":{"url":"https://api.github.com/repos/citusdata/pg_shard/pulls/145","id":45370235,"html_url":"https://github.com/citusdata/pg_shard/pull/145","diff_url":"https://github.com/citusdata/pg_shard/pull/145.diff","patch_url":"https://github.com/citusdata/pg_shard/pull/145.patch","issue_url":"https://api.github.com/repos/citusdata/pg_shard/issues/145","number":145,"state":"open","locked":false,"title":"Fix and improve hash token distribution algorithm","user":{"login":"jasonmp85","id":50673,"avatar_url":"https://avatars.githubusercontent.com/u/50673?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonmp85","html_url":"https://github.com/jasonmp85","followers_url":"https://api.github.com/users/jasonmp85/followers","following_url":"https://api.github.com/users/jasonmp85/following{/other_user}","gists_url":"https://api.github.com/users/jasonmp85/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonmp85/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonmp85/subscriptions","organizations_url":"https://api.github.com/users/jasonmp85/orgs","repos_url":"https://api.github.com/users/jasonmp85/repos","events_url":"https://api.github.com/users/jasonmp85/events{/privacy}","received_events_url":"https://api.github.com/users/jasonmp85/received_events","type":"User","site_admin":false},"body":"There are `2^32` distinct \"hash tokens\" in our hash space, but we were using `INT32_MAX` (`2^32 - 1`) in the code instead. Because of this, shard counts which one might expect to divide evenly into the space (such as 16, 32, or 256) had fewer tokens than they should have. The remainder of the tokens were stuffed into the last shard, causing uneven load.\n\nThough fixing the `INT32_MAX` bug solves the above case, it still doesn't deal with the remainder, which can be as large as `shardCount - 1`. We could continue stuffing it into the top shard, but I find it nicer to have all shard sizes be within one token of one another.\n\nWe previously divided the shard count into the hash token count to get a \"hash token increment\" and added that increment each iteration: this gives something like `shardIndex * (hashCount / shardCount)`. By changing the grouping to `(shardIndex * hashCount) / shardCount`, the issue with distributing the remainder goes away entirely and we get \"nice\" shards.","created_at":"2015-09-18T05:22:37Z","updated_at":"2015-09-18T14:10:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"46e63994fb208f7d7d40116d7af9f7c0d69cd24e","assignee":{"login":"onderkalaci","id":7829470,"avatar_url":"https://avatars.githubusercontent.com/u/7829470?v=3","gravatar_id":"","url":"https://api.github.com/users/onderkalaci","html_url":"https://github.com/onderkalaci","followers_url":"https://api.github.com/users/onderkalaci/followers","following_url":"https://api.github.com/users/onderkalaci/following{/other_user}","gists_url":"https://api.github.com/users/onderkalaci/gists{/gist_id}","starred_url":"https://api.github.com/users/onderkalaci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onderkalaci/subscriptions","organizations_url":"https://api.github.com/users/onderkalaci/orgs","repos_url":"https://api.github.com/users/onderkalaci/repos","events_url":"https://api.github.com/users/onderkalaci/events{/privacy}","received_events_url":"https://api.github.com/users/onderkalaci/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/citusdata/pg_shard/pulls/145/commits","review_comments_url":"https://api.github.com/repos/citusdata/pg_shard/pulls/145/comments","review_comment_url":"https://api.github.com/repos/citusdata/pg_shard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/citusdata/pg_shard/issues/145/comments","statuses_url":"https://api.github.com/repos/citusdata/pg_shard/statuses/49bb672b95f6f16d48fbe97ea90b2eebf7b213fc","head":{"label":"citusdata:better_hash_token_distribution","ref":"better_hash_token_distribution","sha":"49bb672b95f6f16d48fbe97ea90b2eebf7b213fc","user":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"repo":{"id":27522888,"name":"pg_shard","full_name":"citusdata/pg_shard","owner":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citusdata/pg_shard","description":"PostgreSQL extension to scale out real-time reads and writes. Check out the mailing list at https://groups.google.com/group/pg_shard-users","fork":false,"url":"https://api.github.com/repos/citusdata/pg_shard","forks_url":"https://api.github.com/repos/citusdata/pg_shard/forks","keys_url":"https://api.github.com/repos/citusdata/pg_shard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citusdata/pg_shard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citusdata/pg_shard/teams","hooks_url":"https://api.github.com/repos/citusdata/pg_shard/hooks","issue_events_url":"https://api.github.com/repos/citusdata/pg_shard/issues/events{/number}","events_url":"https://api.github.com/repos/citusdata/pg_shard/events","assignees_url":"https://api.github.com/repos/citusdata/pg_shard/assignees{/user}","branches_url":"https://api.github.com/repos/citusdata/pg_shard/branches{/branch}","tags_url":"https://api.github.com/repos/citusdata/pg_shard/tags","blobs_url":"https://api.github.com/repos/citusdata/pg_shard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citusdata/pg_shard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citusdata/pg_shard/git/refs{/sha}","trees_url":"https://api.github.com/repos/citusdata/pg_shard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citusdata/pg_shard/statuses/{sha}","languages_url":"https://api.github.com/repos/citusdata/pg_shard/languages","stargazers_url":"https://api.github.com/repos/citusdata/pg_shard/stargazers","contributors_url":"https://api.github.com/repos/citusdata/pg_shard/contributors","subscribers_url":"https://api.github.com/repos/citusdata/pg_shard/subscribers","subscription_url":"https://api.github.com/repos/citusdata/pg_shard/subscription","commits_url":"https://api.github.com/repos/citusdata/pg_shard/commits{/sha}","git_commits_url":"https://api.github.com/repos/citusdata/pg_shard/git/commits{/sha}","comments_url":"https://api.github.com/repos/citusdata/pg_shard/comments{/number}","issue_comment_url":"https://api.github.com/repos/citusdata/pg_shard/issues/comments{/number}","contents_url":"https://api.github.com/repos/citusdata/pg_shard/contents/{+path}","compare_url":"https://api.github.com/repos/citusdata/pg_shard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citusdata/pg_shard/merges","archive_url":"https://api.github.com/repos/citusdata/pg_shard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citusdata/pg_shard/downloads","issues_url":"https://api.github.com/repos/citusdata/pg_shard/issues{/number}","pulls_url":"https://api.github.com/repos/citusdata/pg_shard/pulls{/number}","milestones_url":"https://api.github.com/repos/citusdata/pg_shard/milestones{/number}","notifications_url":"https://api.github.com/repos/citusdata/pg_shard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citusdata/pg_shard/labels{/name}","releases_url":"https://api.github.com/repos/citusdata/pg_shard/releases{/id}","created_at":"2014-12-04T04:24:37Z","updated_at":"2015-09-18T08:37:58Z","pushed_at":"2015-09-18T13:17:59Z","git_url":"git://github.com/citusdata/pg_shard.git","ssh_url":"git@github.com:citusdata/pg_shard.git","clone_url":"https://github.com/citusdata/pg_shard.git","svn_url":"https://github.com/citusdata/pg_shard","homepage":"","size":3204,"stargazers_count":883,"watchers_count":883,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":44,"forks":44,"open_issues":44,"watchers":883,"default_branch":"develop"}},"base":{"label":"citusdata:develop","ref":"develop","sha":"f894c07711684983c805a6187a6015c648dae9af","user":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"repo":{"id":27522888,"name":"pg_shard","full_name":"citusdata/pg_shard","owner":{"login":"citusdata","id":2545424,"avatar_url":"https://avatars.githubusercontent.com/u/2545424?v=3","gravatar_id":"","url":"https://api.github.com/users/citusdata","html_url":"https://github.com/citusdata","followers_url":"https://api.github.com/users/citusdata/followers","following_url":"https://api.github.com/users/citusdata/following{/other_user}","gists_url":"https://api.github.com/users/citusdata/gists{/gist_id}","starred_url":"https://api.github.com/users/citusdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/citusdata/subscriptions","organizations_url":"https://api.github.com/users/citusdata/orgs","repos_url":"https://api.github.com/users/citusdata/repos","events_url":"https://api.github.com/users/citusdata/events{/privacy}","received_events_url":"https://api.github.com/users/citusdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/citusdata/pg_shard","description":"PostgreSQL extension to scale out real-time reads and writes. Check out the mailing list at https://groups.google.com/group/pg_shard-users","fork":false,"url":"https://api.github.com/repos/citusdata/pg_shard","forks_url":"https://api.github.com/repos/citusdata/pg_shard/forks","keys_url":"https://api.github.com/repos/citusdata/pg_shard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/citusdata/pg_shard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/citusdata/pg_shard/teams","hooks_url":"https://api.github.com/repos/citusdata/pg_shard/hooks","issue_events_url":"https://api.github.com/repos/citusdata/pg_shard/issues/events{/number}","events_url":"https://api.github.com/repos/citusdata/pg_shard/events","assignees_url":"https://api.github.com/repos/citusdata/pg_shard/assignees{/user}","branches_url":"https://api.github.com/repos/citusdata/pg_shard/branches{/branch}","tags_url":"https://api.github.com/repos/citusdata/pg_shard/tags","blobs_url":"https://api.github.com/repos/citusdata/pg_shard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/citusdata/pg_shard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/citusdata/pg_shard/git/refs{/sha}","trees_url":"https://api.github.com/repos/citusdata/pg_shard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/citusdata/pg_shard/statuses/{sha}","languages_url":"https://api.github.com/repos/citusdata/pg_shard/languages","stargazers_url":"https://api.github.com/repos/citusdata/pg_shard/stargazers","contributors_url":"https://api.github.com/repos/citusdata/pg_shard/contributors","subscribers_url":"https://api.github.com/repos/citusdata/pg_shard/subscribers","subscription_url":"https://api.github.com/repos/citusdata/pg_shard/subscription","commits_url":"https://api.github.com/repos/citusdata/pg_shard/commits{/sha}","git_commits_url":"https://api.github.com/repos/citusdata/pg_shard/git/commits{/sha}","comments_url":"https://api.github.com/repos/citusdata/pg_shard/comments{/number}","issue_comment_url":"https://api.github.com/repos/citusdata/pg_shard/issues/comments{/number}","contents_url":"https://api.github.com/repos/citusdata/pg_shard/contents/{+path}","compare_url":"https://api.github.com/repos/citusdata/pg_shard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/citusdata/pg_shard/merges","archive_url":"https://api.github.com/repos/citusdata/pg_shard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/citusdata/pg_shard/downloads","issues_url":"https://api.github.com/repos/citusdata/pg_shard/issues{/number}","pulls_url":"https://api.github.com/repos/citusdata/pg_shard/pulls{/number}","milestones_url":"https://api.github.com/repos/citusdata/pg_shard/milestones{/number}","notifications_url":"https://api.github.com/repos/citusdata/pg_shard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/citusdata/pg_shard/labels{/name}","releases_url":"https://api.github.com/repos/citusdata/pg_shard/releases{/id}","created_at":"2014-12-04T04:24:37Z","updated_at":"2015-09-18T08:37:58Z","pushed_at":"2015-09-18T13:17:59Z","git_url":"git://github.com/citusdata/pg_shard.git","ssh_url":"git@github.com:citusdata/pg_shard.git","clone_url":"https://github.com/citusdata/pg_shard.git","svn_url":"https://github.com/citusdata/pg_shard","homepage":"","size":3204,"stargazers_count":883,"watchers_count":883,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":44,"forks":44,"open_issues":44,"watchers":883,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/145"},"html":{"href":"https://github.com/citusdata/pg_shard/pull/145"},"issue":{"href":"https://api.github.com/repos/citusdata/pg_shard/issues/145"},"comments":{"href":"https://api.github.com/repos/citusdata/pg_shard/issues/145/comments"},"review_comments":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/145/comments"},"review_comment":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/citusdata/pg_shard/pulls/145/commits"},"statuses":{"href":"https://api.github.com/repos/citusdata/pg_shard/statuses/49bb672b95f6f16d48fbe97ea90b2eebf7b213fc"}}}}