{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/comments/191701361","pull_request_review_id":124321012,"id":191701361,"diff_hunk":"@@ -0,0 +1,190 @@\n+// Copyright 2018 PingCAP, Inc.\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+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+use super::engine::{Engine, ScanMode};\n+use super::mvcc::{MvccReader, MvccTxn, MAX_TXN_WRITE_SIZE};\n+use super::txn::GC_BATCH_SIZE;\n+use super::{Callback, Error, Key, Result};\n+use kvproto::kvrpcpb::Context;\n+use std::fmt::{self, Display, Formatter};\n+use std::sync::{Arc, Mutex};\n+use util::worker::{self, Builder, Runnable, Worker};\n+\n+struct GCTask {\n+    pub ctx: Context,\n+    pub safe_point: u64,\n+    pub callback: Callback<()>,\n+}\n+\n+impl Display for GCTask {\n+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {\n+        let epoch = match self.ctx.region_epoch.as_ref() {\n+            None => \"None\".to_string(),\n+            Some(e) => format!(\"{{{}, {}}}\", e.conf_ver, e.version),\n+        };\n+        write!(\n+            f,\n+            \"GC task at region {}, epoch {}, safe_point {}\",\n+            self.ctx.region_id, epoch, self.safe_point\n+        )\n+    }\n+}\n+\n+// `GCRunner` is used to perform GC on the engine\n+struct GCRunner {\n+    engine: Box<Engine>,\n+    gc_ratio_threshold: f64,\n+}\n+\n+impl GCRunner {\n+    pub fn new(engine: Box<Engine>, gc_ratio_threshold: f64) -> GCRunner {\n+        GCRunner {\n+            engine,\n+            gc_ratio_threshold,\n+        }\n+    }\n+\n+    fn gc_scan_keys(\n+        &self,\n+        ctx: &Context,\n+        safe_point: u64,\n+        next_scan_key: Option<Key>,\n+    ) -> Result<(Option<Vec<Key>>, Option<Key>)> {\n+        let snapshot = self.engine.snapshot(ctx)?;\n+        let mut reader = MvccReader::new(\n+            snapshot,\n+            Some(ScanMode::Forward),\n+            !ctx.get_not_fill_cache(),\n+            None,\n+            None,\n+            ctx.get_isolation_level(),\n+        );\n+        if !reader.need_gc(safe_point, self.gc_ratio_threshold) {\n+            Ok((None, None))\n+        } else {\n+            reader\n+                .scan_keys(next_scan_key, GC_BATCH_SIZE)","path":"src/storage/gc_worker.rs","position":76,"original_position":76,"commit_id":"9acd44a4b90ae59d63a134f32abf220a6995265f","original_commit_id":"89c67ea0ab0c7c73ffc7b8d1e2ce96201b5653ff","user":{"login":"MyonKeminta","id":9948422,"avatar_url":"https://avatars1.githubusercontent.com/u/9948422?v=4","gravatar_id":"","url":"https://api.github.com/users/MyonKeminta","html_url":"https://github.com/MyonKeminta","followers_url":"https://api.github.com/users/MyonKeminta/followers","following_url":"https://api.github.com/users/MyonKeminta/following{/other_user}","gists_url":"https://api.github.com/users/MyonKeminta/gists{/gist_id}","starred_url":"https://api.github.com/users/MyonKeminta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MyonKeminta/subscriptions","organizations_url":"https://api.github.com/users/MyonKeminta/orgs","repos_url":"https://api.github.com/users/MyonKeminta/repos","events_url":"https://api.github.com/users/MyonKeminta/events{/privacy}","received_events_url":"https://api.github.com/users/MyonKeminta/received_events","type":"User","site_admin":false},"body":"How about move it (and other `XXX_BATCH_SIZE`s) to `txn/mod.rs`?","created_at":"2018-05-30T09:32:05Z","updated_at":"2018-05-30T09:32:05Z","html_url":"https://github.com/pingcap/tikv/pull/3119#discussion_r191701361","pull_request_url":"https://api.github.com/repos/pingcap/tikv/pulls/3119","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments/191701361"},"html":{"href":"https://github.com/pingcap/tikv/pull/3119#discussion_r191701361"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/3119"}},"in_reply_to_id":191688138},"pull_request":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/3119","id":191116102,"html_url":"https://github.com/pingcap/tikv/pull/3119","diff_url":"https://github.com/pingcap/tikv/pull/3119.diff","patch_url":"https://github.com/pingcap/tikv/pull/3119.patch","issue_url":"https://api.github.com/repos/pingcap/tikv/issues/3119","number":3119,"state":"open","locked":false,"title":"storage: Move GC out of scheduler","user":{"login":"MyonKeminta","id":9948422,"avatar_url":"https://avatars1.githubusercontent.com/u/9948422?v=4","gravatar_id":"","url":"https://api.github.com/users/MyonKeminta","html_url":"https://github.com/MyonKeminta","followers_url":"https://api.github.com/users/MyonKeminta/followers","following_url":"https://api.github.com/users/MyonKeminta/following{/other_user}","gists_url":"https://api.github.com/users/MyonKeminta/gists{/gist_id}","starred_url":"https://api.github.com/users/MyonKeminta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MyonKeminta/subscriptions","organizations_url":"https://api.github.com/users/MyonKeminta/orgs","repos_url":"https://api.github.com/users/MyonKeminta/repos","events_url":"https://api.github.com/users/MyonKeminta/events{/privacy}","received_events_url":"https://api.github.com/users/MyonKeminta/received_events","type":"User","site_admin":false},"body":"We needn't handle GC requests in Scheduler, which may block them by latches. Locking GC requests by latches is redundant. This PR added a component named `gc_worker` to `Storage`, which is used to handle GC requests.\r\nThis is part of work of distrubuted GC. Next step, gc_worker will be able to scan regions and do GC itself.\r\n\r\n- [ ] Tests\r\n- [ ] Fix broken old tests\r\n- [ ] Metrics","created_at":"2018-05-29T11:35:17Z","updated_at":"2018-05-30T09:32:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"107a3c81a725c58986e0cd0047e77206e82e4206","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tikv/pulls/3119/commits","review_comments_url":"https://api.github.com/repos/pingcap/tikv/pulls/3119/comments","review_comment_url":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tikv/issues/3119/comments","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/9acd44a4b90ae59d63a134f32abf220a6995265f","head":{"label":"MyonKeminta:misono/extract-gc-from-scheduler","ref":"misono/extract-gc-from-scheduler","sha":"9acd44a4b90ae59d63a134f32abf220a6995265f","user":{"login":"MyonKeminta","id":9948422,"avatar_url":"https://avatars1.githubusercontent.com/u/9948422?v=4","gravatar_id":"","url":"https://api.github.com/users/MyonKeminta","html_url":"https://github.com/MyonKeminta","followers_url":"https://api.github.com/users/MyonKeminta/followers","following_url":"https://api.github.com/users/MyonKeminta/following{/other_user}","gists_url":"https://api.github.com/users/MyonKeminta/gists{/gist_id}","starred_url":"https://api.github.com/users/MyonKeminta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MyonKeminta/subscriptions","organizations_url":"https://api.github.com/users/MyonKeminta/orgs","repos_url":"https://api.github.com/users/MyonKeminta/repos","events_url":"https://api.github.com/users/MyonKeminta/events{/privacy}","received_events_url":"https://api.github.com/users/MyonKeminta/received_events","type":"User","site_admin":false},"repo":{"id":114436871,"name":"tikv","full_name":"MyonKeminta/tikv","owner":{"login":"MyonKeminta","id":9948422,"avatar_url":"https://avatars1.githubusercontent.com/u/9948422?v=4","gravatar_id":"","url":"https://api.github.com/users/MyonKeminta","html_url":"https://github.com/MyonKeminta","followers_url":"https://api.github.com/users/MyonKeminta/followers","following_url":"https://api.github.com/users/MyonKeminta/following{/other_user}","gists_url":"https://api.github.com/users/MyonKeminta/gists{/gist_id}","starred_url":"https://api.github.com/users/MyonKeminta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MyonKeminta/subscriptions","organizations_url":"https://api.github.com/users/MyonKeminta/orgs","repos_url":"https://api.github.com/users/MyonKeminta/repos","events_url":"https://api.github.com/users/MyonKeminta/events{/privacy}","received_events_url":"https://api.github.com/users/MyonKeminta/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MyonKeminta/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":true,"url":"https://api.github.com/repos/MyonKeminta/tikv","forks_url":"https://api.github.com/repos/MyonKeminta/tikv/forks","keys_url":"https://api.github.com/repos/MyonKeminta/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MyonKeminta/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MyonKeminta/tikv/teams","hooks_url":"https://api.github.com/repos/MyonKeminta/tikv/hooks","issue_events_url":"https://api.github.com/repos/MyonKeminta/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/MyonKeminta/tikv/events","assignees_url":"https://api.github.com/repos/MyonKeminta/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/MyonKeminta/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/MyonKeminta/tikv/tags","blobs_url":"https://api.github.com/repos/MyonKeminta/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MyonKeminta/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MyonKeminta/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/MyonKeminta/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MyonKeminta/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/MyonKeminta/tikv/languages","stargazers_url":"https://api.github.com/repos/MyonKeminta/tikv/stargazers","contributors_url":"https://api.github.com/repos/MyonKeminta/tikv/contributors","subscribers_url":"https://api.github.com/repos/MyonKeminta/tikv/subscribers","subscription_url":"https://api.github.com/repos/MyonKeminta/tikv/subscription","commits_url":"https://api.github.com/repos/MyonKeminta/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/MyonKeminta/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/MyonKeminta/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/MyonKeminta/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/MyonKeminta/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/MyonKeminta/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MyonKeminta/tikv/merges","archive_url":"https://api.github.com/repos/MyonKeminta/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MyonKeminta/tikv/downloads","issues_url":"https://api.github.com/repos/MyonKeminta/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/MyonKeminta/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/MyonKeminta/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/MyonKeminta/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MyonKeminta/tikv/labels{/name}","releases_url":"https://api.github.com/repos/MyonKeminta/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/MyonKeminta/tikv/deployments","created_at":"2017-12-16T05:40:14Z","updated_at":"2018-05-18T06:24:54Z","pushed_at":"2018-05-30T08:46:42Z","git_url":"git://github.com/MyonKeminta/tikv.git","ssh_url":"git@github.com:MyonKeminta/tikv.git","clone_url":"https://github.com/MyonKeminta/tikv.git","svn_url":"https://github.com/MyonKeminta/tikv","homepage":"https://pingcap.com","size":14126,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"97951ea26b90e670a0155a97b799f4e1f1be704a","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","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://avatars3.githubusercontent.com/u/11855343?v=4","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":"2018-05-30T08:13:30Z","pushed_at":"2018-05-30T09:04:44Z","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":"https://pingcap.com","size":13680,"stargazers_count":3201,"watchers_count":3201,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":406,"mirror_url":null,"archived":false,"open_issues_count":220,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":406,"open_issues":220,"watchers":3201,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/3119"},"html":{"href":"https://github.com/pingcap/tikv/pull/3119"},"issue":{"href":"https://api.github.com/repos/pingcap/tikv/issues/3119"},"comments":{"href":"https://api.github.com/repos/pingcap/tikv/issues/3119/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/3119/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/3119/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tikv/statuses/9acd44a4b90ae59d63a134f32abf220a6995265f"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"MyonKeminta"}}