{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/57874974","id":57874974,"diff_hunk":"@@ -0,0 +1,449 @@\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.cluster.metadata;\n+\n+import org.elasticsearch.cluster.Diff;\n+import org.elasticsearch.cluster.Diffable;\n+import org.elasticsearch.common.ParseField;\n+import org.elasticsearch.common.io.stream.StreamInput;\n+import org.elasticsearch.common.io.stream.StreamInputReader;\n+import org.elasticsearch.common.io.stream.StreamOutput;\n+import org.elasticsearch.common.io.stream.Writeable;\n+import org.elasticsearch.common.xcontent.ObjectParser;\n+import org.elasticsearch.common.xcontent.ToXContent;\n+import org.elasticsearch.common.xcontent.XContentBuilder;\n+import org.elasticsearch.common.xcontent.XContentParser;\n+import org.elasticsearch.index.Index;\n+\n+import java.io.IOException;\n+import java.util.ArrayDeque;\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.Deque;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.Objects;\n+import java.util.Optional;\n+\n+/**\n+ * A collection of tombstones for explicitly marking indices as deleted in the cluster state.\n+ *\n+ * The cluster state contains a list of index tombstones for indices that have been\n+ * deleted in the cluster.  Because cluster states are processed asynchronously by\n+ * nodes and a node could be removed from the cluster for a period of time, the\n+ * tombstones remain in the cluster state for a fixed period of time, after which\n+ * they are purged.\n+ */\n+final public class IndexGraveyard implements ToXContent, Diffable<IndexGraveyard> {\n+\n+    // X-Content key for index tombstones\n+    public static final String TOMBSTONES_KEY = \"index_tombstones\";\n+\n+    // Setting for the maximum tombstones allowed in the cluster state;\n+    // prevents the cluster state size from exploding too large, but it opens the\n+    // very unlikely risk that if there are greater than MAX_TOMBSTONES index\n+    // deletions while a node was offline, when it comes back online, it will have\n+    // missed index deletions that it may need to process.\n+    private static final int MAX_TOMBSTONES = 10000;\n+\n+    // Setting for the expiration window of tombstone entries.  Any tombstone entries\n+    // that have been in the list longer than EXPIRATION_WINDOW will be purged on the\n+    // next cluster update.\n+    static final long EXPIRATION_WINDOW = 1000 * 60 * 60 * 24 * 14; // 14 days\n+\n+    // holds the index tombstones\n+    private final Deque<Tombstone> tombstones;","path":"core/src/main/java/org/elasticsearch/cluster/metadata/IndexGraveyard.java","position":72,"original_position":72,"commit_id":"953299fb5971e3c2ed5b64e61c22b61ccdc40bb2","original_commit_id":"953299fb5971e3c2ed5b64e61c22b61ccdc40bb2","user":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"body":"why not have a simple array?","created_at":"2016-03-30T11:46:18Z","updated_at":"2016-03-30T11:46:18Z","html_url":"https://github.com/elastic/elasticsearch/pull/17265#discussion_r57874974","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/57874974"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/17265#discussion_r57874974"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265","id":63827841,"html_url":"https://github.com/elastic/elasticsearch/pull/17265","diff_url":"https://github.com/elastic/elasticsearch/pull/17265.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/17265.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/17265","number":17265,"state":"open","locked":false,"title":"Adds tombstones to cluster state for index deletions","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":"Previously, we would determine index deletes in the cluster state by\r\ncomparing the index metadatas between the current cluster state and the\r\nprevious cluster state and decipher which ones were missing (the missing\r\nones are deleted indices).  This led to confusing logic where it was\r\ndifficult to decipher if a missing index in the cluster state was truly\r\ndue to a delete and must be deleted on all nodes, or if it was due to\r\nthe cluster state being wiped out on master and thus, we want the\r\nindices on the various nodes in the cluster to be imported as dangling\r\nindices.\r\n\r\nThis commit introduces the notion of index tombstones in the cluster\r\nstate, where we are explicit about which indices have been deleted.\r\nIndex deletion on each node is now based on the presence of these\r\ntombstones in the cluster state.  There is also functionality to purge\r\nthe tombstones after a 14 day expiry, so they don't stick around in the\r\ncluster state forever.\r\n\r\nCloses #16358","created_at":"2016-03-23T03:46:12Z","updated_at":"2016-03-30T11:46:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94d7b624f778599f76dd81449561cf27b44ba9ab","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/17265/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/953299fb5971e3c2ed5b64e61c22b61ccdc40bb2","head":{"label":"abeyad:feature/tombstone-deleted-indices","ref":"feature/tombstone-deleted-indices","sha":"953299fb5971e3c2ed5b64e61c22b61ccdc40bb2","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-03-29T20:57:48Z","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":205064,"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":"19eeb68bc4b9c404ff95f70de3dcc70f433bcead","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-03-30T11:00:33Z","pushed_at":"2016-03-30T11:37:40Z","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":300116,"stargazers_count":15760,"watchers_count":15760,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5263,"mirror_url":null,"open_issues_count":1074,"forks":5263,"open_issues":1074,"watchers":15760,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/17265"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/17265"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/17265/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/17265/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/953299fb5971e3c2ed5b64e61c22b61ccdc40bb2"}}}}