{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tikv/pulls/comments/84220619","pull_request_review_id":5010204,"id":84220619,"diff_hunk":"@@ -116,13 +128,115 @@ fn main() {\n             }\n         }\n         dump_range(db, from, to, limit, cf_name);\n-    }\n-    else {\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+            \"default\" => {\n+                let key_prefix = gen_key_prefix(key);\n+                dump_mvcc_default(db, key_prefix);\n+            }\n+            \"lock\" => {\n+                let key_prefix = gen_key_prefix(key);\n+                dump_mvcc_lock(db, key_prefix);\n+            }\n+            \"write\" => {\n+                let key_prefix = gen_key_prefix(key);\n+                dump_mvcc_write(db, key_prefix);\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 = \"t\".as_bytes().to_vec();\n+    let mut encoded = encode_bytes(key.as_bytes());\n+    prefix.append(&mut encoded);\n+    prefix\n+}\n+\n+fn compare_prefix(key: &[u8], prefix: &Vec<u8>) -> bool {\n+    let (pre, _) = key.split_at(prefix.len());\n+    pre == prefix.as_slice()\n+}\n+\n+fn get_default_start_ts<'a>(key: &'a [u8], prefix: &Vec<u8>) -> &'a [u8] {\n+    let (_, rest) = key.split_at(prefix.len());\n+    rest\n+}\n+\n+fn dump_mvcc_default(db: DB, key_prefix: Vec<u8>) {\n+    let mut iter = db.new_iterator(None);\n+    iter.seek(key_prefix.as_slice().into());\n+    if iter.valid() {\n+        if compare_prefix(iter.key(), &key_prefix) {\n+            println!(\"key: {:?}\", iter.key());\n+            println!(\"value: {:?}\", iter.value());\n+            println!(\"start_ts: {:?}\", get_default_start_ts(iter.key(), &key_prefix));\n+        }\n+        while iter.next() && compare_prefix(iter.key(), &key_prefix) {\n+            println!(\"key: {:?}\", iter.key());\n+            println!(\"value: {:?}\", iter.value());\n+            println!(\"start_ts: {:?}\", get_default_start_ts(iter.key(), &key_prefix));\n+        }\n+    } else {\n+        println!(\"No such record\");\n+    }\n+}\n+\n+fn dump_mvcc_lock(db: DB, key_prefix: Vec<u8>) {\n+    let mut iter = db.new_iterator(None);","path":"src/bin/tikv-ctl.rs","position":101,"original_position":101,"commit_id":"c647f164eb34c8514af0267460ffeb98a8f8f8fd","original_commit_id":"c647f164eb34c8514af0267460ffeb98a8f8f8fd","user":{"login":"disksing","id":12077877,"avatar_url":"https://avatars.githubusercontent.com/u/12077877?v=3","gravatar_id":"","url":"https://api.github.com/users/disksing","html_url":"https://github.com/disksing","followers_url":"https://api.github.com/users/disksing/followers","following_url":"https://api.github.com/users/disksing/following{/other_user}","gists_url":"https://api.github.com/users/disksing/gists{/gist_id}","starred_url":"https://api.github.com/users/disksing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/disksing/subscriptions","organizations_url":"https://api.github.com/users/disksing/orgs","repos_url":"https://api.github.com/users/disksing/repos","events_url":"https://api.github.com/users/disksing/events{/privacy}","received_events_url":"https://api.github.com/users/disksing/received_events","type":"User","site_admin":false},"body":"I think you want to use `new_iterator_cf`.","created_at":"2016-10-20T06:41:34Z","updated_at":"2016-10-20T06:48:06Z","html_url":"https://github.com/pingcap/tikv/pull/1196#discussion_r84220619","pull_request_url":"https://api.github.com/repos/pingcap/tikv/pulls/1196","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tikv/pulls/comments/84220619"},"html":{"href":"https://github.com/pingcap/tikv/pull/1196#discussion_r84220619"},"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":"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 \r\nAdd mvcc decoding support for tiki-ctl","created_at":"2016-10-20T06:31:49Z","updated_at":"2016-10-20T06:48:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cbbff641f4536bac725164519018d9e99235766c","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/c647f164eb34c8514af0267460ffeb98a8f8f8fd","head":{"label":"mrmiywj:ctl-mvcc","ref":"ctl-mvcc","sha":"c647f164eb34c8514af0267460ffeb98a8f8f8fd","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-20T06:31:09Z","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":4832,"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":"233e7486887cf2eac988e53d1b89528359388240","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-10-19T20:59:20Z","pushed_at":"2016-10-20T06:41:11Z","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":6618,"stargazers_count":1100,"watchers_count":1100,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":92,"mirror_url":null,"open_issues_count":69,"forks":92,"open_issues":69,"watchers":1100,"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/c647f164eb34c8514af0267460ffeb98a8f8f8fd"}}}}
{"actor":{"display_login":"disksing"}}