{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/32311017","id":32311017,"diff_hunk":"@@ -150,8 +158,31 @@ public IndexService(Injector injector, Index index, @IndexSettings Settings inde\n         indexFieldData.setIndexService(this);\n         bitSetFilterCache.setIndexService(this);\n         this.nodeEnv = nodeEnv;\n+        clusterInfoService.addListener(new ShardSizeListener());\n     }\n \n+    /**\n+     * Just records average size of shards in the cluster as a heuristic to help when allocating new shards to data paths.\n+     */\n+    class ShardSizeListener implements ClusterInfoService.Listener {","path":"src/main/java/org/elasticsearch/index/IndexService.java","position":48,"original_position":48,"commit_id":"36bee7095941e1b56fc09fa108540c7503b08665","original_commit_id":"36bee7095941e1b56fc09fa108540c7503b08665","user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"body":"I think this causes a memory leak since IndexService is created per index and if it's closed you need to remove this. you should add this listener in `IndicesService`","created_at":"2015-06-12T12:25:53Z","updated_at":"2015-06-12T12:25:53Z","html_url":"https://github.com/elastic/elasticsearch/pull/11185#discussion_r32311017","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/32311017"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11185#discussion_r32311017"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185","id":35513783,"html_url":"https://github.com/elastic/elasticsearch/pull/11185","diff_url":"https://github.com/elastic/elasticsearch/pull/11185.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/11185.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11185","number":11185,"state":"open","locked":false,"title":"Balance new shard allocations more evenly on multiple path.data","user":{"login":"mikemccand","id":796508,"avatar_url":"https://avatars.githubusercontent.com/u/796508?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemccand","html_url":"https://github.com/mikemccand","followers_url":"https://api.github.com/users/mikemccand/followers","following_url":"https://api.github.com/users/mikemccand/following{/other_user}","gists_url":"https://api.github.com/users/mikemccand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemccand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemccand/subscriptions","organizations_url":"https://api.github.com/users/mikemccand/orgs","repos_url":"https://api.github.com/users/mikemccand/repos","events_url":"https://api.github.com/users/mikemccand/events{/privacy}","received_events_url":"https://api.github.com/users/mikemccand/received_events","type":"User","site_admin":false},"body":"This change adds a simplistic heuristic to try to balance new shard allocations across multiple data paths on one node.\r\n\r\nIt very roughly predicts (guesses!) how much disk space a shard will eventually use, as the max of the current avg. size of shards across the cluster, and 5% of current free space across all path.data on the current node, and then reserves space by counting how many shards are now assigned to each path.data.\r\n\r\nPicking the best path.data for a new shard is using the same \"most free space\" logic, except it now deducts the reserved space.\r\n\r\nI tested this on an EC2 instance with 2 SSDs with nearly the same amount of free space and confirmed we now put 2 shards on one SSD and 3 shards on the other, vs all 5 shards on a single path with master today, but I'm not sure how to make a standalone unit test ... maybe I can use a MockFS to fake up N path.datas with different free space?\r\n\r\nThis is just a heuristic, and it easily has adversarial cases that will fill up one path.data while other path.data on the same node still have plenty of space, and unfortunately ES can't recover from that today. E.g., DiskThresholdDecider won't even detect any problem (since it sums up total free space across all path.data) ... I think we should separately think about fixing that, but at least this change improves the current situation.\r\n\r\nCloses #11122\r\n","created_at":"2015-05-15T13:41:25Z","updated_at":"2015-06-12T12:25:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d77354f8053ceb2212ccfd7db6eab3a400ad4b0","assignee":{"login":"mikemccand","id":796508,"avatar_url":"https://avatars.githubusercontent.com/u/796508?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemccand","html_url":"https://github.com/mikemccand","followers_url":"https://api.github.com/users/mikemccand/followers","following_url":"https://api.github.com/users/mikemccand/following{/other_user}","gists_url":"https://api.github.com/users/mikemccand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemccand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemccand/subscriptions","organizations_url":"https://api.github.com/users/mikemccand/orgs","repos_url":"https://api.github.com/users/mikemccand/repos","events_url":"https://api.github.com/users/mikemccand/events{/privacy}","received_events_url":"https://api.github.com/users/mikemccand/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11185/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/36bee7095941e1b56fc09fa108540c7503b08665","head":{"label":"mikemccand:new_shard_alloc","ref":"new_shard_alloc","sha":"36bee7095941e1b56fc09fa108540c7503b08665","user":{"login":"mikemccand","id":796508,"avatar_url":"https://avatars.githubusercontent.com/u/796508?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemccand","html_url":"https://github.com/mikemccand","followers_url":"https://api.github.com/users/mikemccand/followers","following_url":"https://api.github.com/users/mikemccand/following{/other_user}","gists_url":"https://api.github.com/users/mikemccand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemccand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemccand/subscriptions","organizations_url":"https://api.github.com/users/mikemccand/orgs","repos_url":"https://api.github.com/users/mikemccand/repos","events_url":"https://api.github.com/users/mikemccand/events{/privacy}","received_events_url":"https://api.github.com/users/mikemccand/received_events","type":"User","site_admin":false},"repo":{"id":18938255,"name":"elasticsearch","full_name":"mikemccand/elasticsearch","owner":{"login":"mikemccand","id":796508,"avatar_url":"https://avatars.githubusercontent.com/u/796508?v=3","gravatar_id":"","url":"https://api.github.com/users/mikemccand","html_url":"https://github.com/mikemccand","followers_url":"https://api.github.com/users/mikemccand/followers","following_url":"https://api.github.com/users/mikemccand/following{/other_user}","gists_url":"https://api.github.com/users/mikemccand/gists{/gist_id}","starred_url":"https://api.github.com/users/mikemccand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikemccand/subscriptions","organizations_url":"https://api.github.com/users/mikemccand/orgs","repos_url":"https://api.github.com/users/mikemccand/repos","events_url":"https://api.github.com/users/mikemccand/events{/privacy}","received_events_url":"https://api.github.com/users/mikemccand/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mikemccand/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/mikemccand/elasticsearch","forks_url":"https://api.github.com/repos/mikemccand/elasticsearch/forks","keys_url":"https://api.github.com/repos/mikemccand/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikemccand/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikemccand/elasticsearch/teams","hooks_url":"https://api.github.com/repos/mikemccand/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/mikemccand/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/mikemccand/elasticsearch/events","assignees_url":"https://api.github.com/repos/mikemccand/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/mikemccand/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/mikemccand/elasticsearch/tags","blobs_url":"https://api.github.com/repos/mikemccand/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikemccand/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikemccand/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikemccand/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikemccand/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/mikemccand/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/mikemccand/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/mikemccand/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/mikemccand/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/mikemccand/elasticsearch/subscription","commits_url":"https://api.github.com/repos/mikemccand/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikemccand/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikemccand/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikemccand/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikemccand/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/mikemccand/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikemccand/elasticsearch/merges","archive_url":"https://api.github.com/repos/mikemccand/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikemccand/elasticsearch/downloads","issues_url":"https://api.github.com/repos/mikemccand/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/mikemccand/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/mikemccand/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/mikemccand/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikemccand/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/mikemccand/elasticsearch/releases{/id}","created_at":"2014-04-19T09:41:16Z","updated_at":"2015-03-20T17:44:08Z","pushed_at":"2015-06-08T22:41:10Z","git_url":"git://github.com/mikemccand/elasticsearch.git","ssh_url":"git@github.com:mikemccand/elasticsearch.git","clone_url":"https://github.com/mikemccand/elasticsearch.git","svn_url":"https://github.com/mikemccand/elasticsearch","homepage":"http://elasticsearch.org","size":135983,"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":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"719252a1385a79261e57cf235412abb24c62709b","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-06-12T12:12:17Z","pushed_at":"2015-06-12T12:20:23Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":1890261,"stargazers_count":11577,"watchers_count":11577,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3663,"mirror_url":null,"open_issues_count":1115,"forks":3663,"open_issues":1115,"watchers":11577,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11185"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11185"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11185/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11185/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/36bee7095941e1b56fc09fa108540c7503b08665"}}}}