{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/29454622","id":29454622,"diff_hunk":"@@ -838,46 +864,46 @@ func (r *Range) applyRaftCommand(index uint64, originNodeID multiraft.NodeID, ar\n \treturn reply.Header().GoError()\n }\n \n-// startGossip periodically gossips the cluster ID if it's the first\n-// range. This function should only be called if this range replica is\n-// the raft leader.\n-func (r *Range) startGossip(stopper *util.Stopper) {\n-\tstopper.RunWorker(func() {\n-\t\tr.maybeGossipClusterID()\n-\t\tr.maybeGossipFirstRange()\n-\n-\t\tticker := time.NewTicker(ttlClusterIDGossip / 2)\n-\t\tfor {\n-\t\t\tselect {\n-\t\t\tcase <-ticker.C:\n-\t\t\t\tif held, expired := r.HasLeaderLease(r.rm.Clock().Now()); held && !expired {\n-\t\t\t\t\tr.maybeGossipClusterID()\n-\t\t\t\t\tr.maybeGossipFirstRange()\n-\t\t\t\t}\n-\t\t\tcase <-stopper.ShouldStop():\n-\t\t\t\treturn\n-\t\t\t}\n-\t\t}\n-\t})\n-}\n+// maybeGossipFirstRangeWithLease is periodically called and gossips the\n+// sentinel and first range metadata if the range has the lease and is the\n+// first range. Since one replica in the first range should always gossip this\n+// information, a lease is acquired if there is no active lease.\n+func (r *Range) maybeGossipFirstRangeWithLease() {\n+\t// If no Gossip available (some tests) or not first range: nothing to do.\n+\tif r.rm.Gossip() == nil || !r.isInitialized() || !r.IsFirstRange() {\n+\t\treturn\n+\t}\n+\ttimestamp := r.rm.Clock().Now()\n+\theld, shouldGetLease := r.HasLeaderLease(timestamp)","path":"storage/range.go","position":117,"original_position":117,"commit_id":"04e0fc48e448929594dfa890bde00031ee40ccb7","original_commit_id":"04e0fc48e448929594dfa890bde00031ee40ccb7","user":{"login":"spencerkimball","id":6147149,"avatar_url":"https://avatars.githubusercontent.com/u/6147149?v=3","gravatar_id":"","url":"https://api.github.com/users/spencerkimball","html_url":"https://github.com/spencerkimball","followers_url":"https://api.github.com/users/spencerkimball/followers","following_url":"https://api.github.com/users/spencerkimball/following{/other_user}","gists_url":"https://api.github.com/users/spencerkimball/gists{/gist_id}","starred_url":"https://api.github.com/users/spencerkimball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spencerkimball/subscriptions","organizations_url":"https://api.github.com/users/spencerkimball/orgs","repos_url":"https://api.github.com/users/spencerkimball/repos","events_url":"https://api.github.com/users/spencerkimball/events{/privacy}","received_events_url":"https://api.github.com/users/spencerkimball/received_events","type":"User","site_admin":false},"body":"Renaming this shouldGetLease doesn't make the code clearer. Just keep calling it `expired` I think would be better.\r\n\r\nThis logic is indistinguishable from redirectOnOrAcquireLeaderLease. Why not use that instead of duplicating the logic here? You could just change the parameters that method accepts to\r\n\r\n    func (r *Range) redirectOnOrAcquireLeaderLease(timestamp proto.Timestamp, reason string) error\r\n\r\nAnd supply `\"on read or write pressure\"` in one case and `\"for first range gossip\"` for `reason`","created_at":"2015-04-30T18:09:20Z","updated_at":"2015-04-30T18:09:20Z","html_url":"https://github.com/cockroachdb/cockroach/pull/858#discussion_r29454622","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/29454622"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/858#discussion_r29454622"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858","id":34462959,"html_url":"https://github.com/cockroachdb/cockroach/pull/858","diff_url":"https://github.com/cockroachdb/cockroach/pull/858.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/858.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/858","number":858,"state":"open","locked":false,"title":"run gossip ticker in store & integrate leases","user":{"login":"tschottdorf","id":5076964,"avatar_url":"https://avatars.githubusercontent.com/u/5076964?v=3","gravatar_id":"","url":"https://api.github.com/users/tschottdorf","html_url":"https://github.com/tschottdorf","followers_url":"https://api.github.com/users/tschottdorf/followers","following_url":"https://api.github.com/users/tschottdorf/following{/other_user}","gists_url":"https://api.github.com/users/tschottdorf/gists{/gist_id}","starred_url":"https://api.github.com/users/tschottdorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschottdorf/subscriptions","organizations_url":"https://api.github.com/users/tschottdorf/orgs","repos_url":"https://api.github.com/users/tschottdorf/repos","events_url":"https://api.github.com/users/tschottdorf/events{/privacy}","received_events_url":"https://api.github.com/users/tschottdorf/received_events","type":"User","site_admin":false},"body":"- moved the goroutine responsible for regularly gossiping\r\n  first range information to the store level (since first\r\n  range replicas may change, but stores don't)\r\n- updated the logic to acquire a leader lease if none is\r\n  held on first range gossip; that makes sure we don't\r\n  lose the sentinel and first range info when there's no\r\n  read/write pressure on the first range.\r\n- previously we blindly gossiped whenever we started a\r\n  first range. Ideally there would be aa one-time iteration\r\n  that grabs a lease, but this necessitates various changes\r\n  to existing tests and causes some amount of randomness\r\n  that is tedious to deal with in testing situations.\r\n  put into place a workaround and a detailed TODO for now.\r\n\r\nI'll add some testing code for the regular loop and see if the\r\nTODO can be rectified next.\r\n\r\nfixes #844","created_at":"2015-04-30T14:08:51Z","updated_at":"2015-04-30T18:09:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"60d07b2a0ae6950af74aecd529eee3e0fd4615eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/858/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/04e0fc48e448929594dfa890bde00031ee40ccb7","head":{"label":"tschottdorf:tschottdorf/first_range_gossip","ref":"tschottdorf/first_range_gossip","sha":"04e0fc48e448929594dfa890bde00031ee40ccb7","user":{"login":"tschottdorf","id":5076964,"avatar_url":"https://avatars.githubusercontent.com/u/5076964?v=3","gravatar_id":"","url":"https://api.github.com/users/tschottdorf","html_url":"https://github.com/tschottdorf","followers_url":"https://api.github.com/users/tschottdorf/followers","following_url":"https://api.github.com/users/tschottdorf/following{/other_user}","gists_url":"https://api.github.com/users/tschottdorf/gists{/gist_id}","starred_url":"https://api.github.com/users/tschottdorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschottdorf/subscriptions","organizations_url":"https://api.github.com/users/tschottdorf/orgs","repos_url":"https://api.github.com/users/tschottdorf/repos","events_url":"https://api.github.com/users/tschottdorf/events{/privacy}","received_events_url":"https://api.github.com/users/tschottdorf/received_events","type":"User","site_admin":false},"repo":{"id":23832429,"name":"cockroach","full_name":"tschottdorf/cockroach","owner":{"login":"tschottdorf","id":5076964,"avatar_url":"https://avatars.githubusercontent.com/u/5076964?v=3","gravatar_id":"","url":"https://api.github.com/users/tschottdorf","html_url":"https://github.com/tschottdorf","followers_url":"https://api.github.com/users/tschottdorf/followers","following_url":"https://api.github.com/users/tschottdorf/following{/other_user}","gists_url":"https://api.github.com/users/tschottdorf/gists{/gist_id}","starred_url":"https://api.github.com/users/tschottdorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tschottdorf/subscriptions","organizations_url":"https://api.github.com/users/tschottdorf/orgs","repos_url":"https://api.github.com/users/tschottdorf/repos","events_url":"https://api.github.com/users/tschottdorf/events{/privacy}","received_events_url":"https://api.github.com/users/tschottdorf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tschottdorf/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":true,"url":"https://api.github.com/repos/tschottdorf/cockroach","forks_url":"https://api.github.com/repos/tschottdorf/cockroach/forks","keys_url":"https://api.github.com/repos/tschottdorf/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tschottdorf/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tschottdorf/cockroach/teams","hooks_url":"https://api.github.com/repos/tschottdorf/cockroach/hooks","issue_events_url":"https://api.github.com/repos/tschottdorf/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/tschottdorf/cockroach/events","assignees_url":"https://api.github.com/repos/tschottdorf/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/tschottdorf/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/tschottdorf/cockroach/tags","blobs_url":"https://api.github.com/repos/tschottdorf/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tschottdorf/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tschottdorf/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/tschottdorf/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tschottdorf/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/tschottdorf/cockroach/languages","stargazers_url":"https://api.github.com/repos/tschottdorf/cockroach/stargazers","contributors_url":"https://api.github.com/repos/tschottdorf/cockroach/contributors","subscribers_url":"https://api.github.com/repos/tschottdorf/cockroach/subscribers","subscription_url":"https://api.github.com/repos/tschottdorf/cockroach/subscription","commits_url":"https://api.github.com/repos/tschottdorf/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/tschottdorf/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/tschottdorf/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/tschottdorf/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/tschottdorf/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/tschottdorf/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tschottdorf/cockroach/merges","archive_url":"https://api.github.com/repos/tschottdorf/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tschottdorf/cockroach/downloads","issues_url":"https://api.github.com/repos/tschottdorf/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/tschottdorf/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/tschottdorf/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/tschottdorf/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tschottdorf/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/tschottdorf/cockroach/releases{/id}","created_at":"2014-09-09T12:26:29Z","updated_at":"2015-04-30T01:27:18Z","pushed_at":"2015-04-30T14:44:05Z","git_url":"git://github.com/tschottdorf/cockroach.git","ssh_url":"git@github.com:tschottdorf/cockroach.git","clone_url":"https://github.com/tschottdorf/cockroach.git","svn_url":"https://github.com/tschottdorf/cockroach","homepage":null,"size":15481,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":16,"forks":0,"open_issues":16,"watchers":0,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"498b996cda03e7b432b520fa1adc0be528091a19","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-04-30T18:01:17Z","pushed_at":"2015-04-30T17:47: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":29334,"stargazers_count":3356,"watchers_count":3356,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":259,"mirror_url":null,"open_issues_count":54,"forks":259,"open_issues":54,"watchers":3356,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/858"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/858"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/858/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/858/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/04e0fc48e448929594dfa890bde00031ee40ccb7"}}}}