mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
40 lines
616 B
Go
40 lines
616 B
Go
package internal
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"zero/core/hash"
|
|
)
|
|
|
|
type HashChange struct {
|
|
id int64
|
|
oldHash *hash.ConsistentHash
|
|
newHash *hash.ConsistentHash
|
|
}
|
|
|
|
func NewHashChange(oldHash, newHash *hash.ConsistentHash) HashChange {
|
|
return HashChange{
|
|
id: rand.Int63(),
|
|
oldHash: oldHash,
|
|
newHash: newHash,
|
|
}
|
|
}
|
|
|
|
func (hc HashChange) GetId() int64 {
|
|
return hc.id
|
|
}
|
|
|
|
func (hc HashChange) ShallEvict(key interface{}) bool {
|
|
oldTarget, oldOk := hc.oldHash.Get(key)
|
|
if !oldOk {
|
|
return false
|
|
}
|
|
|
|
newTarget, newOk := hc.newHash.Get(key)
|
|
if !newOk {
|
|
return false
|
|
}
|
|
|
|
return oldTarget != newTarget
|
|
}
|