(es raftpb.Entry, pending map[uint64]bool, isZero bool)
| 23 | ) |
| 24 | |
| 25 | func printEntry(es raftpb.Entry, pending map[uint64]bool, isZero bool) { |
| 26 | var buf bytes.Buffer |
| 27 | defer func() { |
| 28 | fmt.Printf("%s\n", buf.Bytes()) |
| 29 | }() |
| 30 | |
| 31 | var key uint64 |
| 32 | if len(es.Data) >= 8 { |
| 33 | key = binary.BigEndian.Uint64(es.Data[:8]) |
| 34 | } |
| 35 | fmt.Fprintf(&buf, "%d . %d . %v . %-6s . %8d .", es.Term, es.Index, es.Type, |
| 36 | humanize.Bytes(uint64(es.Size())), key) |
| 37 | if es.Type == raftpb.EntryConfChange { |
| 38 | var cc raftpb.ConfChange |
| 39 | if err := cc.Unmarshal(es.Data); err != nil { |
| 40 | fmt.Fprintf(&buf, " [ConfChange unmarshal error: %v]", err) |
| 41 | return |
| 42 | } |
| 43 | fmt.Fprintf(&buf, " Type: %s . NodeID: %#x .", cc.Type, cc.NodeID) |
| 44 | if len(cc.Context) > 0 { |
| 45 | var rc pb.RaftContext |
| 46 | if err := proto.Unmarshal(cc.Context, &rc); err == nil { |
| 47 | fmt.Fprintf(&buf, " RaftContext: %s", rc.String()) |
| 48 | } |
| 49 | } |
| 50 | return |
| 51 | } |
| 52 | if len(es.Data) == 0 { |
| 53 | return |
| 54 | } |
| 55 | var err error |
| 56 | if isZero { |
| 57 | var zpr pb.ZeroProposal |
| 58 | if err = proto.Unmarshal(es.Data[8:], &zpr); err == nil { |
| 59 | printZeroProposal(&buf, &zpr) |
| 60 | return |
| 61 | } |
| 62 | } else { |
| 63 | var pr pb.Proposal |
| 64 | if err = proto.Unmarshal(es.Data[8:], &pr); err == nil { |
| 65 | printAlphaProposal(&buf, &pr, pending) |
| 66 | return |
| 67 | } |
| 68 | } |
| 69 | fmt.Fprintf(&buf, " Unable to parse Proposal: %v", err) |
| 70 | } |
| 71 | |
| 72 | type RaftStore interface { |
| 73 | raft.Storage |
no test coverage detected