mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 15:57:24 +08:00
able to read chan and write chan
This commit is contained in:
38
weed/messaging/broker/consistent_distribution.go
Normal file
38
weed/messaging/broker/consistent_distribution.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package broker
|
||||
|
||||
import (
|
||||
"github.com/cespare/xxhash"
|
||||
"github.com/buraksezer/consistent"
|
||||
)
|
||||
|
||||
type Member string
|
||||
|
||||
func (m Member) String() string {
|
||||
return string(m)
|
||||
}
|
||||
|
||||
type hasher struct{}
|
||||
|
||||
func (h hasher) Sum64(data []byte) uint64 {
|
||||
return xxhash.Sum64(data)
|
||||
}
|
||||
|
||||
func PickMember(members []string, key []byte) string {
|
||||
cfg := consistent.Config{
|
||||
PartitionCount: 9791,
|
||||
ReplicationFactor: 2,
|
||||
Load: 1.25,
|
||||
Hasher: hasher{},
|
||||
}
|
||||
|
||||
cmembers := []consistent.Member{}
|
||||
for _, m := range members {
|
||||
cmembers = append(cmembers, Member(m))
|
||||
}
|
||||
|
||||
c := consistent.New(cmembers, cfg)
|
||||
|
||||
m := c.LocateKey(key)
|
||||
|
||||
return m.String()
|
||||
}
|
Reference in New Issue
Block a user