From f45c0ed23360a8c41210df042755ff6ee4d882b3 Mon Sep 17 00:00:00 2001 From: ngaut Date: Wed, 23 Dec 2015 11:11:07 +0800 Subject: [PATCH 1/2] kv: Remove CommittedVersion from transaction --- kv/kv.go | 3 --- store/localstore/mvcc_test.go | 25 ------------------------- 2 files changed, 28 deletions(-) diff --git a/kv/kv.go b/kv/kv.go index 68369bf1eb..0b0067a79f 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -66,9 +66,6 @@ type Transaction interface { UnionStore // Commit commits the transaction operations to KV store. Commit() error - // CommittedVersion returns the version of this committed transaction. If this - // transaction has not been committed, returns ErrNotCommitted error. - CommittedVersion() (Version, error) // Rollback undoes the transaction operations to KV store. Rollback() error // String implements fmt.Stringer interface. diff --git a/store/localstore/mvcc_test.go b/store/localstore/mvcc_test.go index 086f90ca9a..1bf290fbb0 100644 --- a/store/localstore/mvcc_test.go +++ b/store/localstore/mvcc_test.go @@ -171,8 +171,6 @@ func (t *testMvccSuite) TestSnapshotGet(c *C) { c.Assert(err, IsNil) err = tx.Commit() c.Assert(err, IsNil) - v, err := tx.CommittedVersion() - c.Assert(err, IsNil) testKey := encodeTestDataKey(1) snapshot, err := t.s.GetSnapshot(kv.MaxVersion) @@ -181,13 +179,6 @@ func (t *testMvccSuite) TestSnapshotGet(c *C) { c.Assert(err, IsNil) c.Assert(string(b), Equals, "new") - // Get last version - lastVerSnapshot, err := t.s.GetSnapshot(kv.NewVersion(v.Ver - 1)) - c.Assert(err, IsNil) - b, err = lastVerSnapshot.Get(testKey) - c.Assert(err, IsNil) - c.Assert(string(b), Equals, string(encodeInt(1))) - // Get version not exists minVerSnapshot, err := t.s.GetSnapshot(kv.MinVersion) c.Assert(err, IsNil) @@ -230,8 +221,6 @@ func (t *testMvccSuite) TestMvccSeek(c *C) { c.Assert(err, IsNil) err = txn.Commit() c.Assert(err, IsNil) - v1, err := txn.CommittedVersion() - c.Assert(err, IsNil) txn, err = t.s.Begin() c.Assert(err, IsNil) @@ -239,20 +228,6 @@ func (t *testMvccSuite) TestMvccSeek(c *C) { c.Assert(err, IsNil) err = txn.Commit() c.Assert(err, IsNil) - v2, err := txn.CommittedVersion() - c.Assert(err, IsNil) - - s = t.getSnapshot(c, v2) - k, v, err = s.mvccSeek(encodeInt(2), false) - c.Assert(err, IsNil) - c.Assert([]byte(k), BytesEquals, encodeInt(3)) - c.Assert(v, BytesEquals, encodeInt(1003)) - - s = t.getSnapshot(c, v1) - k, v, err = s.mvccSeek(encodeInt(2), false) - c.Assert(err, IsNil) - c.Assert([]byte(k), BytesEquals, encodeInt(2)) - c.Assert(v, BytesEquals, encodeInt(2)) } func (t *testMvccSuite) TestMvccSuiteGetLatest(c *C) { From 01f4579ab21e2a985ff67c6a03318b378c5e709b Mon Sep 17 00:00:00 2001 From: disksing Date: Wed, 23 Dec 2015 11:30:01 +0800 Subject: [PATCH 2/2] store: more clean ups, restore tests --- store/hbase/txn.go | 8 -------- store/localstore/mvcc_test.go | 25 +++++++++++++++++++++++++ store/localstore/txn.go | 8 -------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/store/hbase/txn.go b/store/hbase/txn.go index 4910959789..2e76fbcee9 100644 --- a/store/hbase/txn.go +++ b/store/hbase/txn.go @@ -155,14 +155,6 @@ func (txn *hbaseTxn) Commit() error { return txn.doCommit() } -func (txn *hbaseTxn) CommittedVersion() (kv.Version, error) { - // Check if this transaction is not committed. - if txn.version.Cmp(kv.MinVersion) == 0 { - return kv.MinVersion, kv.ErrNotCommitted - } - return txn.version, nil -} - func (txn *hbaseTxn) close() error { txn.UnionStore.Release() txn.valid = false diff --git a/store/localstore/mvcc_test.go b/store/localstore/mvcc_test.go index 1bf290fbb0..5ec39ce378 100644 --- a/store/localstore/mvcc_test.go +++ b/store/localstore/mvcc_test.go @@ -165,6 +165,8 @@ func (t *testMvccSuite) TestSnapshotGet(c *C) { c.Assert(err, IsNil) tx.Commit() + lastVer, err := globalVersionProvider.CurrentVersion() + c.Assert(err, IsNil) // Modify tx, _ = t.s.Begin() err = tx.Set(encodeInt(1), []byte("new")) @@ -179,6 +181,13 @@ func (t *testMvccSuite) TestSnapshotGet(c *C) { c.Assert(err, IsNil) c.Assert(string(b), Equals, "new") + // Get last version + lastVerSnapshot, err := t.s.GetSnapshot(lastVer) + c.Assert(err, IsNil) + b, err = lastVerSnapshot.Get(testKey) + c.Assert(err, IsNil) + c.Assert(string(b), Equals, string(encodeInt(1))) + // Get version not exists minVerSnapshot, err := t.s.GetSnapshot(kv.MinVersion) c.Assert(err, IsNil) @@ -221,6 +230,8 @@ func (t *testMvccSuite) TestMvccSeek(c *C) { c.Assert(err, IsNil) err = txn.Commit() c.Assert(err, IsNil) + v1, err := globalVersionProvider.CurrentVersion() + c.Assert(err, IsNil) txn, err = t.s.Begin() c.Assert(err, IsNil) @@ -228,6 +239,20 @@ func (t *testMvccSuite) TestMvccSeek(c *C) { c.Assert(err, IsNil) err = txn.Commit() c.Assert(err, IsNil) + v2, err := globalVersionProvider.CurrentVersion() + c.Assert(err, IsNil) + + s = t.getSnapshot(c, v2) + k, v, err = s.mvccSeek(encodeInt(2), false) + c.Assert(err, IsNil) + c.Assert([]byte(k), BytesEquals, encodeInt(3)) + c.Assert(v, BytesEquals, encodeInt(1003)) + + s = t.getSnapshot(c, v1) + k, v, err = s.mvccSeek(encodeInt(2), false) + c.Assert(err, IsNil) + c.Assert([]byte(k), BytesEquals, encodeInt(2)) + c.Assert(v, BytesEquals, encodeInt(2)) } func (t *testMvccSuite) TestMvccSuiteGetLatest(c *C) { diff --git a/store/localstore/txn.go b/store/localstore/txn.go index 44092f2d57..dc87e651b9 100644 --- a/store/localstore/txn.go +++ b/store/localstore/txn.go @@ -142,14 +142,6 @@ func (txn *dbTxn) Commit() error { return errors.Trace(txn.doCommit()) } -func (txn *dbTxn) CommittedVersion() (kv.Version, error) { - // Check if this transaction is not committed. - if txn.version.Cmp(kv.MinVersion) == 0 { - return kv.MinVersion, kv.ErrNotCommitted - } - return txn.version, nil -} - func (txn *dbTxn) close() error { txn.UnionStore.Release() txn.snapshotVals = nil