mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
mvcc: do not hash consistent index
This commit is contained in:
parent
8bbccf1047
commit
269de67bde
@ -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 {
|
||||||
|
bk := IgnoreKey{Bucket: string(next), Key: string(k)}
|
||||||
|
if _, ok := ignores[bk]; !ok {
|
||||||
h.Write(k)
|
h.Write(k)
|
||||||
h.Write(v)
|
h.Write(v)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@ type fakeBackend struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user