{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38702462","id":38702462,"diff_hunk":"@@ -99,28 +113,45 @@ func (rq replicateQueue) process(now proto.Timestamp, repl *Replica) error {\n \t}\n \n \tdesc := repl.Desc()\n-\tif needs, _ := rq.needsReplication(zone, repl, desc); !needs {\n+\tdelta := rq.replicaDelta(zone, repl, desc)\n+\tif delta == 0 {\n \t\t// Something changed between shouldQueue and process.\n \t\treturn nil\n \t}\n \n-\t// TODO(bdarnell): handle non-homogeneous ReplicaAttrs.\n-\t// Allow constraints to be relaxed if necessary.\n-\tnewReplica, err := rq.allocator.allocateTarget(zone.ReplicaAttrs[0], desc.Replicas, true, nil)\n-\tif err != nil {\n-\t\treturn err\n-\t}\n+\t// TODO(bdarnell): handle non-homogenous ReplicaAttrs.\n+\tif delta > 0 {\n+\t\t// Allow constraints to be relaxed if necessary.\n+\t\tnewReplica, err := rq.allocator.allocateTarget(zone.ReplicaAttrs[0], desc.Replicas, true, nil)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n \n-\treplica := proto.Replica{\n-\t\tNodeID:  newReplica.Node.NodeID,\n-\t\tStoreID: newReplica.StoreID,\n-\t}\n-\tif err = repl.ChangeReplicas(proto.ADD_REPLICA, replica, desc); err != nil {\n-\t\treturn err\n+\t\treplica := proto.Replica{\n+\t\t\tNodeID:  newReplica.Node.NodeID,\n+\t\t\tStoreID: newReplica.StoreID,\n+\t\t}\n+\t\tif err = repl.ChangeReplicas(proto.ADD_REPLICA, replica, desc); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t} else {\n+\t\tremoveReplica, err := rq.allocator.removeTarget(desc.Replicas)\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t\tif log.V(1) {\n+\t\t\tlog.Infof(\"Remove replica %s\", removeReplica)\n+\t\t}\n+\n+\t\tif err = repl.ChangeReplicas(proto.REMOVE_REPLICA, removeReplica, desc); err != nil {\n+\t\t\tif log.V(1) {\n+\t\t\t\tlog.Infof(\"Error removing replica %s\", err)\n+\t\t\t}\n+\t\t\treturn err\n+\t\t}\n \t}\n \n \t// Enqueue this replica again to see if there are more changes to be made.\n-\t//go rq.MaybeAdd(repl, rq.clock.Now())","path":"storage/replicate_queue.go","position":101,"original_position":101,"commit_id":"1a81f28cc4313012de5e99af6feac534ea7799a7","original_commit_id":"1a81f28cc4313012de5e99af6feac534ea7799a7","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 line should probably be restored and the one below it removed.  I think I removed the go routine accidentally as part of another change.","created_at":"2015-09-03T22:09:26Z","updated_at":"2015-09-03T22:09:26Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2350#discussion_r38702462","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/38702462"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2350#discussion_r38702462"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350","id":44162861,"html_url":"https://github.com/cockroachdb/cockroach/pull/2350","diff_url":"https://github.com/cockroachdb/cockroach/pull/2350.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2350.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2350","number":2350,"state":"open","locked":false,"title":"Add downreplication to Replicate queue","user":{"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},"body":"The Replicate Queue can now remove replicas from a range that is\r\nover-replicated.","created_at":"2015-09-03T21:59:52Z","updated_at":"2015-09-03T22:09:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e95b94a895be72231ffd37ca93a30b197eca7ed5","assignee":{"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},"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2350/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/1a81f28cc4313012de5e99af6feac534ea7799a7","head":{"label":"mrtracy:mtracy/replicate_queue_enhance","ref":"mtracy/replicate_queue_enhance","sha":"1a81f28cc4313012de5e99af6feac534ea7799a7","user":{"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},"repo":{"id":39856388,"name":"cockroach","full_name":"mrtracy/cockroach","owner":{"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},"private":false,"html_url":"https://github.com/mrtracy/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":true,"url":"https://api.github.com/repos/mrtracy/cockroach","forks_url":"https://api.github.com/repos/mrtracy/cockroach/forks","keys_url":"https://api.github.com/repos/mrtracy/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrtracy/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrtracy/cockroach/teams","hooks_url":"https://api.github.com/repos/mrtracy/cockroach/hooks","issue_events_url":"https://api.github.com/repos/mrtracy/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/mrtracy/cockroach/events","assignees_url":"https://api.github.com/repos/mrtracy/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/mrtracy/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/mrtracy/cockroach/tags","blobs_url":"https://api.github.com/repos/mrtracy/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrtracy/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrtracy/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrtracy/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrtracy/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/mrtracy/cockroach/languages","stargazers_url":"https://api.github.com/repos/mrtracy/cockroach/stargazers","contributors_url":"https://api.github.com/repos/mrtracy/cockroach/contributors","subscribers_url":"https://api.github.com/repos/mrtracy/cockroach/subscribers","subscription_url":"https://api.github.com/repos/mrtracy/cockroach/subscription","commits_url":"https://api.github.com/repos/mrtracy/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrtracy/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrtracy/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrtracy/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/mrtracy/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/mrtracy/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrtracy/cockroach/merges","archive_url":"https://api.github.com/repos/mrtracy/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrtracy/cockroach/downloads","issues_url":"https://api.github.com/repos/mrtracy/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/mrtracy/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/mrtracy/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/mrtracy/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrtracy/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/mrtracy/cockroach/releases{/id}","created_at":"2015-07-28T20:33:41Z","updated_at":"2015-07-28T20:33:42Z","pushed_at":"2015-09-03T22:02:23Z","git_url":"git://github.com/mrtracy/cockroach.git","ssh_url":"git@github.com:mrtracy/cockroach.git","clone_url":"https://github.com/mrtracy/cockroach.git","svn_url":"https://github.com/mrtracy/cockroach","homepage":null,"size":28615,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"cockroachdb:master","ref":"master","sha":"bf0b84704ad462d01597ec355c56fd5c8c80c42f","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-03T22:06:18Z","pushed_at":"2015-09-03T22:08:53Z","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":54295,"stargazers_count":5133,"watchers_count":5133,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":408,"mirror_url":null,"open_issues_count":158,"forks":408,"open_issues":158,"watchers":5133,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2350"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2350"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2350/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2350/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/1a81f28cc4313012de5e99af6feac534ea7799a7"}}}}