{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/comments/64022313","id":64022313,"diff_hunk":"@@ -131,13 +97,118 @@ impl<'a> Peekable for RegionSnapshot<'a> {\n     }\n }\n \n+/// `RegionIterator` wrap a rocksdb iterator and only allow it to\n+/// iterate in the region. It behaves as if underlying\n+/// db only contains one region.\n+pub struct RegionIterator<'a> {\n+    iter: DBIterator<'a>,\n+\n+    valid: bool,\n+    start_key: Vec<u8>,\n+    end_key: Vec<u8>,\n+}\n+\n+// we use rocksdb's style iterator, so omit the warning.\n+#[allow(should_implement_trait)]\n+impl<'a> RegionIterator<'a> {\n+    pub fn new(iter: DBIterator<'a>, region: &Region) -> RegionIterator<'a> {\n+        RegionIterator {\n+            iter: iter,\n+\n+            valid: false,\n+            start_key: keys::enc_start_key(region),\n+            end_key: keys::enc_end_key(region),\n+        }\n+    }\n+\n+    pub fn seek_to_first(&mut self) -> bool {\n+        self.valid = self.iter.seek(self.start_key.as_slice().into());\n+\n+        self.update_valid()\n+    }\n+\n+    #[inline]\n+    fn update_valid(&mut self) -> bool {\n+        if self.valid {\n+            let key = self.iter.key();\n+            self.valid = key >= &self.start_key && (self.end_key.is_empty() || key < &self.end_key);\n+        }\n+        self.valid\n+    }\n+\n+    pub fn seek_to_last(&mut self) -> bool {\n+        if (self.end_key.is_empty() || !self.iter.seek(self.end_key.as_slice().into())) &&\n+           !self.iter.seek(SeekKey::End) {\n+            self.valid = false;\n+            return self.valid;\n+        }\n+\n+        if !self.end_key.is_empty() {\n+            while self.iter.key() >= &self.end_key && self.iter.prev() {","path":"src/raftstore/coprocessor/region_snapshot.rs","position":179,"original_position":179,"commit_id":"027e0c08005d788995a57ede583b87d3b53cb861","original_commit_id":"027e0c08005d788995a57ede583b87d3b53cb861","user":{"login":"ngaut","id":878009,"avatar_url":"https://avatars.githubusercontent.com/u/878009?v=3","gravatar_id":"","url":"https://api.github.com/users/ngaut","html_url":"https://github.com/ngaut","followers_url":"https://api.github.com/users/ngaut/followers","following_url":"https://api.github.com/users/ngaut/following{/other_user}","gists_url":"https://api.github.com/users/ngaut/gists{/gist_id}","starred_url":"https://api.github.com/users/ngaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngaut/subscriptions","organizations_url":"https://api.github.com/users/ngaut/orgs","repos_url":"https://api.github.com/users/ngaut/repos","events_url":"https://api.github.com/users/ngaut/events{/privacy}","received_events_url":"https://api.github.com/users/ngaut/received_events","type":"User","site_admin":false},"body":"Could you simplify call self.iter.seek(self.end_key) ?","created_at":"2016-05-20T10:46:12Z","updated_at":"2016-05-20T10:46:12Z","html_url":"https://github.com/pingcap/tikv/pull/596#discussion_r64022313","pull_request_url":"https://api.github.com/repos/pingcap/tikv/pulls/596","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments/64022313"},"html":{"href":"https://github.com/pingcap/tikv/pull/596#discussion_r64022313"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/596"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/596","id":70831926,"html_url":"https://github.com/pingcap/tikv/pull/596","diff_url":"https://github.com/pingcap/tikv/pull/596.diff","patch_url":"https://github.com/pingcap/tikv/pull/596.patch","issue_url":"https://api.github.com/repos/pingcap/tikv/issues/596","number":596,"state":"open","locked":false,"title":"storage: introduce interator","user":{"login":"BusyJay","id":1701473,"avatar_url":"https://avatars.githubusercontent.com/u/1701473?v=3","gravatar_id":"","url":"https://api.github.com/users/BusyJay","html_url":"https://github.com/BusyJay","followers_url":"https://api.github.com/users/BusyJay/followers","following_url":"https://api.github.com/users/BusyJay/following{/other_user}","gists_url":"https://api.github.com/users/BusyJay/gists{/gist_id}","starred_url":"https://api.github.com/users/BusyJay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BusyJay/subscriptions","organizations_url":"https://api.github.com/users/BusyJay/orgs","repos_url":"https://api.github.com/users/BusyJay/repos","events_url":"https://api.github.com/users/BusyJay/events{/privacy}","received_events_url":"https://api.github.com/users/BusyJay/received_events","type":"User","site_admin":false},"body":"This is the first peer for #540.\r\n\r\n@ngaut @disksing PTAL","created_at":"2016-05-20T10:17:40Z","updated_at":"2016-05-20T10:46:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b86c430408481f85dceb9bb1cb5f2565329281e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tikv/pulls/596/commits","review_comments_url":"https://api.github.com/repos/pingcap/tikv/pulls/596/comments","review_comment_url":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tikv/issues/596/comments","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/027e0c08005d788995a57ede583b87d3b53cb861","head":{"label":"pingcap:busyjay/introduce-iterator","ref":"busyjay/introduce-iterator","sha":"027e0c08005d788995a57ede583b87d3b53cb861","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":48833910,"name":"tikv","full_name":"pingcap/tikv","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":false,"url":"https://api.github.com/repos/pingcap/tikv","forks_url":"https://api.github.com/repos/pingcap/tikv/forks","keys_url":"https://api.github.com/repos/pingcap/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tikv/teams","hooks_url":"https://api.github.com/repos/pingcap/tikv/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tikv/events","assignees_url":"https://api.github.com/repos/pingcap/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tikv/tags","blobs_url":"https://api.github.com/repos/pingcap/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tikv/languages","stargazers_url":"https://api.github.com/repos/pingcap/tikv/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tikv/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tikv/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tikv/subscription","commits_url":"https://api.github.com/repos/pingcap/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tikv/merges","archive_url":"https://api.github.com/repos/pingcap/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tikv/downloads","issues_url":"https://api.github.com/repos/pingcap/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tikv/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tikv/deployments","created_at":"2015-12-31T04:51:32Z","updated_at":"2016-05-20T03:07:57Z","pushed_at":"2016-05-20T10:17:41Z","git_url":"git://github.com/pingcap/tikv.git","ssh_url":"git@github.com:pingcap/tikv.git","clone_url":"https://github.com/pingcap/tikv.git","svn_url":"https://github.com/pingcap/tikv","homepage":"","size":3021,"stargazers_count":654,"watchers_count":654,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":46,"mirror_url":null,"open_issues_count":30,"forks":46,"open_issues":30,"watchers":654,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"af24ef499ea4260f03ffa67834d7ed0b2f541dc8","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":48833910,"name":"tikv","full_name":"pingcap/tikv","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":false,"url":"https://api.github.com/repos/pingcap/tikv","forks_url":"https://api.github.com/repos/pingcap/tikv/forks","keys_url":"https://api.github.com/repos/pingcap/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tikv/teams","hooks_url":"https://api.github.com/repos/pingcap/tikv/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tikv/events","assignees_url":"https://api.github.com/repos/pingcap/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tikv/tags","blobs_url":"https://api.github.com/repos/pingcap/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tikv/languages","stargazers_url":"https://api.github.com/repos/pingcap/tikv/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tikv/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tikv/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tikv/subscription","commits_url":"https://api.github.com/repos/pingcap/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tikv/merges","archive_url":"https://api.github.com/repos/pingcap/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tikv/downloads","issues_url":"https://api.github.com/repos/pingcap/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tikv/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/tikv/deployments","created_at":"2015-12-31T04:51:32Z","updated_at":"2016-05-20T03:07:57Z","pushed_at":"2016-05-20T10:17:41Z","git_url":"git://github.com/pingcap/tikv.git","ssh_url":"git@github.com:pingcap/tikv.git","clone_url":"https://github.com/pingcap/tikv.git","svn_url":"https://github.com/pingcap/tikv","homepage":"","size":3021,"stargazers_count":654,"watchers_count":654,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":46,"mirror_url":null,"open_issues_count":30,"forks":46,"open_issues":30,"watchers":654,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/596"},"html":{"href":"https://github.com/pingcap/tikv/pull/596"},"issue":{"href":"https://api.github.com/repos/pingcap/tikv/issues/596"},"comments":{"href":"https://api.github.com/repos/pingcap/tikv/issues/596/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/596/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/596/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tikv/statuses/027e0c08005d788995a57ede583b87d3b53cb861"}}}}
{"actor":{"display_login":"ngaut"}}