本文整理匯總了Golang中github.com/cockroachdb/cockroach/roachpb.RaftCommand類的典型用法代碼示例。如果您正苦於以下問題:Golang RaftCommand類的具體用法?Golang RaftCommand怎麽用?Golang RaftCommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RaftCommand類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printRaftLogEntry
func printRaftLogEntry(kv engine.MVCCKeyValue) (bool, error) {
var meta engine.MVCCMetadata
if err := meta.Unmarshal(kv.Value); err != nil {
return false, err
}
value := roachpb.Value{
RawBytes: meta.RawBytes,
}
var ent raftpb.Entry
if err := value.GetProto(&ent); err != nil {
return false, err
}
if len(ent.Data) > 0 {
_, cmdData := storage.DecodeRaftCommand(ent.Data)
var cmd roachpb.RaftCommand
if err := cmd.Unmarshal(cmdData); err != nil {
return false, err
}
ent.Data = nil
fmt.Printf("%s\n", &ent)
fmt.Printf("%s\n", &cmd)
} else {
fmt.Printf("%s: EMPTY\n", &ent)
}
return false, nil
}
示例2: tryRaftLogEntry
func tryRaftLogEntry(kv engine.MVCCKeyValue) (string, error) {
var ent raftpb.Entry
if err := maybeUnmarshalInline(kv.Value, &ent); err != nil {
return "", err
}
if ent.Type == raftpb.EntryNormal {
if len(ent.Data) > 0 {
_, cmdData := storage.DecodeRaftCommand(ent.Data)
var cmd roachpb.RaftCommand
if err := cmd.Unmarshal(cmdData); err != nil {
return "", err
}
ent.Data = nil
return fmt.Sprintf("%s by %v\n%s\n%s\n", &ent, cmd.OriginReplica, &cmd.Cmd, &cmd), nil
}
return fmt.Sprintf("%s: EMPTY\n", &ent), nil
} else if ent.Type == raftpb.EntryConfChange {
var cc raftpb.ConfChange
if err := cc.Unmarshal(ent.Data); err != nil {
return "", err
}
var ctx storage.ConfChangeContext
if err := ctx.Unmarshal(cc.Context); err != nil {
return "", err
}
var cmd roachpb.RaftCommand
if err := cmd.Unmarshal(ctx.Payload); err != nil {
return "", err
}
ent.Data = nil
return fmt.Sprintf("%s\n%s\n", &ent, &cmd), nil
}
return "", fmt.Errorf("Unknown log entry type: %s\n", &ent)
}