{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38827228","id":38827228,"diff_hunk":"@@ -0,0 +1,135 @@\n+// Copyright 2015 The Cockroach Authors.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may 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, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n+// implied. See the License for the specific language governing\n+// permissions and limitations under the License. See the AUTHORS file\n+// for names of contributors.\n+//\n+// Author: Bram Gruneir (bram+code@cockroachlabs.com)\n+\n+package storage\n+\n+import (\n+\t\"time\"\n+\n+\t\"github.com/cockroachdb/cockroach/proto\"\n+\t\"github.com/cockroachdb/cockroach/util\"\n+\t\"github.com/cockroachdb/cockroach/util/hlc\"\n+\t\"github.com/cockroachdb/cockroach/util/log\"\n+)\n+\n+const (\n+\t// repairQueueMaxSize is the max size of the replicate queue.\n+\trepairQueueMaxSize = 100\n+\n+\t// replicaQueueTimerDuration is the duration between removals of queued\n+\t// replicas.\n+\trepairQueueTimerDuration = 0 // zero duration to process removals greedily\n+)\n+\n+// repairQueue manages a queue of replicas which may have one of its other\n+// replica on a dead store.\n+type repairQueue struct {\n+\t*baseQueue\n+\tstorePool      *StorePool\n+\treplicateQueue *replicateQueue\n+\tclock          *hlc.Clock\n+}\n+\n+// makeRepairQueue returns a new instance of repairQueue.\n+func makeRepairQueue(storePool *StorePool, replicateQueue *replicateQueue, clock *hlc.Clock) repairQueue {\n+\trq := repairQueue{\n+\t\tstorePool:      storePool,\n+\t\treplicateQueue: replicateQueue,\n+\t\tclock:          clock,\n+\t}\n+\t// rq must be a pointer in order to setup the reference cycle.\n+\trq.baseQueue = newBaseQueue(\"repair\", &rq, repairQueueMaxSize)\n+\treturn rq\n+}\n+\n+// needsLeaderLease implements the queueImpl interface.\n+// This should not require a leader lease, but if we find that there is too\n+// much contention on the replica removals we can revisit that decision.\n+func (rq repairQueue) needsLeaderLease() bool {\n+\treturn false\n+}\n+\n+// shouldQueue implements the queueImpl interface.\n+func (rq repairQueue) shouldQueue(now proto.Timestamp, repl *Replica) (shouldQ bool, priority float64) {\n+\tshouldQ, priority, _ = rq.needsRepair(repl)\n+\treturn\n+}\n+\n+// needsRepair determines if any replicas that belong to the same range as repl\n+// belong to a dead store. If so, it returns the priority (the number of\n+// replicas on dead stores) and the list of these 'dead' replicas.\n+func (rq repairQueue) needsRepair(repl *Replica) (bool, float64, []proto.Replica) {\n+\trangeDesc := repl.Desc()\n+\tvar deadReplicas []proto.Replica\n+\tfor _, otherRepl := range rangeDesc.Replicas {\n+\t\tif rq.storePool.getStoreDetail(otherRepl.StoreID).dead {\n+\t\t\tdeadReplicas = append(deadReplicas, otherRepl)\n+\t\t}\n+\t}\n+\n+\tif len(deadReplicas) == 0 {\n+\t\treturn false, float64(0), deadReplicas\n+\t}\n+\n+\t// Does the range still have a quorum of live replicas? We shouldn't remove\n+\t// one without at least a quorum.\n+\tquorum := (len(rangeDesc.Replicas) / 2) + 1\n+\tliveReplicas := len(rangeDesc.Replicas) - len(deadReplicas)\n+\n+\t// Priority is calculated based on need. By basing this off of the number\n+\t// of live replicas over he quorum amount ensures that in the case where a\n+\t// 5 replica range is only missing one it gets a lower priority than a 3\n+\t// replica range missing 1. Note that this may produce negative priorities,\n+\t// but these are correctly handled by baseQueue.\n+\tpriority := float64(quorum - liveReplicas)\n+\treturn liveReplicas >= quorum, priority, deadReplicas","path":"storage/repair_queue.go","position":99,"original_position":99,"commit_id":"8b2d985e22710cc9eb08abd62074a697a11eaad4","original_commit_id":"8b2d985e22710cc9eb08abd62074a697a11eaad4","user":{"login":"tamird","id":1535036,"avatar_url":"https://avatars.githubusercontent.com/u/1535036?v=3","gravatar_id":"","url":"https://api.github.com/users/tamird","html_url":"https://github.com/tamird","followers_url":"https://api.github.com/users/tamird/followers","following_url":"https://api.github.com/users/tamird/following{/other_user}","gists_url":"https://api.github.com/users/tamird/gists{/gist_id}","starred_url":"https://api.github.com/users/tamird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tamird/subscriptions","organizations_url":"https://api.github.com/users/tamird/orgs","repos_url":"https://api.github.com/users/tamird/repos","events_url":"https://api.github.com/users/tamird/events{/privacy}","received_events_url":"https://api.github.com/users/tamird/received_events","type":"User","site_admin":false},"body":"why is this `liveReplicas >= quorum`? are we not repairing unavailable ranges?","created_at":"2015-09-06T22:53:10Z","updated_at":"2015-09-06T22:53:10Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2336#discussion_r38827228","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38827228"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2336#discussion_r38827228"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336","id":44041210,"html_url":"https://github.com/cockroachdb/cockroach/pull/2336","diff_url":"https://github.com/cockroachdb/cockroach/pull/2336.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2336.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2336","number":2336,"state":"open","locked":false,"title":"Add repair queue [WIP]","user":{"login":"BramGruneir","id":1614265,"avatar_url":"https://avatars.githubusercontent.com/u/1614265?v=3","gravatar_id":"","url":"https://api.github.com/users/BramGruneir","html_url":"https://github.com/BramGruneir","followers_url":"https://api.github.com/users/BramGruneir/followers","following_url":"https://api.github.com/users/BramGruneir/following{/other_user}","gists_url":"https://api.github.com/users/BramGruneir/gists{/gist_id}","starred_url":"https://api.github.com/users/BramGruneir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BramGruneir/subscriptions","organizations_url":"https://api.github.com/users/BramGruneir/orgs","repos_url":"https://api.github.com/users/BramGruneir/repos","events_url":"https://api.github.com/users/BramGruneir/events{/privacy}","received_events_url":"https://api.github.com/users/BramGruneir/received_events","type":"User","site_admin":false},"body":"This is the basic structure for the repair queue.  Please take a look.\r\nThis doesn't yet include the client test where we actually remove a store.\r\n","created_at":"2015-09-02T20:55:10Z","updated_at":"2015-09-06T22:53:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"12fe46a5b5363bc0b0233694abd2d06fb0a7c50f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2336/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/8b2d985e22710cc9eb08abd62074a697a11eaad4","head":{"label":"cockroachdb:bram/repair","ref":"bram/repair","sha":"8b2d985e22710cc9eb08abd62074a697a11eaad4","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-09-06T22:09:21Z","pushed_at":"2015-09-06T22:36:26Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":51683,"stargazers_count":5174,"watchers_count":5174,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":413,"mirror_url":null,"open_issues_count":155,"forks":413,"open_issues":155,"watchers":5174,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"013810431870dca47d9ac7b36e3d41c027bad064","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-09-06T22:09:21Z","pushed_at":"2015-09-06T22:36:26Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":51683,"stargazers_count":5174,"watchers_count":5174,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":413,"mirror_url":null,"open_issues_count":155,"forks":413,"open_issues":155,"watchers":5174,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2336"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2336"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2336/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2336/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/8b2d985e22710cc9eb08abd62074a697a11eaad4"}}}}