瀏覽代碼

raft: remove entry type

Blake Mizerany 11 年之前
父節點
當前提交
8d9b7b1680
共有 5 個文件被更改,包括 31 次插入59 次删除
  1. 0 8
      raft/log.go
  2. 1 1
      raft/raft.go
  3. 6 6
      raft/raft_test.go
  4. 24 43
      raft/raftpb/raft.pb.go
  5. 0 1
      raft/raftpb/raft.proto

+ 0 - 8
raft/log.go

@@ -6,14 +6,6 @@ import (
 	pb "github.com/coreos/etcd/raft/raftpb"
 )
 
-const (
-	Normal int64 = iota
-
-	ClusterInit
-	AddNode
-	RemoveNode
-)
-
 const (
 	defaultCompactThreshold = 10000
 )

+ 1 - 1
raft/raft.go

@@ -305,7 +305,7 @@ func (r *raft) becomeLeader() {
 	r.tick = r.tickElection
 	r.lead = r.id
 	r.state = stateLeader
-	r.appendEntry(pb.Entry{Type: Normal, Data: nil})
+	r.appendEntry(pb.Entry{Data: nil})
 }
 
 func (r *raft) ReadMessages() []pb.Message {

+ 6 - 6
raft/raft_test.go

@@ -223,7 +223,7 @@ func TestDuelingCandidates(t *testing.T) {
 	nt.recover()
 	nt.send(pb.Message{From: 2, To: 2, Type: msgHup})
 
-	wlog := &raftLog{ents: []pb.Entry{{}, pb.Entry{Type: Normal, Data: nil, Term: 1, Index: 1}}, committed: 1}
+	wlog := &raftLog{ents: []pb.Entry{{}, pb.Entry{Data: nil, Term: 1, Index: 1}}, committed: 1}
 	tests := []struct {
 		sm      *raft
 		state   stateType
@@ -275,7 +275,7 @@ func TestCandidateConcede(t *testing.T) {
 	if g := a.Term; g != 1 {
 		t.Errorf("term = %d, want %d", g, 1)
 	}
-	wantLog := ltoa(&raftLog{ents: []pb.Entry{{}, {Type: Normal, Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}}, committed: 2})
+	wantLog := ltoa(&raftLog{ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}}, committed: 2})
 	for i, p := range tt.peers {
 		if sm, ok := p.(*raft); ok {
 			l := ltoa(sm.raftLog)
@@ -309,8 +309,8 @@ func TestOldMessages(t *testing.T) {
 
 	l := &raftLog{
 		ents: []pb.Entry{
-			{}, {Type: Normal, Data: nil, Term: 1, Index: 1},
-			{Type: Normal, Data: nil, Term: 2, Index: 2}, {Type: Normal, Data: nil, Term: 3, Index: 3},
+			{}, {Data: nil, Term: 1, Index: 1},
+			{Data: nil, Term: 2, Index: 2}, {Data: nil, Term: 3, Index: 3},
 		},
 		committed: 3,
 	}
@@ -364,7 +364,7 @@ func TestProposal(t *testing.T) {
 
 		wantLog := newLog()
 		if tt.success {
-			wantLog = &raftLog{ents: []pb.Entry{{}, {Type: Normal, Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}}, committed: 2}
+			wantLog = &raftLog{ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}}, committed: 2}
 		}
 		base := ltoa(wantLog)
 		for i, p := range tt.peers {
@@ -398,7 +398,7 @@ func TestProposalByProxy(t *testing.T) {
 		// propose via follower
 		tt.send(pb.Message{From: 1, To: 1, Type: msgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
 
-		wantLog := &raftLog{ents: []pb.Entry{{}, {Type: Normal, Data: nil, Term: 1, Index: 1}, {Term: 1, Data: data, Index: 2}}, committed: 2}
+		wantLog := &raftLog{ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Data: data, Index: 2}}, committed: 2}
 		base := ltoa(wantLog)
 		for i, p := range tt.peers {
 			if sm, ok := p.(*raft); ok {

+ 24 - 43
raft/raftpb/raft.pb.go

@@ -18,16 +18,17 @@
 package raftpb
 
 import proto "code.google.com/p/gogoprotobuf/proto"
+import json "encoding/json"
 import math "math"
 
 // discarding unused import gogoproto "code.google.com/p/gogoprotobuf/gogoproto/gogo.pb"
 
 import io "io"
-import fmt "fmt"
 import code_google_com_p_gogoprotobuf_proto "code.google.com/p/gogoprotobuf/proto"
 
-// Reference imports to suppress errors if they are not otherwise used.
+// Reference proto, json, and math imports to suppress error if they are not otherwise used.
 var _ = proto.Marshal
+var _ = &json.SyntaxError{}
 var _ = math.Inf
 
 type Info struct {
@@ -40,7 +41,6 @@ func (m *Info) String() string { return proto.CompactTextString(m) }
 func (*Info) ProtoMessage()    {}
 
 type Entry struct {
-	Type             int64  `protobuf:"varint,1,req,name=type" json:"type"`
 	Term             int64  `protobuf:"varint,2,req,name=term" json:"term"`
 	Index            int64  `protobuf:"varint,3,req,name=index" json:"index"`
 	Data             []byte `protobuf:"bytes,4,opt,name=data" json:"data"`
@@ -115,7 +115,7 @@ func (m *Info) Unmarshal(data []byte) error {
 		switch fieldNum {
 		case 1:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -170,24 +170,9 @@ func (m *Entry) Unmarshal(data []byte) error {
 		fieldNum := int32(wire >> 3)
 		wireType := int(wire & 0x7)
 		switch fieldNum {
-		case 1:
-			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
-			}
-			for shift := uint(0); ; shift += 7 {
-				if index >= l {
-					return io.ErrUnexpectedEOF
-				}
-				b := data[index]
-				index++
-				m.Type |= (int64(b) & 0x7F) << shift
-				if b < 0x80 {
-					break
-				}
-			}
 		case 2:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -202,7 +187,7 @@ func (m *Entry) Unmarshal(data []byte) error {
 			}
 		case 3:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -217,7 +202,7 @@ func (m *Entry) Unmarshal(data []byte) error {
 			}
 		case 4:
 			if wireType != 2 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
@@ -281,7 +266,7 @@ func (m *Snapshot) Unmarshal(data []byte) error {
 		switch fieldNum {
 		case 1:
 			if wireType != 2 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			var byteLen int
 			for shift := uint(0); ; shift += 7 {
@@ -303,7 +288,7 @@ func (m *Snapshot) Unmarshal(data []byte) error {
 			index = postIndex
 		case 2:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			var v int64
 			for shift := uint(0); ; shift += 7 {
@@ -320,7 +305,7 @@ func (m *Snapshot) Unmarshal(data []byte) error {
 			m.Nodes = append(m.Nodes, v)
 		case 3:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -335,7 +320,7 @@ func (m *Snapshot) Unmarshal(data []byte) error {
 			}
 		case 4:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -392,7 +377,7 @@ func (m *Message) Unmarshal(data []byte) error {
 		switch fieldNum {
 		case 1:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -407,7 +392,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 2:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field To", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -422,7 +407,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 3:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field From", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -437,7 +422,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 4:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -452,7 +437,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 5:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field LogTerm", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -467,7 +452,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 6:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -482,7 +467,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 7:
 			if wireType != 2 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			var msglen int
 			for shift := uint(0); ; shift += 7 {
@@ -505,7 +490,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			index = postIndex
 		case 8:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -520,7 +505,7 @@ func (m *Message) Unmarshal(data []byte) error {
 			}
 		case 9:
 			if wireType != 2 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			var msglen int
 			for shift := uint(0); ; shift += 7 {
@@ -586,7 +571,7 @@ func (m *State) Unmarshal(data []byte) error {
 		switch fieldNum {
 		case 1:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -601,7 +586,7 @@ func (m *State) Unmarshal(data []byte) error {
 			}
 		case 2:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -616,7 +601,7 @@ func (m *State) Unmarshal(data []byte) error {
 			}
 		case 3:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -631,7 +616,7 @@ func (m *State) Unmarshal(data []byte) error {
 			}
 		case 4:
 			if wireType != 0 {
-				return fmt.Errorf("proto: wrong wireType = %d for field LastIndex", wireType)
+				return code_google_com_p_gogoprotobuf_proto.ErrWrongType
 			}
 			for shift := uint(0); ; shift += 7 {
 				if index >= l {
@@ -679,7 +664,6 @@ func (m *Info) Size() (n int) {
 func (m *Entry) Size() (n int) {
 	var l int
 	_ = l
-	n += 1 + sovRaft(uint64(m.Type))
 	n += 1 + sovRaft(uint64(m.Term))
 	n += 1 + sovRaft(uint64(m.Index))
 	l = len(m.Data)
@@ -793,9 +777,6 @@ func (m *Entry) MarshalTo(data []byte) (n int, err error) {
 	_ = i
 	var l int
 	_ = l
-	data[i] = 0x8
-	i++
-	i = encodeVarintRaft(data, i, uint64(m.Type))
 	data[i] = 0x10
 	i++
 	i = encodeVarintRaft(data, i, uint64(m.Term))

+ 0 - 1
raft/raftpb/raft.proto

@@ -12,7 +12,6 @@ message Info {
 }
 
 message Entry {
-	required int64 type  = 1 [(gogoproto.nullable) = false];
 	required int64 term  = 2 [(gogoproto.nullable) = false];
 	required int64 index = 3 [(gogoproto.nullable) = false];
 	optional bytes data  = 4 [(gogoproto.nullable) = false];