本文整理汇总了Golang中github.com/kandoo/beehive/Godeps/_workspace/src/github.com/golang/glog.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: applyConfChange
func (g *group) applyConfChange(e raftpb.Entry) error {
var cc raftpb.ConfChange
pbutil.MustUnmarshal(&cc, e.Data)
glog.V(2).Infof("%v applies conf change %v: %#v", g, e.Index, cc)
if len(cc.Context) == 0 {
g.stateMachine.ApplyConfChange(cc, GroupNode{})
return nil
}
if id, req, err := g.node.decReq(cc.Context); err == nil {
if gn, ok := req.Data.(GroupNode); ok {
res := Response{ID: id}
res.Err = g.stateMachine.ApplyConfChange(cc, gn)
g.node.line.call(res)
return nil
}
}
var gn GroupNode
if err := bhgob.Decode(&gn, cc.Context); err != nil {
glog.Fatalf("%v cannot decode config change: %v", g, err)
}
if gn.Node != cc.NodeID {
glog.Fatalf("invalid config change: %v != %v", gn.Node, cc.NodeID)
}
g.stateMachine.ApplyConfChange(cc, gn)
return nil
}
示例2: handleUnicastMsg
func (q *qee) handleUnicastMsg(mh msgAndHandler) {
glog.V(2).Infof("unicast msg: %v", mh.msg)
b, ok := q.beeByID(mh.msg.To())
if !ok {
info, err := q.hive.registry.bee(mh.msg.To())
if err != nil {
glog.Errorf("cannot find bee %v", mh.msg.To())
}
if q.isLocalBee(info) {
glog.Fatalf("%v cannot find local bee %v", q, mh.msg.To())
}
if b, ok = q.beeByID(info.ID); !ok {
if b, err = q.newProxyBee(info); err != nil {
glog.Errorf("%v cannnot find remote bee %v", q, mh.msg.To())
return
}
}
}
if mh.handler == nil && !b.detached && !b.proxy {
glog.Fatalf("handler is nil for message %v", mh.msg)
}
b.enqueMsg(mh)
}
示例3: hiveIDFromPeers
func hiveIDFromPeers(addr string, paddrs []string) uint64 {
if len(paddrs) == 0 {
return 1
}
ch := make(chan uint64, len(paddrs))
for _, paddr := range paddrs {
glog.Infof("requesting hive ID from %v", paddr)
go func(paddr string) {
c, err := newRPCClient(paddr)
if err != nil {
glog.Error(err)
return
}
defer c.stop()
id, err := c.sendCmd(cmd{Data: cmdNewHiveID{}})
if err != nil {
glog.Error(err)
return
}
if id == Nil {
glog.Fatalf("invalid ID from peer")
}
_, err = c.sendCmd(cmd{
Data: cmdAddHive{
Hive: HiveInfo{
ID: id.(uint64),
Addr: addr,
},
},
})
if err != nil {
glog.Error(err)
return
}
ch <- id.(uint64)
}(paddr)
select {
case id := <-ch:
return id
case <-time.After(1 * time.Second):
glog.Infof("cannot get id from %v", paddr)
continue
}
}
glog.Fatalf("cannot get a new hive ID from peers")
return 1
}
示例4: saveMeta
func saveMeta(m hiveMeta, cfg HiveConfig) {
metafile := path.Join(cfg.StatePath, "meta")
f, err := os.OpenFile(metafile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700)
if err != nil {
glog.Fatalf("cannot open meta file: %v", err)
}
enc := gob.NewEncoder(f)
if err := enc.Encode(&m); err != nil {
glog.Fatalf("cannot encode meta: %v", err)
}
f.Close()
}
示例5: ApplyConfChange
func (b *bee) ApplyConfChange(cc raftpb.ConfChange, gn raft.GroupNode) error {
if gn.Data == nil {
return nil
}
b.Lock()
defer b.Unlock()
col := b.beeColony
bid := gn.Data.(uint64)
switch cc.Type {
case raftpb.ConfChangeAddNode:
if col.Contains(bid) {
return ErrDuplicateBee
}
col.AddFollower(bid)
case raftpb.ConfChangeRemoveNode:
if !col.Contains(bid) {
return ErrNoSuchBee
}
if bid == b.beeID {
// TODO(soheil): should we stop the bee here?
glog.Fatalf("bee is alive but removed from raft")
}
if col.Leader == bid {
// TODO(soheil): should we launch a goroutine to campaign here?
col.Leader = 0
} else {
col.DelFollower(bid)
}
}
b.beeColony = col
return nil
}
示例6: StartDetached
func (b *bee) StartDetached(h DetachedHandler) uint64 {
d, err := b.qee.processCmd(cmdStartDetached{Handler: h})
if err != nil {
glog.Fatalf("Cannot start a detached bee: %v", err)
}
return d.(uint64)
}
示例7: meta
func meta(cfg HiveConfig) hiveMeta {
m := hiveMeta{}
var dec *gob.Decoder
metapath := path.Join(cfg.StatePath, "meta")
f, err := os.Open(metapath)
if err != nil {
// TODO(soheil): We should also update our peer addresses when we have an
// existing meta.
m.Peers = peersInfo(cfg.PeerAddrs)
m.Hive.Addr = cfg.Addr
if len(cfg.PeerAddrs) == 0 {
// The initial ID is 1. There is no raft node up yet to allocate an ID. So
// we must do this when the hive starts.
m.Hive.ID = 1
goto save
}
m.Hive.ID = hiveIDFromPeers(cfg.Addr, cfg.PeerAddrs)
goto save
}
dec = gob.NewDecoder(f)
if err = dec.Decode(&m); err != nil {
glog.Fatalf("Cannot decode meta: %v", err)
}
m.Hive.Addr = cfg.Addr
f.Close()
save:
saveMeta(m, cfg)
return m
}
示例8: ApplyConfChange
func (r *registry) ApplyConfChange(cc raftpb.ConfChange, gn raft.GroupNode) (
err error) {
r.m.Lock()
defer r.m.Unlock()
glog.V(2).Infof("%v applies conf change %#v for %v", r, cc, gn.Node)
switch cc.Type {
case raftpb.ConfChangeAddNode:
if gn.Node != cc.NodeID {
glog.Fatalf("invalid data in the config change: %v != %v", gn.Node,
cc.NodeID)
}
if gn.Data != nil {
hi := HiveInfo{
ID: gn.Node,
Addr: gn.Data.(string),
}
r.addHive(hi)
glog.V(2).Infof("%v adds hive %[email protected]%v", r, hi.ID, hi.Addr)
}
case raftpb.ConfChangeRemoveNode:
r.delHive(cc.NodeID)
glog.V(2).Infof("%v deletes hive %v", r, cc.NodeID)
}
return nil
}
示例9: addFlowEntriesForPath
func addFlowEntriesForPath(sub bh.AppCellKey, path nom.Path,
flows []nom.FlowEntry, ctx bh.RcvContext) {
fs := make([]flowAndStatus, 0, len(flows))
path.ID = strconv.FormatUint(reservePathID(ctx), 16)
for i := range flows {
flows[i].ID = path.ID
fs = append(fs, flowAndStatus{Flow: flows[i]})
}
pf := pathAndFlows{
Subscriber: sub,
Path: path,
Flows: fs,
Timestamp: time.Now(),
}
d := ctx.Dict(dictPath)
if err := d.Put(path.ID, pf); err != nil {
glog.Fatalf("error in storing path entry: %v", err)
}
ack := centralizedAppCellKey(ctx.App())
for _, f := range flows {
addf := nom.AddFlowEntry{
Flow: f,
Subscriber: ack,
}
ctx.Emit(addf)
}
}
示例10: Start
func (h *hive) Start() error {
h.status = hiveStarted
h.registerSignals()
h.startRaftNode()
if err := h.listen(); err != nil {
glog.Errorf("%v cannot start listener: %v", h, err)
h.Stop()
return err
}
if err := h.raftBarrier(); err != nil {
glog.Fatalf("error when joining the cluster: %v", err)
}
glog.V(2).Infof("%v is in sync with the cluster", h)
h.startQees()
h.reloadState()
glog.V(2).Infof("%v starts message loop", h)
dataCh := h.dataCh.out()
for h.status == hiveStarted {
select {
case m := <-dataCh:
h.handleMsg(m.msg)
case cmd := <-h.ctrlCh:
h.handleCmd(cmd)
}
}
return nil
}
示例11: mustFindBee
func (r *registry) mustFindBee(id uint64) BeeInfo {
info, ok := r.Bees[id]
if !ok {
glog.Fatalf("cannot find bee %v", id)
}
return info
}
示例12: MustEncode
// MustEncode encodes the hive into bytes.
func (i GroupNode) MustEncode() []byte {
b, err := bhgob.Encode(i)
if err != nil {
glog.Fatalf("error in encoding peer: %v", err)
}
return b
}
示例13: beeForCells
func (r *registry) beeForCells(app string, cells MappedCells) (info BeeInfo,
hasAll bool, err error) {
r.m.RLock()
defer r.m.RUnlock()
hasAll = true
for _, k := range cells {
col, ok := r.Store.colony(app, k)
if !ok {
hasAll = false
continue
}
if info.ID == 0 {
info = r.Bees[col.Leader]
if info.ID != col.Leader {
glog.Fatalf("bee %b has an invalid info %#v", col.Leader, info)
}
} else if info.ID != col.Leader {
// Incosistencies should be handled by consensus.
hasAll = false
}
if !hasAll {
return info, hasAll, nil
}
}
if info.ID == 0 {
return info, hasAll, ErrNoSuchBee
}
return info, hasAll, nil
}
示例14: parseBeeID
func parseBeeID(str string) uint64 {
id, err := strconv.ParseUint(str, 10, 64)
if err != nil {
glog.Fatalf("error in parsing id: %v", err)
}
return id
}
示例15: followerHandlers
func (b *bee) followerHandlers() (func(mhs []msgAndHandler),
func(cc cmdAndChannel)) {
c := b.colony()
if c.Leader == b.ID() {
glog.Fatalf("%v is the leader", b)
}
_, err := b.hive.registry.bee(c.Leader)
if err != nil {
glog.Fatalf("%v cannot find leader %v", b, c.Leader)
}
mfn, _ := b.proxyHandlers(c.Leader)
return mfn, b.handleCmdLocal
}