{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/39943540","id":39943540,"diff_hunk":"@@ -0,0 +1,136 @@\n+package localstore\n+\n+import (\n+\t\"bytes\"\n+\n+\t\"github.com/ngaut/log\"\n+\t. \"github.com/pingcap/check\"\n+\t\"github.com/pingcap/tidb/kv\"\n+\t\"github.com/pingcap/tidb/store/localstore/goleveldb\"\n+)\n+\n+var _ = Suite(&testMvccSuite{})\n+\n+type testMvccSuite struct {\n+\ts kv.Storage\n+}\n+\n+func createMemStore() kv.Storage {\n+\tpath := \"memory:\"\n+\td := Driver{\n+\t\tgoleveldb.MemoryDriver{},\n+\t}\n+\tstore, err := d.Open(path)\n+\tif err != nil {\n+\t\tpanic(err)\n+\t}\n+\treturn store\n+}\n+\n+func (t *testMvccSuite) addDirtyData() {\n+\tengineDB := t.s.(*dbStore).db\n+\tb := engineDB.NewBatch()\n+\tb.Put([]byte(\"\\xf0dirty\"), []byte(\"testvalue\"))\n+\tb.Put([]byte(\"\\x00dirty\"), []byte(\"testvalue\"))\n+\tengineDB.Commit(b)\n+}\n+\n+func (t *testMvccSuite) TestMvccEncode(c *C) {\n+\tencodedKey1 := MvccEncodeVersionKey([]byte(\"A\"), kv.Version{1})\n+\tencodedKey2 := MvccEncodeVersionKey([]byte(\"A\"), kv.Version{2})\n+\t// A_2\n+\t// A_1\n+\tc.Assert(encodedKey1.Cmp(encodedKey2), Greater, 0)\n+\n+\t// decode test\n+\tkey, ver, err := MvccDecode(encodedKey1)\n+\tc.Assert(err, IsNil)\n+\tc.Assert(bytes.Compare(key, []byte(\"A\")), Equals, 0)\n+\tc.Assert(ver.Ver, Equals, uint64(1))\n+}\n+\n+func (t *testMvccSuite) scanRawEngine(c *C, f func([]byte, []byte)) {\n+\t// scan raw db\n+\ts, err := t.s.(*dbStore).db.GetSnapshot()\n+\tc.Assert(err, IsNil)\n+\tit := s.NewIterator(nil)\n+\tfor it.Next() {\n+\t\tf(it.Key(), it.Value())\n+\t}\n+}\n+\n+func (t *testMvccSuite) SetUpTest(c *C) {\n+\t// create new store\n+\tt.s = createMemStore()\n+\tt.addDirtyData()\n+\t// insert test data\n+\ttxn, err := t.s.Begin()\n+\tc.Assert(err, IsNil)\n+\tfor i := 0; i < 5; i++ {\n+\t\tval := encodeInt(i)\n+\t\terr := txn.Set(val, val)\n+\t\tc.Assert(err, IsNil)\n+\t}\n+\ttxn.Commit()\n+}\n+\n+func (t *testMvccSuite) TestMvccGet(c *C) {\n+\ttxn, err := t.s.Begin()\n+\tc.Assert(err, IsNil)\n+\tk := encodeInt(1)\n+\t_, err = txn.Get(k)\n+\tc.Assert(err, IsNil)\n+\t// no such key\n+\tk = encodeInt(1024)\n+\t_, err = txn.Get(k)\n+\tc.Assert(err, NotNil)\n+\ttxn.Commit()\n+}\n+\n+func (t *testMvccSuite) TestMvccPutAndDel(c *C) {\n+\ttxn, err := t.s.Begin()\n+\tc.Assert(err, IsNil)\n+\t// remove 0,1,2\n+\tfor i := 0; i < 3; i++ {\n+\t\tval := encodeInt(i)\n+\t\terr := txn.Delete(val)\n+\t\tc.Assert(err, IsNil)\n+\t}\n+\ttxn.Commit()\n+\n+\ttxn, _ = t.s.Begin()\n+\t_, err = txn.Get(encodeInt(0))\n+\tc.Assert(err, NotNil)\n+\tv, err := txn.Get(encodeInt(4))\n+\tc.Assert(err, IsNil)\n+\tc.Assert(len(v), Greater, 0)\n+\ttxn.Commit()\n+\n+\tcnt := 0\n+\tt.scanRawEngine(c, func(k, v []byte) {\n+\t\tcnt++\n+\t})\n+\ttxn, _ = t.s.Begin()\n+\ttxn.Set(encodeInt(0), []byte(\"v\"))\n+\tv, err = txn.Get(encodeInt(0))","path":"store/localstore/mvcc_test.go","position":114,"original_position":115,"commit_id":"27e80f38d4d9009657e80558541fb4c0aef47ad5","original_commit_id":"975a746902741db1ef8143f73646f2bbf7b645bd","user":{"login":"c4pt0r","id":773853,"avatar_url":"https://avatars.githubusercontent.com/u/773853?v=3","gravatar_id":"","url":"https://api.github.com/users/c4pt0r","html_url":"https://github.com/c4pt0r","followers_url":"https://api.github.com/users/c4pt0r/followers","following_url":"https://api.github.com/users/c4pt0r/following{/other_user}","gists_url":"https://api.github.com/users/c4pt0r/gists{/gist_id}","starred_url":"https://api.github.com/users/c4pt0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c4pt0r/subscriptions","organizations_url":"https://api.github.com/users/c4pt0r/orgs","repos_url":"https://api.github.com/users/c4pt0r/repos","events_url":"https://api.github.com/users/c4pt0r/events{/privacy}","received_events_url":"https://api.github.com/users/c4pt0r/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2015-09-21T06:25:22Z","updated_at":"2015-09-21T06:25:22Z","html_url":"https://github.com/pingcap/tidb/pull/209#discussion_r39943540","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/209","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/39943540"},"html":{"href":"https://github.com/pingcap/tidb/pull/209#discussion_r39943540"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/209"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/209","id":45509978,"html_url":"https://github.com/pingcap/tidb/pull/209","diff_url":"https://github.com/pingcap/tidb/pull/209.diff","patch_url":"https://github.com/pingcap/tidb/pull/209.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/209","number":209,"state":"open","locked":false,"title":"first MVCC support","user":{"login":"c4pt0r","id":773853,"avatar_url":"https://avatars.githubusercontent.com/u/773853?v=3","gravatar_id":"","url":"https://api.github.com/users/c4pt0r","html_url":"https://github.com/c4pt0r","followers_url":"https://api.github.com/users/c4pt0r/followers","following_url":"https://api.github.com/users/c4pt0r/following{/other_user}","gists_url":"https://api.github.com/users/c4pt0r/gists{/gist_id}","starred_url":"https://api.github.com/users/c4pt0r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c4pt0r/subscriptions","organizations_url":"https://api.github.com/users/c4pt0r/orgs","repos_url":"https://api.github.com/users/c4pt0r/repos","events_url":"https://api.github.com/users/c4pt0r/events{/privacy}","received_events_url":"https://api.github.com/users/c4pt0r/received_events","type":"User","site_admin":false},"body":"1. Add MVCC to original interfaces (alway handles newest version).\r\n2. Add some tests.  \r\n\r\nTODO (I'll put them in next commits, to avoid a big PR):\r\n1. Get/Scan specific version.\r\n2. Compact\r\n\r\nthe structure of MVCC kv:\r\n\r\nKey1 => 3 (newest version)\r\nKey1_3 => ... (value of this version)\r\nKey1_2 => ... (value of this version)\r\nKey2 => 2\r\nKey2_2 =>  Tombstone (this key is deleted in the version)\r\nKey2_1 => ...\r\nKey3 => 4\r\nKey3_4 => ...\r\n\r\n","created_at":"2015-09-21T02:10:29Z","updated_at":"2015-09-21T06:25:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bebd6f6e8eabeea5c3432438be1de176bfdd2fa5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/209/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/209/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/209/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/27e80f38d4d9009657e80558541fb4c0aef47ad5","head":{"label":"pingcap:c4pt0r/MVCC-support","ref":"c4pt0r/MVCC-support","sha":"27e80f38d4d9009657e80558541fb4c0aef47ad5","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":41986369,"name":"tidb","full_name":"pingcap/tidb","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/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-09-21T02:59:48Z","pushed_at":"2015-09-21T06:24:38Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":9213,"stargazers_count":2238,"watchers_count":2238,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":188,"mirror_url":null,"open_issues_count":23,"forks":188,"open_issues":23,"watchers":2238,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"6b7c3bf183ef26b63f8839d6803fcbddb469879a","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":41986369,"name":"tidb","full_name":"pingcap/tidb","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/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-09-21T02:59:48Z","pushed_at":"2015-09-21T06:24:38Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":9213,"stargazers_count":2238,"watchers_count":2238,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":188,"mirror_url":null,"open_issues_count":23,"forks":188,"open_issues":23,"watchers":2238,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/209"},"html":{"href":"https://github.com/pingcap/tidb/pull/209"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/209"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/209/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/209/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/209/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/27e80f38d4d9009657e80558541fb4c0aef47ad5"}}}}