From 20bac87d6064b7d4ffbcb0e49f3703058d0ba820 Mon Sep 17 00:00:00 2001 From: dongxu Date: Tue, 22 Sep 2015 17:51:41 +0800 Subject: [PATCH] kv : Add some comments, add release interface address code review comments --- kv/kv.go | 4 +++- store/localstore/mvcc_test.go | 2 ++ store/localstore/snapshot.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kv/kv.go b/kv/kv.go index 0e3f52c08b..7c8c5c4d0d 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -129,6 +129,8 @@ type MvccSnapshot interface { // MvccIterator seeks to the key in the specific version's snapshot, if the // version doesn't exists, return the nearest(lower) version's snaphot. NewMvccIterator(k Key, ver Version) Iterator + // Release releases this snapshot. + MvccRelease() } // Snapshot defines the interface for the snapshot fetched from KV store. @@ -153,7 +155,7 @@ type Driver interface { type Storage interface { // Begin transaction Begin() (Transaction, error) - // MvccSnapshot get a snaphot that cloud read any version of data. + // MvccSnapshot get a snaphot that is able to read any version of data. GetMvccSnapshot() (MvccSnapshot, error) // Close store Close() error diff --git a/store/localstore/mvcc_test.go b/store/localstore/mvcc_test.go index f5bd55f84c..5b02b97765 100644 --- a/store/localstore/mvcc_test.go +++ b/store/localstore/mvcc_test.go @@ -154,6 +154,7 @@ func (t *testMvccSuite) TestMvccSnapshotGet(c *C) { c.Assert(err, IsNil) mvccSnapshot, err := t.s.GetMvccSnapshot() + defer mvccSnapshot.MvccRelease() b, err = mvccSnapshot.MvccGet(kv.EncodeKey(encodeInt(1)), kv.MaxVersion) c.Assert(err, IsNil) c.Assert(string(b), Equals, "new") @@ -178,6 +179,7 @@ func (t *testMvccSuite) TestMvccSnapshotScan(c *C) { c.Assert(err, IsNil) mvccSnapshot, err := t.s.GetMvccSnapshot() + defer mvccSnapshot.MvccRelease() c.Assert(err, IsNil) // iter helper function diff --git a/store/localstore/snapshot.go b/store/localstore/snapshot.go index 3f835a1f5b..37a882db5d 100644 --- a/store/localstore/snapshot.go +++ b/store/localstore/snapshot.go @@ -95,6 +95,10 @@ func (s *dbSnapshot) NewIterator(param interface{}) kv.Iterator { return newDBIter(s, k, kv.MaxVersion) } +func (s *dbSnapshot) MvccRelease() { + s.Release() +} + func (s *dbSnapshot) Release() { if s.Snapshot != nil { s.Snapshot.Release()