Skip to content

Commit

Permalink
store: more clean ups, restore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing committed Dec 23, 2015
1 parent f45c0ed commit 01f4579
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
8 changes: 0 additions & 8 deletions store/hbase/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions store/localstore/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
Expand Down Expand Up @@ -221,13 +230,29 @@ 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)
err = txn.Delete(encodeInt(2))
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) {
Expand Down
8 changes: 0 additions & 8 deletions store/localstore/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01f4579

Please sign in to comment.