本文整理匯總了Golang中github.com/coreos/torus.Ring.GetPeers方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ring.GetPeers方法的具體用法?Golang Ring.GetPeers怎麽用?Golang Ring.GetPeers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/torus.Ring
的用法示例。
在下文中一共展示了Ring.GetPeers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: assignData
func assignData(blocks []torus.BlockRef, r torus.Ring) ClusterState {
out := make(map[string][]torus.BlockRef)
for _, p := range r.Members() {
out[p] = make([]torus.BlockRef, 0)
}
for _, b := range blocks {
peers, err := r.GetPeers(b)
if err != nil {
fmt.Fprintf(os.Stderr, "error in the ring: %s\n", err)
os.Exit(1)
}
for _, p := range peers.Peers[:peers.Replication] {
out[p] = append(out[p], b)
}
}
return out
}
示例2: Rebalance
func (c ClusterState) Rebalance(oldRing, newRing torus.Ring) (ClusterState, RebalanceStats) {
var stats RebalanceStats
out := make(map[string][]torus.BlockRef)
for _, p := range newRing.Members() {
out[p] = make([]torus.BlockRef, 0)
}
for p, l := range c {
for _, ref := range l {
newp, err := newRing.GetPeers(ref)
newpeers := newp.Peers[:newp.Replication]
if err != nil {
fmt.Fprintf(os.Stderr, "error in the new ring: %s\n", err)
os.Exit(1)
}
oldp, err := oldRing.GetPeers(ref)
oldpeers := oldp.Peers[:oldp.Replication]
if err != nil {
fmt.Fprintf(os.Stderr, "error in the old ring: %s\n", err)
os.Exit(1)
}
myIndex := oldpeers.IndexAt(p)
if newpeers.Has(p) {
out[p] = append(out[p], ref)
stats.BlocksKept++
}
diffpeers := newpeers.AndNot(oldpeers)
if myIndex >= len(diffpeers) {
// downsizing
continue
}
if myIndex == len(oldpeers)-1 && len(diffpeers) > len(oldpeers) {
for i := myIndex; i < len(diffpeers); i++ {
p := diffpeers[i]
out[p] = append(out[p], ref)
stats.BlocksSent++
}
} else {
p := diffpeers[myIndex]
out[p] = append(out[p], ref)
stats.BlocksSent++
}
}
}
return out, stats
}