{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/68975590","id":68975590,"diff_hunk":"@@ -0,0 +1,167 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.elasticsearch.action.admin.indices.create;\n+\n+import org.elasticsearch.ElasticsearchTimeoutException;\n+import org.elasticsearch.action.support.ActiveShardCount;\n+import org.elasticsearch.common.settings.Settings;\n+import org.elasticsearch.test.ESIntegTestCase;\n+\n+import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING;\n+import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING;\n+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;\n+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;\n+\n+/**\n+ * Tests that the index creation operation waits for the appropriate\n+ * number of active shards to be started before returning, or\n+ * times out as appropriate.\n+ */\n+@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)\n+public class CreateIndexWaitsIT extends ESIntegTestCase {\n+\n+    public void testCreateIndexNoActiveShardsTimesOut() throws Exception {\n+        final String indexName = \"test-idx\";\n+        Settings.Builder settingsBuilder = Settings.builder()\n+                                               .put(indexSettings())\n+                                               .put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(2, 5))\n+                                               .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0);\n+        if (internalCluster().getNodeNames().length > 0) {\n+            String exclude = String.join(\",\", internalCluster().getNodeNames());\n+            settingsBuilder.put(\"index.routing.allocation.exclude._name\", exclude);\n+        }\n+        Settings settings = settingsBuilder.build();\n+        assertThrows(prepareCreate(indexName)\n+                         .setSettings(settings)\n+                         .setWaitForActiveShards(randomBoolean() ? ActiveShardCount.ONE : ActiveShardCount.ALL)\n+                         .setTimeout(\"2s\"), ElasticsearchTimeoutException.class);\n+    }\n+\n+    public void testCreateIndexNoActiveShardsNoWaiting() throws Exception {\n+        final String indexName = \"test-idx\";\n+        Settings.Builder settingsBuilder = Settings.builder()\n+                                               .put(indexSettings())\n+                                               .put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(2, 5))\n+                                               .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0);\n+        if (internalCluster().getNodeNames().length > 0) {\n+            String exclude = String.join(\",\", internalCluster().getNodeNames());\n+            settingsBuilder.put(\"index.routing.allocation.exclude._name\", exclude);\n+        }\n+        Settings settings = settingsBuilder.build();\n+        CreateIndexResponse response = prepareCreate(indexName)\n+                                           .setSettings(settings)\n+                                           .setWaitForActiveShards(ActiveShardCount.from(0))\n+                                           .setTimeout(\"2s\")\n+                                           .get();\n+        assertTrue(response.isAcknowledged());\n+    }\n+\n+    public void testCreateIndexNotEnoughActiveShardsTimesOut() throws Exception {\n+        final String indexName = \"test-idx\";\n+        final int numReplicas = randomIntBetween(2, 4);\n+        Settings settings = Settings.builder()\n+                                .put(indexSettings())\n+                                .put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(2, 7))\n+                                .put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), numReplicas)\n+                                .build();\n+        final int numNodes = randomIntBetween(1, numReplicas - 1);\n+        internalCluster().ensureAtMostNumDataNodes(numNodes);\n+        assertThrows(prepareCreate(indexName)\n+                         .setSettings(settings)\n+                         .setWaitForActiveShards(ActiveShardCount.from(numNodes + 1))\n+                         .setTimeout(\"2s\"), ElasticsearchTimeoutException.class);","path":"core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexWaitsIT.java","position":89,"original_position":89,"commit_id":"24b180b6a3ded7306fb5ffea11c93c8425092fe8","original_commit_id":"24b180b6a3ded7306fb5ffea11c93c8425092fe8","user":{"login":"ywelsch","id":3718355,"avatar_url":"https://avatars.githubusercontent.com/u/3718355?v=3","gravatar_id":"","url":"https://api.github.com/users/ywelsch","html_url":"https://github.com/ywelsch","followers_url":"https://api.github.com/users/ywelsch/followers","following_url":"https://api.github.com/users/ywelsch/following{/other_user}","gists_url":"https://api.github.com/users/ywelsch/gists{/gist_id}","starred_url":"https://api.github.com/users/ywelsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ywelsch/subscriptions","organizations_url":"https://api.github.com/users/ywelsch/orgs","repos_url":"https://api.github.com/users/ywelsch/repos","events_url":"https://api.github.com/users/ywelsch/events{/privacy}","received_events_url":"https://api.github.com/users/ywelsch/received_events","type":"User","site_admin":false},"body":"having the tests wait 2 seconds is way too long. Please increase the timeouts to 1minute (or leave default) when we expect NOT to have timeouts, otherwise set timeout to 0 so that we instantly run into timeout.","created_at":"2016-06-29T16:01:47Z","updated_at":"2016-06-29T16:01:47Z","html_url":"https://github.com/elastic/elasticsearch/pull/18985#discussion_r68975590","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/68975590"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/18985#discussion_r68975590"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985","id":74509460,"html_url":"https://github.com/elastic/elasticsearch/pull/18985","diff_url":"https://github.com/elastic/elasticsearch/pull/18985.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/18985.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/18985","number":18985,"state":"open","locked":false,"title":"WIP: Index creation waits for write consistency shards","user":{"login":"abeyad","id":1631297,"avatar_url":"https://avatars.githubusercontent.com/u/1631297?v=3","gravatar_id":"","url":"https://api.github.com/users/abeyad","html_url":"https://github.com/abeyad","followers_url":"https://api.github.com/users/abeyad/followers","following_url":"https://api.github.com/users/abeyad/following{/other_user}","gists_url":"https://api.github.com/users/abeyad/gists{/gist_id}","starred_url":"https://api.github.com/users/abeyad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abeyad/subscriptions","organizations_url":"https://api.github.com/users/abeyad/orgs","repos_url":"https://api.github.com/users/abeyad/repos","events_url":"https://api.github.com/users/abeyad/events{/privacy}","received_events_url":"https://api.github.com/users/abeyad/received_events","type":"User","site_admin":false},"body":"Before returning, index creation now waits for the write consistency\r\nnumber of shards to be available. An index can not take any indexing or\r\nother replication operations without the write consistency level of\r\nshards being available anyway, so waiting on the index creation response\r\nin order for this condition to be met makes sense, and allows API users\r\nto not depend on cluster health checks before attempting indexing\r\noperations on the newly created index.","created_at":"2016-06-20T20:41:11Z","updated_at":"2016-06-29T16:01:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"243466708885562fa39172f2a03a65746660746d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/18985/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/24b180b6a3ded7306fb5ffea11c93c8425092fe8","head":{"label":"abeyad:index-creation-wait-for-shards","ref":"index-creation-wait-for-shards","sha":"24b180b6a3ded7306fb5ffea11c93c8425092fe8","user":{"login":"abeyad","id":1631297,"avatar_url":"https://avatars.githubusercontent.com/u/1631297?v=3","gravatar_id":"","url":"https://api.github.com/users/abeyad","html_url":"https://github.com/abeyad","followers_url":"https://api.github.com/users/abeyad/followers","following_url":"https://api.github.com/users/abeyad/following{/other_user}","gists_url":"https://api.github.com/users/abeyad/gists{/gist_id}","starred_url":"https://api.github.com/users/abeyad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abeyad/subscriptions","organizations_url":"https://api.github.com/users/abeyad/orgs","repos_url":"https://api.github.com/users/abeyad/repos","events_url":"https://api.github.com/users/abeyad/events{/privacy}","received_events_url":"https://api.github.com/users/abeyad/received_events","type":"User","site_admin":false},"repo":{"id":48216890,"name":"elasticsearch","full_name":"abeyad/elasticsearch","owner":{"login":"abeyad","id":1631297,"avatar_url":"https://avatars.githubusercontent.com/u/1631297?v=3","gravatar_id":"","url":"https://api.github.com/users/abeyad","html_url":"https://github.com/abeyad","followers_url":"https://api.github.com/users/abeyad/followers","following_url":"https://api.github.com/users/abeyad/following{/other_user}","gists_url":"https://api.github.com/users/abeyad/gists{/gist_id}","starred_url":"https://api.github.com/users/abeyad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abeyad/subscriptions","organizations_url":"https://api.github.com/users/abeyad/orgs","repos_url":"https://api.github.com/users/abeyad/repos","events_url":"https://api.github.com/users/abeyad/events{/privacy}","received_events_url":"https://api.github.com/users/abeyad/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abeyad/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/abeyad/elasticsearch","forks_url":"https://api.github.com/repos/abeyad/elasticsearch/forks","keys_url":"https://api.github.com/repos/abeyad/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abeyad/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abeyad/elasticsearch/teams","hooks_url":"https://api.github.com/repos/abeyad/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/abeyad/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/abeyad/elasticsearch/events","assignees_url":"https://api.github.com/repos/abeyad/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/abeyad/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/abeyad/elasticsearch/tags","blobs_url":"https://api.github.com/repos/abeyad/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abeyad/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abeyad/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/abeyad/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abeyad/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/abeyad/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/abeyad/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/abeyad/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/abeyad/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/abeyad/elasticsearch/subscription","commits_url":"https://api.github.com/repos/abeyad/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/abeyad/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/abeyad/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/abeyad/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/abeyad/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/abeyad/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abeyad/elasticsearch/merges","archive_url":"https://api.github.com/repos/abeyad/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abeyad/elasticsearch/downloads","issues_url":"https://api.github.com/repos/abeyad/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/abeyad/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/abeyad/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/abeyad/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abeyad/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/abeyad/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/abeyad/elasticsearch/deployments","created_at":"2015-12-18T05:46:26Z","updated_at":"2015-12-18T05:46:48Z","pushed_at":"2016-06-28T21:17:26Z","git_url":"git://github.com/abeyad/elasticsearch.git","ssh_url":"git@github.com:abeyad/elasticsearch.git","clone_url":"https://github.com/abeyad/elasticsearch.git","svn_url":"https://github.com/abeyad/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":231773,"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:feature/friendly-index-creation","ref":"feature/friendly-index-creation","sha":"0c741779fc0e1231b8296699413441ad283bbd40","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}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2016-06-29T14:28:36Z","pushed_at":"2016-06-29T15:50:56Z","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":335837,"stargazers_count":17128,"watchers_count":17128,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5801,"mirror_url":null,"open_issues_count":1073,"forks":5801,"open_issues":1073,"watchers":17128,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/18985"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/18985"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/18985/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/18985/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/24b180b6a3ded7306fb5ffea11c93c8425092fe8"}}}}
{"actor":{"display_login":"ywelsch"}}