本文整理汇总了Golang中github.com/hashicorp/consul/consul/structs.MessageType函数的典型用法代码示例。如果您正苦于以下问题:Golang MessageType函数的具体用法?Golang MessageType怎么用?Golang MessageType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MessageType函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Apply
func (c *consulFSM) Apply(log *raft.Log) interface{} {
buf := log.Data
msgType := structs.MessageType(buf[0])
// Check if this message type should be ignored when unknown. This is
// used so that new commands can be added with developer control if older
// versions can safely ignore the command, or if they should crash.
ignoreUnknown := false
if msgType&structs.IgnoreUnknownTypeFlag == structs.IgnoreUnknownTypeFlag {
msgType &= ^structs.IgnoreUnknownTypeFlag
ignoreUnknown = true
}
switch msgType {
case structs.RegisterRequestType:
return c.applyRegister(buf[1:], log.Index)
case structs.DeregisterRequestType:
return c.applyDeregister(buf[1:], log.Index)
case structs.KVSRequestType:
return c.applyKVSOperation(buf[1:], log.Index)
case structs.SessionRequestType:
return c.applySessionOperation(buf[1:], log.Index)
case structs.ACLRequestType:
return c.applyACLOperation(buf[1:], log.Index)
case structs.TombstoneRequestType:
return c.applyTombstoneOperation(buf[1:], log.Index)
default:
if ignoreUnknown {
c.logger.Printf("[WARN] consul.fsm: ignoring unknown message type (%d), upgrade to newer version", msgType)
return nil
} else {
panic(fmt.Errorf("failed to apply request: %#v", buf))
}
}
}
开发者ID:eicca,项目名称:consul,代码行数:35,代码来源:fsm.go
示例2: Restore
func (c *consulFSM) Restore(old io.ReadCloser) error {
defer old.Close()
// Create a new state store
state, err := NewStateStore(c.logOutput)
if err != nil {
return err
}
c.state.Close()
c.state = state
// Create a decoder
var handle codec.MsgpackHandle
dec := codec.NewDecoder(old, &handle)
// Read in the header
var header snapshotHeader
if err := dec.Decode(&header); err != nil {
return err
}
// Populate the new state
msgType := make([]byte, 1)
for {
// Read the message type
_, err := old.Read(msgType)
if err == io.EOF {
break
} else if err != nil {
return err
}
// Decode
switch structs.MessageType(msgType[0]) {
case structs.RegisterRequestType:
var req structs.RegisterRequest
if err := dec.Decode(&req); err != nil {
return err
}
c.applyRegister(&req, header.LastIndex)
case structs.KVSRequestType:
var req structs.DirEntry
if err := dec.Decode(&req); err != nil {
return err
}
if err := c.state.KVSRestore(&req); err != nil {
return err
}
default:
return fmt.Errorf("Unrecognized msg type: %v", msgType)
}
}
return nil
}
开发者ID:rayleyva,项目名称:consul,代码行数:57,代码来源:fsm.go
示例3: Apply
func (c *consulFSM) Apply(log *raft.Log) interface{} {
buf := log.Data
switch structs.MessageType(buf[0]) {
case structs.RegisterRequestType:
return c.decodeRegister(buf[1:], log.Index)
case structs.DeregisterRequestType:
return c.applyDeregister(buf[1:], log.Index)
case structs.KVSRequestType:
return c.applyKVSOperation(buf[1:], log.Index)
default:
panic(fmt.Errorf("failed to apply request: %#v", buf))
}
}
开发者ID:rayleyva,项目名称:consul,代码行数:13,代码来源:fsm.go
示例4: handleLogCommand
func handleLogCommand(log raft.Log) {
buf := log.Data
if len(buf) > 0 {
msgType := structs.MessageType(buf[0])
switch msgType {
case structs.RegisterRequestType:
var data structs.RegisterRequest
printData(log, buf[1:], &data)
case structs.DeregisterRequestType:
var data structs.DeregisterRequest
printData(log, buf[1:], &data)
case structs.KVSRequestType:
var data structs.KVSRequest
printData(log, buf[1:], &data)
case structs.SessionRequestType:
var data structs.SessionRequest
printData(log, buf[1:], &data)
case structs.ACLRequestType:
var data structs.ACLRequest
printData(log, buf[1:], &data)
case structs.TombstoneRequestType:
var data structs.TombstoneRequest
printData(log, buf[1:], &data)
case structs.CoordinateBatchUpdateType, 134:
var data structs.Coordinates
printData(log, buf[1:], &data)
case structs.PreparedQueryRequestType:
var data structs.PreparedQueryRequest
printData(log, buf[1:], &data)
default:
kingpin.Errorf("Unknown msg type %d", msgType)
printMsgPackData(log, reflect.Indirect(reflect.ValueOf(msgType)).Type().Name(), buf[1:])
}
} else {
printJson(log, "", log.Data)
}
}
开发者ID:outbrain,项目名称:consul-raftdb-reader,代码行数:38,代码来源:main.go
示例5: Restore
func (c *consulFSM) Restore(old io.ReadCloser) error {
defer old.Close()
// Create a new state store
stateNew, err := state.NewStateStore(c.gc)
if err != nil {
return err
}
c.state = stateNew
// Set up a new restore transaction
restore := c.state.Restore()
defer restore.Abort()
// Create a decoder
dec := codec.NewDecoder(old, msgpackHandle)
// Read in the header
var header snapshotHeader
if err := dec.Decode(&header); err != nil {
return err
}
// Populate the new state
msgType := make([]byte, 1)
for {
// Read the message type
_, err := old.Read(msgType)
if err == io.EOF {
break
} else if err != nil {
return err
}
// Decode
switch structs.MessageType(msgType[0]) {
case structs.RegisterRequestType:
var req structs.RegisterRequest
if err := dec.Decode(&req); err != nil {
return err
}
if err := restore.Registration(header.LastIndex, &req); err != nil {
return err
}
case structs.KVSRequestType:
var req structs.DirEntry
if err := dec.Decode(&req); err != nil {
return err
}
if err := restore.KVS(&req); err != nil {
return err
}
case structs.TombstoneRequestType:
var req structs.DirEntry
if err := dec.Decode(&req); err != nil {
return err
}
// For historical reasons, these are serialized in the
// snapshots as KV entries. We want to keep the snapshot
// format compatible with pre-0.6 versions for now.
stone := &state.Tombstone{
Key: req.Key,
Index: req.ModifyIndex,
}
if err := restore.Tombstone(stone); err != nil {
return err
}
case structs.SessionRequestType:
var req structs.Session
if err := dec.Decode(&req); err != nil {
return err
}
if err := restore.Session(&req); err != nil {
return err
}
case structs.ACLRequestType:
var req structs.ACL
if err := dec.Decode(&req); err != nil {
return err
}
if err := restore.ACL(&req); err != nil {
return err
}
case structs.CoordinateBatchUpdateType:
var req structs.Coordinates
if err := dec.Decode(&req); err != nil {
return err
}
if err := restore.Coordinates(header.LastIndex, req); err != nil {
return err
}
case structs.PreparedQueryRequestType:
//.........这里部分代码省略.........
开发者ID:catroot,项目名称:consul,代码行数:101,代码来源:fsm.go
注:本文中的github.com/hashicorp/consul/consul/structs.MessageType函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论