{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/comments/85885637","pull_request_review_id":6572323,"id":85885637,"diff_hunk":"@@ -116,12 +131,149 @@ fn main() {\n             }\n         }\n         dump_range(db, from, to, limit, cf_name);\n+    } else if let Some(matches) = matches.subcommand_matches(\"mvcc\") {\n+        let cf_name = matches.value_of(\"cf\").unwrap_or(\"default\");\n+        let key = matches.value_of(\"key\").unwrap();\n+        println!(\"You are searching Key {}: \", key);\n+        match cf_name {\n+            CF_DEFAULT => {\n+                dump_mvcc_default(db, key);\n+            }\n+            CF_LOCK => {\n+                dump_mvcc_lock(db, key);\n+            }\n+            CF_WRITE => {\n+                dump_mvcc_write(db, key);\n+            }\n+            _ => {\n+                let _ = app.print_help();\n+            }\n+        }\n     } else {\n         let _ = app.print_help();\n     }\n \n }\n \n+fn gen_key_prefix(key: &str) -> Vec<u8> {\n+    let mut prefix = keys::DATA_PREFIX_KEY.to_vec();\n+    let mut encoded = encode_bytes(key.as_bytes());\n+    prefix.append(&mut encoded);\n+    prefix\n+}\n+\n+pub struct MVCCDefaultKV {\n+    key: Key,\n+    value: Vec<u8>,\n+}\n+\n+pub fn gen_mvcc_default_iter(db: &DB, key_prefix: &str) -> Vec<MVCCDefaultKV> {\n+    let prefix = gen_key_prefix(key_prefix);\n+    let mut iter = db.new_iterator(None);\n+    iter.seek(prefix.as_slice().into());\n+    if !iter.valid() {\n+        println!(\"No such Default record!\");\n+        return Vec::new();\n+    }\n+    iter.map(|s| {\n+            let key = &keys::origin_key(&s.0);\n+            let len = key.len();\n+            let (raw, mut ts) = key.split_at(len - number::U64_SIZE);\n+            let mut kv = MVCCDefaultKV {\n+                key: Key::from_encoded(raw.to_vec()),\n+                value: s.1,\n+            };\n+            kv.key = kv.key.append_ts(ts.decode_u64_desc().unwrap());\n+            kv\n+        })\n+        .collect()\n+}\n+\n+pub struct MVCCLockKV {\n+    key: Key,\n+    value: Lock,\n+}\n+\n+pub fn gen_mvcc_lock_iter(db: &DB, key_prefix: &str) -> Vec<MVCCLockKV> {\n+    let prefix = gen_key_prefix(key_prefix);\n+    let mut iter = db.new_iterator_cf(CF_LOCK, None).unwrap();\n+    iter.seek(prefix.as_slice().into());\n+    if !iter.valid() {\n+        println!(\"No such Lock record!\");\n+        return Vec::new();\n+    }\n+    iter.map(|s| {\n+            let key = s.0;\n+            MVCCLockKV {\n+                key: Key::from_raw(keys::origin_key(&key)),\n+                value: Lock::parse(s.1.clone().as_mut_slice()).unwrap(),\n+            }\n+        })\n+        .collect()\n+}\n+\n+pub struct MVCCWriteKV {\n+    key: Key,\n+    value: Write,\n+}\n+\n+pub fn gen_mvcc_write_iter(db: &DB, key_prefix: &str) -> Vec<MVCCWriteKV> {","path":"src/bin/tikv-ctl.rs","position":132,"original_position":132,"commit_id":"7fc18ffa7a8453ee3e3f3d8e8c7ae0ded2fc2802","original_commit_id":"7fc18ffa7a8453ee3e3f3d8e8c7ae0ded2fc2802","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":"`gen_mvcc_default_iter`, `gen_mvcc_lock_iter` and `gen_mvcc_write_iter` are almost same, I think they can be merged as one.","created_at":"2016-11-01T07:36:24Z","updated_at":"2016-11-01T07:39:56Z","html_url":"https://github.com/pingcap/tikv/pull/1196#discussion_r85885637","pull_request_url":"https://api.github.com/repos/pingcap/tikv/pulls/1196","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments/85885637"},"html":{"href":"https://github.com/pingcap/tikv/pull/1196#discussion_r85885637"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/1196"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/1196","id":90140618,"html_url":"https://github.com/pingcap/tikv/pull/1196","diff_url":"https://github.com/pingcap/tikv/pull/1196.diff","patch_url":"https://github.com/pingcap/tikv/pull/1196.patch","issue_url":"https://api.github.com/repos/pingcap/tikv/issues/1196","number":1196,"state":"open","locked":false,"title":"[DNM] add tikv-ctl support for MVCC","user":{"login":"mrmiywj","id":7459820,"avatar_url":"https://avatars.githubusercontent.com/u/7459820?v=3","gravatar_id":"","url":"https://api.github.com/users/mrmiywj","html_url":"https://github.com/mrmiywj","followers_url":"https://api.github.com/users/mrmiywj/followers","following_url":"https://api.github.com/users/mrmiywj/following{/other_user}","gists_url":"https://api.github.com/users/mrmiywj/gists{/gist_id}","starred_url":"https://api.github.com/users/mrmiywj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrmiywj/subscriptions","organizations_url":"https://api.github.com/users/mrmiywj/orgs","repos_url":"https://api.github.com/users/mrmiywj/repos","events_url":"https://api.github.com/users/mrmiywj/events{/privacy}","received_events_url":"https://api.github.com/users/mrmiywj/received_events","type":"User","site_admin":false},"body":"# 1077\n\nAdd mvcc decoding support for tiki-ctl\n","created_at":"2016-10-20T06:31:49Z","updated_at":"2016-11-01T07:39:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"814ad6458a7476e83c9955d57f423346127ffe08","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tikv/pulls/1196/commits","review_comments_url":"https://api.github.com/repos/pingcap/tikv/pulls/1196/comments","review_comment_url":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tikv/issues/1196/comments","statuses_url":"https://api.github.com/repos/pingcap/tikv/statuses/7fc18ffa7a8453ee3e3f3d8e8c7ae0ded2fc2802","head":{"label":"mrmiywj:ctl-mvcc","ref":"ctl-mvcc","sha":"7fc18ffa7a8453ee3e3f3d8e8c7ae0ded2fc2802","user":{"login":"mrmiywj","id":7459820,"avatar_url":"https://avatars.githubusercontent.com/u/7459820?v=3","gravatar_id":"","url":"https://api.github.com/users/mrmiywj","html_url":"https://github.com/mrmiywj","followers_url":"https://api.github.com/users/mrmiywj/followers","following_url":"https://api.github.com/users/mrmiywj/following{/other_user}","gists_url":"https://api.github.com/users/mrmiywj/gists{/gist_id}","starred_url":"https://api.github.com/users/mrmiywj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrmiywj/subscriptions","organizations_url":"https://api.github.com/users/mrmiywj/orgs","repos_url":"https://api.github.com/users/mrmiywj/repos","events_url":"https://api.github.com/users/mrmiywj/events{/privacy}","received_events_url":"https://api.github.com/users/mrmiywj/received_events","type":"User","site_admin":false},"repo":{"id":70453970,"name":"tikv","full_name":"mrmiywj/tikv","owner":{"login":"mrmiywj","id":7459820,"avatar_url":"https://avatars.githubusercontent.com/u/7459820?v=3","gravatar_id":"","url":"https://api.github.com/users/mrmiywj","html_url":"https://github.com/mrmiywj","followers_url":"https://api.github.com/users/mrmiywj/followers","following_url":"https://api.github.com/users/mrmiywj/following{/other_user}","gists_url":"https://api.github.com/users/mrmiywj/gists{/gist_id}","starred_url":"https://api.github.com/users/mrmiywj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrmiywj/subscriptions","organizations_url":"https://api.github.com/users/mrmiywj/orgs","repos_url":"https://api.github.com/users/mrmiywj/repos","events_url":"https://api.github.com/users/mrmiywj/events{/privacy}","received_events_url":"https://api.github.com/users/mrmiywj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mrmiywj/tikv","description":"Distributed transactional key value database powered by Rust and Raft","fork":true,"url":"https://api.github.com/repos/mrmiywj/tikv","forks_url":"https://api.github.com/repos/mrmiywj/tikv/forks","keys_url":"https://api.github.com/repos/mrmiywj/tikv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrmiywj/tikv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrmiywj/tikv/teams","hooks_url":"https://api.github.com/repos/mrmiywj/tikv/hooks","issue_events_url":"https://api.github.com/repos/mrmiywj/tikv/issues/events{/number}","events_url":"https://api.github.com/repos/mrmiywj/tikv/events","assignees_url":"https://api.github.com/repos/mrmiywj/tikv/assignees{/user}","branches_url":"https://api.github.com/repos/mrmiywj/tikv/branches{/branch}","tags_url":"https://api.github.com/repos/mrmiywj/tikv/tags","blobs_url":"https://api.github.com/repos/mrmiywj/tikv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrmiywj/tikv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrmiywj/tikv/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrmiywj/tikv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrmiywj/tikv/statuses/{sha}","languages_url":"https://api.github.com/repos/mrmiywj/tikv/languages","stargazers_url":"https://api.github.com/repos/mrmiywj/tikv/stargazers","contributors_url":"https://api.github.com/repos/mrmiywj/tikv/contributors","subscribers_url":"https://api.github.com/repos/mrmiywj/tikv/subscribers","subscription_url":"https://api.github.com/repos/mrmiywj/tikv/subscription","commits_url":"https://api.github.com/repos/mrmiywj/tikv/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrmiywj/tikv/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrmiywj/tikv/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrmiywj/tikv/issues/comments{/number}","contents_url":"https://api.github.com/repos/mrmiywj/tikv/contents/{+path}","compare_url":"https://api.github.com/repos/mrmiywj/tikv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrmiywj/tikv/merges","archive_url":"https://api.github.com/repos/mrmiywj/tikv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrmiywj/tikv/downloads","issues_url":"https://api.github.com/repos/mrmiywj/tikv/issues{/number}","pulls_url":"https://api.github.com/repos/mrmiywj/tikv/pulls{/number}","milestones_url":"https://api.github.com/repos/mrmiywj/tikv/milestones{/number}","notifications_url":"https://api.github.com/repos/mrmiywj/tikv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrmiywj/tikv/labels{/name}","releases_url":"https://api.github.com/repos/mrmiywj/tikv/releases{/id}","deployments_url":"https://api.github.com/repos/mrmiywj/tikv/deployments","created_at":"2016-10-10T05:11:56Z","updated_at":"2016-10-10T05:11:59Z","pushed_at":"2016-10-31T14:59:13Z","git_url":"git://github.com/mrmiywj/tikv.git","ssh_url":"git@github.com:mrmiywj/tikv.git","clone_url":"https://github.com/mrmiywj/tikv.git","svn_url":"https://github.com/mrmiywj/tikv","homepage":"","size":5038,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"pingcap:master","ref":"master","sha":"854ef53cc9657ce53157830f0c5d5f8dfc9e1fbf","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-11-01T02:43:55Z","pushed_at":"2016-11-01T07:12:42Z","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":7027,"stargazers_count":1150,"watchers_count":1150,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":72,"forks":94,"open_issues":72,"watchers":1150,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/1196"},"html":{"href":"https://github.com/pingcap/tikv/pull/1196"},"issue":{"href":"https://api.github.com/repos/pingcap/tikv/issues/1196"},"comments":{"href":"https://api.github.com/repos/pingcap/tikv/issues/1196/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/1196/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/1196/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tikv/statuses/7fc18ffa7a8453ee3e3f3d8e8c7ae0ded2fc2802"}}}}
{"actor":{"display_login":"BusyJay"}}