diff --git a/mvcc/backend/backend.go b/mvcc/backend/backend.go index c9b41307b..51b89021d 100644 --- a/mvcc/backend/backend.go +++ b/mvcc/backend/backend.go @@ -55,7 +55,7 @@ const ( type Backend interface { BatchTx() BatchTx Snapshot() Snapshot - Hash() (uint32, error) + Hash(ignores map[IgnoreKey]struct{}) (uint32, error) // Size returns the current size of the backend. Size() int64 Defrag() error @@ -144,7 +144,12 @@ func (b *backend) Snapshot() Snapshot { return &snapshot{tx} } -func (b *backend) Hash() (uint32, error) { +type IgnoreKey struct { + Bucket string + Key string +} + +func (b *backend) Hash(ignores map[IgnoreKey]struct{}) (uint32, error) { h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) b.mu.RLock() @@ -158,8 +163,11 @@ func (b *backend) Hash() (uint32, error) { } h.Write(next) b.ForEach(func(k, v []byte) error { - h.Write(k) - h.Write(v) + bk := IgnoreKey{Bucket: string(next), Key: string(k)} + if _, ok := ignores[bk]; !ok { + h.Write(k) + h.Write(v) + } return nil }) } diff --git a/mvcc/backend/backend_test.go b/mvcc/backend/backend_test.go index 769c95f2c..06d908db5 100644 --- a/mvcc/backend/backend_test.go +++ b/mvcc/backend/backend_test.go @@ -141,7 +141,7 @@ func TestBackendDefrag(t *testing.T) { size := b.Size() // shrink and check hash - oh, err := b.Hash() + oh, err := b.Hash(nil) if err != nil { t.Fatal(err) } @@ -151,7 +151,7 @@ func TestBackendDefrag(t *testing.T) { t.Fatal(err) } - nh, err := b.Hash() + nh, err := b.Hash(nil) if err != nil { t.Fatal(err) } diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index 4cc52d2b6..d1c71fd7c 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -320,7 +320,14 @@ func (s *store) Hash() (uint32, int64, error) { s.mu.Lock() defer s.mu.Unlock() - h, err := s.b.Hash() + // ignore hash consistent index field for now. + // consistent index might be changed due to v2 internal sync, which + // is not controllable by the user. + ignores := make(map[backend.IgnoreKey]struct{}) + bk := backend.IgnoreKey{Bucket: string(metaBucketName), Key: string(consistentIndexKeyName)} + ignores[bk] = struct{}{} + + h, err := s.b.Hash(ignores) rev := s.currentRev.main return h, rev, err } diff --git a/mvcc/kvstore_test.go b/mvcc/kvstore_test.go index 814e989a2..c401354fe 100644 --- a/mvcc/kvstore_test.go +++ b/mvcc/kvstore_test.go @@ -593,13 +593,13 @@ type fakeBackend struct { tx *fakeBatchTx } -func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx } -func (b *fakeBackend) Hash() (uint32, error) { return 0, nil } -func (b *fakeBackend) Size() int64 { return 0 } -func (b *fakeBackend) Snapshot() backend.Snapshot { return nil } -func (b *fakeBackend) ForceCommit() {} -func (b *fakeBackend) Defrag() error { return nil } -func (b *fakeBackend) Close() error { return nil } +func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx } +func (b *fakeBackend) Hash(ignores map[backend.IgnoreKey]struct{}) (uint32, error) { return 0, nil } +func (b *fakeBackend) Size() int64 { return 0 } +func (b *fakeBackend) Snapshot() backend.Snapshot { return nil } +func (b *fakeBackend) ForceCommit() {} +func (b *fakeBackend) Defrag() error { return nil } +func (b *fakeBackend) Close() error { return nil } type indexGetResp struct { rev revision