mvcc: Hash to return Revision

This commit is contained in:
Gyu-Ho Lee 2016-05-02 14:37:56 -07:00
parent a8139e2b0e
commit 7a6d9ea01a
3 changed files with 11 additions and 5 deletions

View File

@ -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()

View File

@ -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)
}

View File

@ -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() }