{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38322483","id":38322483,"diff_hunk":"@@ -0,0 +1,298 @@\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\"container/heap\"\n+\t\"sort\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\tgogoproto \"github.com/gogo/protobuf/proto\"\n+\n+\t\"github.com/cockroachdb/cockroach/gossip\"\n+\t\"github.com/cockroachdb/cockroach/proto\"\n+\t\"github.com/cockroachdb/cockroach/util/hlc\"\n+\t\"github.com/cockroachdb/cockroach/util/log\"\n+\t\"github.com/cockroachdb/cockroach/util/stop\"\n+)\n+\n+const (\n+\t// testTimeUntilStoreDead is the the test value for TimeUntilStoreDead to\n+\t// quickly mark stores as dead.\n+\ttestTimeUntilStoreDead = 10 * time.Millisecond\n+\n+\t// TestTimeUntilStoreDeadOff is the test value for TimeUntilStoreDead that\n+\t// prevents the store pool from marking stores as dead.\n+\tTestTimeUntilStoreDeadOff = 24 * time.Hour\n+)\n+\n+type storeDetail struct {\n+\tdesc            proto.StoreDescriptor\n+\tdead            bool\n+\ttimesDied       int\n+\tfoundDeadOn     time.Time\n+\tlastUpdatedTime time.Time // This is also the priority for the queue.\n+\tindex           int       // index of the item in the heap, required for heap.Interface\n+}\n+\n+// markDead sets the storeDetail to dead(inactive).\n+func (sd *storeDetail) markDead(foundDeadOn time.Time) {\n+\tsd.dead = true\n+\tsd.foundDeadOn = foundDeadOn\n+\tsd.timesDied++\n+\tlog.Warningf(\"store %s on node %s is now considered offline\", sd.desc.StoreID, sd.desc.Node.NodeID)\n+}\n+\n+// markAlive sets the storeDetail to alive(active) and saves the updated time\n+// and descriptor.\n+func (sd *storeDetail) markAlive(foundAliveOn time.Time, storeDesc proto.StoreDescriptor) {\n+\tsd.desc = storeDesc\n+\tsd.dead = false\n+\tsd.lastUpdatedTime = foundAliveOn\n+}\n+\n+// storePoolPQ implements the heap.Interface (which includes  sort.Interface)\n+// and holds storeDetail.\n+type storePoolPQ []*storeDetail\n+\n+// Len implements the sort.Interface.\n+func (pq storePoolPQ) Len() int {\n+\treturn len(pq)\n+}\n+\n+// Less implements the sort.Interface.\n+func (pq storePoolPQ) Less(i, j int) bool {\n+\treturn pq[i].lastUpdatedTime.UnixNano() < pq[j].lastUpdatedTime.UnixNano()\n+}\n+\n+// Swap implements the sort.Interface.\n+func (pq storePoolPQ) Swap(i, j int) {\n+\tpq[i], pq[j] = pq[j], pq[i]\n+\tpq[i].index, pq[j].index = i, j\n+}\n+\n+// Push implements the heap.Interface.\n+func (pq *storePoolPQ) Push(x interface{}) {\n+\tn := len(*pq)\n+\titem := x.(*storeDetail)\n+\titem.index = n\n+\t*pq = append(*pq, item)\n+}\n+\n+// Pop implements the heap.Interface.\n+func (pq *storePoolPQ) Pop() interface{} {\n+\told := *pq\n+\tn := len(old)\n+\titem := old[n-1]\n+\titem.index = -1 // for safety\n+\t*pq = old[0 : n-1]\n+\treturn item\n+}\n+\n+// peek returns the next value in the priority queue without dequeuing it.\n+// Lock is assumed held by caller.\n+func (pq *storePoolPQ) peek() *storeDetail {\n+\tif len(*pq) == 0 {\n+\t\treturn nil\n+\t}\n+\tdetail := (*pq)[0]\n+\treturn detail\n+}\n+\n+// enqueue either adds the detail to the queue or updates its location in the\n+// priority queue.\n+// Lock is assumed held by caller.\n+func (pq *storePoolPQ) enqueue(detail *storeDetail) {\n+\tif detail.index < 0 {\n+\t\theap.Push(pq, detail)\n+\t} else {\n+\t\theap.Fix(pq, detail.index)\n+\t}\n+}\n+\n+// dequeue removes the next detail from the priority queue.\n+// Lock is assumed help by the caller.\n+func (pq *storePoolPQ) dequeue() *storeDetail {\n+\tif len(*pq) == 0 {\n+\t\treturn nil\n+\t}\n+\tdetail := heap.Pop(pq).(*storeDetail)","path":"storage/store_pool.go","position":135,"original_position":135,"commit_id":"28ff9354ab698e449132c7813e711f50f33ec8bc","original_commit_id":"28ff9354ab698e449132c7813e711f50f33ec8bc","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":"nope, I think it was there from when I was testing.","created_at":"2015-08-31T15:19:55Z","updated_at":"2015-08-31T15:19:55Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2286#discussion_r38322483","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38322483"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2286#discussion_r38322483"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286","id":43578189,"html_url":"https://github.com/cockroachdb/cockroach/pull/2286","diff_url":"https://github.com/cockroachdb/cockroach/pull/2286.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2286.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2286","number":2286,"state":"open","locked":false,"title":"Adds StorePool","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":"StorePool will keep a list of alive/dead nodes as per the RPC from #2191\r\nThe allocator uses StorePool to ensure that the stores being picked are indeed alive.\r\n\r\nNext up will be:\r\n- get the scanner to sniff out replicas on failed stores\r\n\r\n","created_at":"2015-08-27T23:17:01Z","updated_at":"2015-08-31T15:19:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b6aa1acf46d723544c17f456d3102e0a4f37530","assignee":{"login":"mrtracy","id":6969858,"avatar_url":"https://avatars.githubusercontent.com/u/6969858?v=3","gravatar_id":"","url":"https://api.github.com/users/mrtracy","html_url":"https://github.com/mrtracy","followers_url":"https://api.github.com/users/mrtracy/followers","following_url":"https://api.github.com/users/mrtracy/following{/other_user}","gists_url":"https://api.github.com/users/mrtracy/gists{/gist_id}","starred_url":"https://api.github.com/users/mrtracy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrtracy/subscriptions","organizations_url":"https://api.github.com/users/mrtracy/orgs","repos_url":"https://api.github.com/users/mrtracy/repos","events_url":"https://api.github.com/users/mrtracy/events{/privacy}","received_events_url":"https://api.github.com/users/mrtracy/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2286/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/28ff9354ab698e449132c7813e711f50f33ec8bc","head":{"label":"cockroachdb:bram/store-pool","ref":"bram/store-pool","sha":"28ff9354ab698e449132c7813e711f50f33ec8bc","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-08-31T15:08:08Z","pushed_at":"2015-08-31T14:52:15Z","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":52476,"stargazers_count":5068,"watchers_count":5068,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":404,"mirror_url":null,"open_issues_count":153,"forks":404,"open_issues":153,"watchers":5068,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"8273b2922c55bfcb0c9a7205d4cf364e0e121628","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-08-31T15:08:08Z","pushed_at":"2015-08-31T14:52:15Z","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":52476,"stargazers_count":5068,"watchers_count":5068,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":404,"mirror_url":null,"open_issues_count":153,"forks":404,"open_issues":153,"watchers":5068,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2286"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2286"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2286/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2286/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/28ff9354ab698e449132c7813e711f50f33ec8bc"}}}}