Browse Source

Merge pull request #5794 from xiang90/fix_c

mvcc: do not hash consistent index
Xiang Li 9 years ago
parent
commit
38035c8c13
4 changed files with 29 additions and 14 deletions
  1. 12 4
      mvcc/backend/backend.go
  2. 2 2
      mvcc/backend/backend_test.go
  3. 8 1
      mvcc/kvstore.go
  4. 7 7
      mvcc/kvstore_test.go

+ 12 - 4
mvcc/backend/backend.go

@@ -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)
-				h.Write(v)
+				bk := IgnoreKey{Bucket: string(next), Key: string(k)}
+				if _, ok := ignores[bk]; !ok {
+					h.Write(k)
+					h.Write(v)
+				}
 				return nil
 				return nil
 			})
 			})
 		}
 		}

+ 2 - 2
mvcc/backend/backend_test.go

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

+ 8 - 1
mvcc/kvstore.go

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

+ 7 - 7
mvcc/kvstore_test.go

@@ -593,13 +593,13 @@ type fakeBackend struct {
 	tx *fakeBatchTx
 	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 {
 type indexGetResp struct {
 	rev     revision
 	rev     revision