本文整理汇总了Golang中github.com/coreos/torus.Ring类的典型用法代码示例。如果您正苦于以下问题:Golang Ring类的具体用法?Golang Ring怎么用?Golang Ring使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ring类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SetRing
func (c *etcdCtx) SetRing(ring torus.Ring) error {
oldr, etcdver, err := c.getRing()
if err != nil {
return err
}
if oldr.Version() != ring.Version()-1 {
return torus.ErrNonSequentialRing
}
b, err := ring.Marshal()
if err != nil {
return err
}
key := MkKey("meta", "the-one-ring")
txn := c.etcd.Client.Txn(c.getContext()).If(
etcdv3.Compare(etcdv3.Version(key), "=", etcdver),
).Then(
etcdv3.OpPut(key, string(b)),
)
resp, err := txn.Commit()
if err != nil {
return err
}
if resp.Succeeded {
return nil
}
return torus.ErrAgain
}
开发者ID:coreos,项目名称:torus,代码行数:27,代码来源:etcd.go
示例2: watchRing
func (e *Etcd) watchRing(r torus.Ring) {
ctx, cancel := context.WithCancel(e.getContext())
defer cancel()
wch := e.Client.Watch(ctx, MkKey("meta", "the-one-ring"))
for resp := range wch {
if err := resp.Err(); err != nil {
clog.Errorf("error watching ring: %s", err)
return
}
for _, ev := range resp.Events {
newRing, err := ring.Unmarshal(ev.Kv.Value)
if err != nil {
clog.Debugf("corrupted ring: %#v", ev.Kv.Value)
clog.Errorf("Failed to unmarshal ring: %s", err)
clog.Error("corrupted ring? Continuing with current ring")
continue
}
clog.Infof("got new ring")
if r.Version() == newRing.Version() {
clog.Warningf("Same ring version: %d", r.Version())
}
e.mut.RLock()
for _, x := range e.ringListeners {
x <- newRing
}
r = newRing
e.mut.RUnlock()
}
}
}
开发者ID:coreos,项目名称:torus,代码行数:32,代码来源:ring_watch.go
示例3: setRing
func setRing(cfg torus.Config, r torus.Ring) error {
client, err := etcdv3.New(etcdv3.Config{Endpoints: []string{cfg.MetadataAddress}, TLS: cfg.TLS})
if err != nil {
return err
}
defer client.Close()
resp, err := client.Get(context.Background(), MkKey("meta", "the-one-ring"))
if err != nil {
return err
}
if len(resp.Kvs) == 0 {
return torus.ErrNoGlobalMetadata
}
oldr, err := ring.Unmarshal(resp.Kvs[0].Value)
if err != nil {
return err
}
if oldr.Version() != r.Version()-1 {
return torus.ErrNonSequentialRing
}
b, err := r.Marshal()
if err != nil {
return err
}
_, err = client.Put(context.Background(), MkKey("meta", "the-one-ring"), string(b))
return err
}
开发者ID:coreos,项目名称:torus,代码行数:28,代码来源:global_funcs.go
示例4: 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
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:17,代码来源:ringtool.go
示例5: SetRing
func (s *Server) SetRing(ring torus.Ring) error {
s.mut.Lock()
defer s.mut.Unlock()
if ring.Version()-1 != s.ring.Version() {
return torus.ErrNonSequentialRing
}
s.ring = ring
for _, c := range s.ringListeners {
c <- s.ring
}
return nil
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:12,代码来源:temp.go
示例6: 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
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:45,代码来源:ringtool.go
注:本文中的github.com/coreos/torus.Ring类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论