Browse Source

mvcc: Hash to return Revision

Gyu-Ho Lee 9 years ago
parent
commit
7a6d9ea01a
3 changed files with 11 additions and 5 deletions
  1. 2 2
      mvcc/kv.go
  2. 1 1
      mvcc/kv_test.go
  3. 8 2
      mvcc/kvstore.go

+ 2 - 2
mvcc/kv.go

@@ -70,9 +70,9 @@ type KV interface {
 	// Compact frees all superseded keys with revisions less than rev.
 	Compact(rev int64) (<-chan struct{}, error)
 
-	// Hash retrieves the hash of KV state.
+	// Hash retrieves the hash of KV state and revision.
 	// This method is designed for consistency checking purpose.
-	Hash() (uint32, error)
+	Hash() (hash uint32, revision int64, err error)
 
 	// Commit commits txns into the underlying backend.
 	Commit()

+ 1 - 1
mvcc/kv_test.go

@@ -620,7 +620,7 @@ func TestKVHash(t *testing.T) {
 		kv := NewStore(b, &lease.FakeLessor{}, nil)
 		kv.Put([]byte("foo0"), []byte("bar0"), lease.NoLease)
 		kv.Put([]byte("foo1"), []byte("bar0"), lease.NoLease)
-		hashes[i], err = kv.Hash()
+		hashes[i], _, err = kv.Hash()
 		if err != nil {
 			t.Fatalf("failed to get hash: %v", err)
 		}

+ 8 - 2
mvcc/kvstore.go

@@ -293,9 +293,15 @@ func (s *store) Compact(rev int64) (<-chan struct{}, error) {
 	return ch, nil
 }
 
-func (s *store) Hash() (uint32, error) {
+func (s *store) Hash() (uint32, int64, error) {
 	s.b.ForceCommit()
-	return s.b.Hash()
+
+	s.mu.Lock()
+	defer s.mu.Unlock()
+
+	h, err := s.b.Hash()
+	rev := s.currentRev.main
+	return h, rev, err
 }
 
 func (s *store) Commit() { s.b.ForceCommit() }