You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
616 B
Go
40 lines
616 B
Go
4 years ago
|
package internal
|
||
4 years ago
|
|
||
|
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
|
||
|
}
|