mvcc: do not hash consistent index

This commit is contained in:
Xiang Li 2016-06-28 08:49:44 -07:00 committed by Gyu-Ho Lee
parent 8bbccf1047
commit 269de67bde
4 changed files with 29 additions and 14 deletions

View File

@ -55,7 +55,7 @@ const (
type Backend interface { type Backend interface {
BatchTx() BatchTx BatchTx() BatchTx
Snapshot() Snapshot Snapshot() Snapshot
Hash() (uint32, error) Hash(ignores map[IgnoreKey]struct{}) (uint32, error)
// Size returns the current size of the backend. // Size returns the current size of the backend.
Size() int64 Size() int64
Defrag() error Defrag() error
@ -144,7 +144,12 @@ func (b *backend) Snapshot() Snapshot {
return &snapshot{tx} 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)) h := crc32.New(crc32.MakeTable(crc32.Castagnoli))
b.mu.RLock() b.mu.RLock()
@ -158,8 +163,11 @@ func (b *backend) Hash() (uint32, error) {
} }
h.Write(next) h.Write(next)
b.ForEach(func(k, v []byte) error { b.ForEach(func(k, v []byte) error {
h.Write(k) bk := IgnoreKey{Bucket: string(next), Key: string(k)}
h.Write(v) if _, ok := ignores[bk]; !ok {
h.Write(k)
h.Write(v)
}
return nil return nil
}) })
} }

View File

@ -141,7 +141,7 @@ func TestBackendDefrag(t *testing.T) {
size := b.Size() size := b.Size()
// shrink and check hash // shrink and check hash
oh, err := b.Hash() oh, err := b.Hash(nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -151,7 +151,7 @@ func TestBackendDefrag(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
nh, err := b.Hash() nh, err := b.Hash(nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -320,7 +320,14 @@ func (s *store) Hash() (uint32, int64, error) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() 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 rev := s.currentRev.main
return h, rev, err return h, rev, err
} }

View File

@ -593,13 +593,13 @@ type fakeBackend struct {
tx *fakeBatchTx tx *fakeBatchTx
} }
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx } func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
func (b *fakeBackend) Hash() (uint32, error) { return 0, nil } func (b *fakeBackend) Hash(ignores map[backend.IgnoreKey]struct{}) (uint32, error) { return 0, nil }
func (b *fakeBackend) Size() int64 { return 0 } func (b *fakeBackend) Size() int64 { return 0 }
func (b *fakeBackend) Snapshot() backend.Snapshot { return nil } func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
func (b *fakeBackend) ForceCommit() {} func (b *fakeBackend) ForceCommit() {}
func (b *fakeBackend) Defrag() error { return nil } func (b *fakeBackend) Defrag() error { return nil }
func (b *fakeBackend) Close() error { return nil } func (b *fakeBackend) Close() error { return nil }
type indexGetResp struct { type indexGetResp struct {
rev revision rev revision