示例#1
0
文件: log.go 项目: diffoperator/etcd
func toEntry5(ent4 *etcd4pb.LogEntry, raftMap map[string]uint64) (*raftpb.Entry, error) {
	cmd4, err := NewCommand4(ent4.GetCommandName(), ent4.GetCommand(), raftMap)
	if err != nil {
		return nil, err
	}

	data, err := cmd4.Data5()
	if err != nil {
		return nil, err
	}

	ent5 := raftpb.Entry{
		Term:  ent4.GetTerm(),
		Index: ent4.GetIndex(),
		Type:  cmd4.Type5(),
		Data:  data,
	}

	log.Printf("%d: %s -> %s", ent5.Index, ent4.GetCommandName(), ent5.Type)

	return &ent5, nil
}
示例#2
0
文件: log.go 项目: diffoperator/etcd
// DecodeNextEntry4 unmarshals a v0.4 log entry from a reader. Returns the
// number of bytes read and any error that occurs.
func DecodeNextEntry4(r io.Reader) (*etcd4pb.LogEntry, int, error) {
	var length int
	_, err := fmt.Fscanf(r, "%8x\n", &length)
	if err != nil {
		return nil, -1, err
	}

	data := make([]byte, length)
	if _, err = io.ReadFull(r, data); err != nil {
		return nil, -1, err
	}

	ent4 := new(etcd4pb.LogEntry)
	if err = ent4.Unmarshal(data); err != nil {
		return nil, -1, err
	}

	// add width of scanner token to length
	length = length + 8 + 1

	return ent4, length, nil
}
示例#3
0
func toEntry2(ent4 *etcd4pb.LogEntry, raftMap map[string]uint64) (*raftpb.Entry, error) {
	cmd4, err := NewCommand4(ent4.GetCommandName(), ent4.GetCommand(), raftMap)
	if err != nil {
		return nil, err
	}

	data, err := cmd4.Data2()
	if err != nil {
		return nil, err
	}

	ent2 := raftpb.Entry{
		Term:  ent4.GetTerm() + termOffset4to2,
		Index: ent4.GetIndex(),
		Type:  cmd4.Type2(),
		Data:  data,
	}

	return &ent2, nil
}