From 1d5d2e372667fed497976fe5a7bbd6b4c89f07f3 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Tue, 23 Sep 2014 10:17:53 -0700 Subject: [PATCH] *: Id -> ID for protobuf types We use ID instead of Id in this project based on golang conventions. --- etcdserver/etcdhttp/http.go | 2 +- etcdserver/etcdhttp/http_test.go | 28 +++++----- etcdserver/etcdserverpb/etcdserver.pb.go | 38 +++++++------- etcdserver/etcdserverpb/etcdserver.proto | 32 ++++++------ etcdserver/server.go | 10 ++-- etcdserver/server_test.go | 66 ++++++++++++------------ raft/raftpb/raft.pb.go | 8 +-- raft/raftpb/raft.proto | 2 +- wal/wal.go | 4 +- wal/wal_test.go | 12 ++--- 10 files changed, 101 insertions(+), 101 deletions(-) diff --git a/etcdserver/etcdhttp/http.go b/etcdserver/etcdhttp/http.go index db9e4249f..bd6546c5f 100644 --- a/etcdserver/etcdhttp/http.go +++ b/etcdserver/etcdhttp/http.go @@ -257,7 +257,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) { } rr := etcdserverpb.Request{ - Id: id, + ID: id, Method: r.Method, Path: p, Val: r.FormValue("value"), diff --git a/etcdserver/etcdhttp/http_test.go b/etcdserver/etcdhttp/http_test.go index 7e60e53bb..a972e98b4 100644 --- a/etcdserver/etcdhttp/http_test.go +++ b/etcdserver/etcdhttp/http_test.go @@ -222,7 +222,7 @@ func TestGoodParseRequest(t *testing.T) { // good prefix, all other values default mustNewRequest(t, "foo"), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "GET", Path: "/foo", }, @@ -235,7 +235,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"value": []string{"some_value"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", Val: "some_value", Path: "/foo", @@ -249,7 +249,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"prevIndex": []string{"98765"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevIndex: 98765, Path: "/foo", @@ -263,7 +263,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"recursive": []string{"true"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", Recursive: true, Path: "/foo", @@ -277,7 +277,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"sorted": []string{"true"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", Sorted: true, Path: "/foo", @@ -287,7 +287,7 @@ func TestGoodParseRequest(t *testing.T) { // wait specified mustNewRequest(t, "foo?wait=true"), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "GET", Wait: true, Path: "/foo", @@ -297,7 +297,7 @@ func TestGoodParseRequest(t *testing.T) { // empty TTL specified mustNewRequest(t, "foo?ttl="), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "GET", Path: "/foo", Expiration: 0, @@ -307,7 +307,7 @@ func TestGoodParseRequest(t *testing.T) { // dir specified mustNewRequest(t, "foo?dir=true"), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "GET", Dir: true, Path: "/foo", @@ -317,7 +317,7 @@ func TestGoodParseRequest(t *testing.T) { // dir specified negatively mustNewRequest(t, "foo?dir=false"), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "GET", Dir: false, Path: "/foo", @@ -331,7 +331,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"prevExist": []string{"true"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevExist: boolp(true), Path: "/foo", @@ -345,7 +345,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{"prevExist": []string{"false"}}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevExist: boolp(false), Path: "/foo", @@ -363,7 +363,7 @@ func TestGoodParseRequest(t *testing.T) { }, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevExist: boolp(true), PrevValue: "previous value", @@ -379,7 +379,7 @@ func TestGoodParseRequest(t *testing.T) { url.Values{}, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevValue: "woof", Path: "/foo", @@ -395,7 +395,7 @@ func TestGoodParseRequest(t *testing.T) { }, ), etcdserverpb.Request{ - Id: 1234, + ID: 1234, Method: "PUT", PrevValue: "miaow", Path: "/foo", diff --git a/etcdserver/etcdserverpb/etcdserver.pb.go b/etcdserver/etcdserverpb/etcdserver.pb.go index e81b21508..a6720af13 100644 --- a/etcdserver/etcdserverpb/etcdserver.pb.go +++ b/etcdserver/etcdserverpb/etcdserver.pb.go @@ -28,22 +28,22 @@ var _ = &json.SyntaxError{} var _ = math.Inf type Request struct { - Id int64 `protobuf:"varint,1,req,name=id" json:"id"` - Method string `protobuf:"bytes,2,req,name=method" json:"method"` - Path string `protobuf:"bytes,3,req,name=path" json:"path"` - Val string `protobuf:"bytes,4,req,name=val" json:"val"` - Dir bool `protobuf:"varint,5,req,name=dir" json:"dir"` - PrevValue string `protobuf:"bytes,6,req,name=prevValue" json:"prevValue"` - PrevIndex uint64 `protobuf:"varint,7,req,name=prevIndex" json:"prevIndex"` - PrevExist *bool `protobuf:"varint,8,req,name=prevExist" json:"prevExist,omitempty"` - Expiration int64 `protobuf:"varint,9,req,name=expiration" json:"expiration"` - Wait bool `protobuf:"varint,10,req,name=wait" json:"wait"` - Since uint64 `protobuf:"varint,11,req,name=since" json:"since"` - Recursive bool `protobuf:"varint,12,req,name=recursive" json:"recursive"` - Sorted bool `protobuf:"varint,13,req,name=sorted" json:"sorted"` - Quorum bool `protobuf:"varint,14,req,name=quorum" json:"quorum"` - Time int64 `protobuf:"varint,15,req,name=time" json:"time"` - Stream bool `protobuf:"varint,16,req,name=stream" json:"stream"` + ID int64 `protobuf:"varint,1,req" json:"ID"` + Method string `protobuf:"bytes,2,req" json:"Method"` + Path string `protobuf:"bytes,3,req" json:"Path"` + Val string `protobuf:"bytes,4,req" json:"Val"` + Dir bool `protobuf:"varint,5,req" json:"Dir"` + PrevValue string `protobuf:"bytes,6,req" json:"PrevValue"` + PrevIndex uint64 `protobuf:"varint,7,req" json:"PrevIndex"` + PrevExist *bool `protobuf:"varint,8,req" json:"PrevExist,omitempty"` + Expiration int64 `protobuf:"varint,9,req" json:"Expiration"` + Wait bool `protobuf:"varint,10,req" json:"Wait"` + Since uint64 `protobuf:"varint,11,req" json:"Since"` + Recursive bool `protobuf:"varint,12,req" json:"Recursive"` + Sorted bool `protobuf:"varint,13,req" json:"Sorted"` + Quorum bool `protobuf:"varint,14,req" json:"Quorum"` + Time int64 `protobuf:"varint,15,req" json:"Time"` + Stream bool `protobuf:"varint,16,req" json:"Stream"` XXX_unrecognized []byte `json:"-"` } @@ -82,7 +82,7 @@ func (m *Request) Unmarshal(data []byte) error { } b := data[index] index++ - m.Id |= (int64(b) & 0x7F) << shift + m.ID |= (int64(b) & 0x7F) << shift if b < 0x80 { break } @@ -381,7 +381,7 @@ func (m *Request) Unmarshal(data []byte) error { func (m *Request) Size() (n int) { var l int _ = l - n += 1 + sovEtcdserver(uint64(m.Id)) + n += 1 + sovEtcdserver(uint64(m.ID)) l = len(m.Method) n += 1 + l + sovEtcdserver(uint64(l)) l = len(m.Path) @@ -439,7 +439,7 @@ func (m *Request) MarshalTo(data []byte) (n int, err error) { _ = l data[i] = 0x8 i++ - i = encodeVarintEtcdserver(data, i, uint64(m.Id)) + i = encodeVarintEtcdserver(data, i, uint64(m.ID)) data[i] = 0x12 i++ i = encodeVarintEtcdserver(data, i, uint64(len(m.Method))) diff --git a/etcdserver/etcdserverpb/etcdserver.proto b/etcdserver/etcdserverpb/etcdserver.proto index a0b98bb0f..e29e86dca 100644 --- a/etcdserver/etcdserverpb/etcdserver.proto +++ b/etcdserver/etcdserverpb/etcdserver.proto @@ -8,20 +8,20 @@ option (gogoproto.unmarshaler_all) = true; option (gogoproto.goproto_getters_all) = false; message Request { - required int64 id = 1 [(gogoproto.nullable) = false]; - required string method = 2 [(gogoproto.nullable) = false]; - required string path = 3 [(gogoproto.nullable) = false]; - required string val = 4 [(gogoproto.nullable) = false]; - required bool dir = 5 [(gogoproto.nullable) = false]; - required string prevValue = 6 [(gogoproto.nullable) = false]; - required uint64 prevIndex = 7 [(gogoproto.nullable) = false]; - required bool prevExist = 8 [(gogoproto.nullable) = true]; - required int64 expiration = 9 [(gogoproto.nullable) = false]; - required bool wait = 10 [(gogoproto.nullable) = false]; - required uint64 since = 11 [(gogoproto.nullable) = false]; - required bool recursive = 12 [(gogoproto.nullable) = false]; - required bool sorted = 13 [(gogoproto.nullable) = false]; - required bool quorum = 14 [(gogoproto.nullable) = false]; - required int64 time = 15 [(gogoproto.nullable) = false]; - required bool stream = 16 [(gogoproto.nullable) = false]; + required int64 ID = 1 [(gogoproto.nullable) = false]; + required string Method = 2 [(gogoproto.nullable) = false]; + required string Path = 3 [(gogoproto.nullable) = false]; + required string Val = 4 [(gogoproto.nullable) = false]; + required bool Dir = 5 [(gogoproto.nullable) = false]; + required string PrevValue = 6 [(gogoproto.nullable) = false]; + required uint64 PrevIndex = 7 [(gogoproto.nullable) = false]; + required bool PrevExist = 8 [(gogoproto.nullable) = true]; + required int64 Expiration = 9 [(gogoproto.nullable) = false]; + required bool Wait = 10 [(gogoproto.nullable) = false]; + required uint64 Since = 11 [(gogoproto.nullable) = false]; + required bool Recursive = 12 [(gogoproto.nullable) = false]; + required bool Sorted = 13 [(gogoproto.nullable) = false]; + required bool Quorum = 14 [(gogoproto.nullable) = false]; + required int64 Time = 15 [(gogoproto.nullable) = false]; + required bool Stream = 16 [(gogoproto.nullable) = false]; } diff --git a/etcdserver/server.go b/etcdserver/server.go index 8a53a317f..4bfa438e9 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -141,7 +141,7 @@ func (s *EtcdServer) run() { if err := r.Unmarshal(e.Data); err != nil { panic("TODO: this is bad, what do we do about it?") } - s.w.Trigger(r.Id, s.apply(r)) + s.w.Trigger(r.ID, s.apply(r)) case raftpb.EntryConfChange: var cc raftpb.ConfChange if err := cc.Unmarshal(e.Data); err != nil { @@ -202,7 +202,7 @@ func (s *EtcdServer) Stop() { // respective operation. Do will block until an action is performed or there is // an error. func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) { - if r.Id == 0 { + if r.ID == 0 { panic("r.Id cannot be 0") } if r.Method == "GET" && r.Quorum { @@ -214,14 +214,14 @@ func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) { if err != nil { return Response{}, err } - ch := s.w.Register(r.Id) + ch := s.w.Register(r.ID) s.Node.Propose(ctx, data) select { case x := <-ch: resp := x.(Response) return resp, resp.err case <-ctx.Done(): - s.w.Trigger(r.Id, nil) // GC wait + s.w.Trigger(r.ID, nil) // GC wait return Response{}, ctx.Err() case <-s.done: return Response{}, ErrStopped @@ -301,7 +301,7 @@ func (s *EtcdServer) sync(timeout time.Duration) { ctx, cancel := context.WithTimeout(context.Background(), timeout) req := pb.Request{ Method: "SYNC", - Id: GenID(), + ID: GenID(), Time: time.Now().UnixNano(), } data, err := req.Marshal() diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 337cfc98a..30208aefc 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -54,11 +54,11 @@ func TestDoLocalAction(t *testing.T) { wactions []action }{ { - pb.Request{Method: "GET", Id: 1, Wait: true}, + pb.Request{Method: "GET", ID: 1, Wait: true}, Response{Watcher: &stubWatcher{}}, nil, []action{action{name: "Watch"}}, }, { - pb.Request{Method: "GET", Id: 1}, + pb.Request{Method: "GET", ID: 1}, Response{Event: &store.Event{}}, nil, []action{ action{ @@ -68,7 +68,7 @@ func TestDoLocalAction(t *testing.T) { }, }, { - pb.Request{Method: "BADMETHOD", Id: 1}, + pb.Request{Method: "BADMETHOD", ID: 1}, Response{}, ErrUnknownMethod, []action{}, }, } @@ -100,11 +100,11 @@ func TestDoBadLocalAction(t *testing.T) { wactions []action }{ { - pb.Request{Method: "GET", Id: 1, Wait: true}, + pb.Request{Method: "GET", ID: 1, Wait: true}, []action{action{name: "Watch"}}, }, { - pb.Request{Method: "GET", Id: 1}, + pb.Request{Method: "GET", ID: 1}, []action{action{name: "Get"}}, }, } @@ -135,7 +135,7 @@ func TestApply(t *testing.T) { }{ // POST ==> Create { - pb.Request{Method: "POST", Id: 1}, + pb.Request{Method: "POST", ID: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -146,7 +146,7 @@ func TestApply(t *testing.T) { }, // POST ==> Create, with expiration { - pb.Request{Method: "POST", Id: 1, Expiration: 1337}, + pb.Request{Method: "POST", ID: 1, Expiration: 1337}, Response{Event: &store.Event{}}, []action{ action{ @@ -157,7 +157,7 @@ func TestApply(t *testing.T) { }, // POST ==> Create, with dir { - pb.Request{Method: "POST", Id: 1, Dir: true}, + pb.Request{Method: "POST", ID: 1, Dir: true}, Response{Event: &store.Event{}}, []action{ action{ @@ -168,7 +168,7 @@ func TestApply(t *testing.T) { }, // PUT ==> Set { - pb.Request{Method: "PUT", Id: 1}, + pb.Request{Method: "PUT", ID: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -179,7 +179,7 @@ func TestApply(t *testing.T) { }, // PUT ==> Set, with dir { - pb.Request{Method: "PUT", Id: 1, Dir: true}, + pb.Request{Method: "PUT", ID: 1, Dir: true}, Response{Event: &store.Event{}}, []action{ action{ @@ -190,7 +190,7 @@ func TestApply(t *testing.T) { }, // PUT with PrevExist=true ==> Update { - pb.Request{Method: "PUT", Id: 1, PrevExist: boolp(true)}, + pb.Request{Method: "PUT", ID: 1, PrevExist: boolp(true)}, Response{Event: &store.Event{}}, []action{ action{ @@ -201,7 +201,7 @@ func TestApply(t *testing.T) { }, // PUT with PrevExist=false ==> Create { - pb.Request{Method: "PUT", Id: 1, PrevExist: boolp(false)}, + pb.Request{Method: "PUT", ID: 1, PrevExist: boolp(false)}, Response{Event: &store.Event{}}, []action{ action{ @@ -213,7 +213,7 @@ func TestApply(t *testing.T) { // PUT with PrevExist=true *and* PrevIndex set ==> Update // TODO(jonboulle): is this expected?! { - pb.Request{Method: "PUT", Id: 1, PrevExist: boolp(true), PrevIndex: 1}, + pb.Request{Method: "PUT", ID: 1, PrevExist: boolp(true), PrevIndex: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -225,7 +225,7 @@ func TestApply(t *testing.T) { // PUT with PrevExist=false *and* PrevIndex set ==> Create // TODO(jonboulle): is this expected?! { - pb.Request{Method: "PUT", Id: 1, PrevExist: boolp(false), PrevIndex: 1}, + pb.Request{Method: "PUT", ID: 1, PrevExist: boolp(false), PrevIndex: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -236,7 +236,7 @@ func TestApply(t *testing.T) { }, // PUT with PrevIndex set ==> CompareAndSwap { - pb.Request{Method: "PUT", Id: 1, PrevIndex: 1}, + pb.Request{Method: "PUT", ID: 1, PrevIndex: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -247,7 +247,7 @@ func TestApply(t *testing.T) { }, // PUT with PrevValue set ==> CompareAndSwap { - pb.Request{Method: "PUT", Id: 1, PrevValue: "bar"}, + pb.Request{Method: "PUT", ID: 1, PrevValue: "bar"}, Response{Event: &store.Event{}}, []action{ action{ @@ -258,7 +258,7 @@ func TestApply(t *testing.T) { }, // PUT with PrevIndex and PrevValue set ==> CompareAndSwap { - pb.Request{Method: "PUT", Id: 1, PrevIndex: 1, PrevValue: "bar"}, + pb.Request{Method: "PUT", ID: 1, PrevIndex: 1, PrevValue: "bar"}, Response{Event: &store.Event{}}, []action{ action{ @@ -269,7 +269,7 @@ func TestApply(t *testing.T) { }, // DELETE ==> Delete { - pb.Request{Method: "DELETE", Id: 1}, + pb.Request{Method: "DELETE", ID: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -280,7 +280,7 @@ func TestApply(t *testing.T) { }, // DELETE with PrevIndex set ==> CompareAndDelete { - pb.Request{Method: "DELETE", Id: 1, PrevIndex: 1}, + pb.Request{Method: "DELETE", ID: 1, PrevIndex: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -291,7 +291,7 @@ func TestApply(t *testing.T) { }, // DELETE with PrevValue set ==> CompareAndDelete { - pb.Request{Method: "DELETE", Id: 1, PrevValue: "bar"}, + pb.Request{Method: "DELETE", ID: 1, PrevValue: "bar"}, Response{Event: &store.Event{}}, []action{ action{ @@ -302,7 +302,7 @@ func TestApply(t *testing.T) { }, // DELETE with PrevIndex *and* PrevValue set ==> CompareAndDelete { - pb.Request{Method: "DELETE", Id: 1, PrevIndex: 5, PrevValue: "bar"}, + pb.Request{Method: "DELETE", ID: 1, PrevIndex: 5, PrevValue: "bar"}, Response{Event: &store.Event{}}, []action{ action{ @@ -313,7 +313,7 @@ func TestApply(t *testing.T) { }, // QGET ==> Get { - pb.Request{Method: "QGET", Id: 1}, + pb.Request{Method: "QGET", ID: 1}, Response{Event: &store.Event{}}, []action{ action{ @@ -324,7 +324,7 @@ func TestApply(t *testing.T) { }, // SYNC ==> DeleteExpiredKeys { - pb.Request{Method: "SYNC", Id: 1}, + pb.Request{Method: "SYNC", ID: 1}, Response{}, []action{ action{ @@ -334,7 +334,7 @@ func TestApply(t *testing.T) { }, }, { - pb.Request{Method: "SYNC", Id: 1, Time: 12345}, + pb.Request{Method: "SYNC", ID: 1, Time: 12345}, Response{}, []action{ action{ @@ -345,7 +345,7 @@ func TestApply(t *testing.T) { }, // Unknown method - error { - pb.Request{Method: "BADMETHOD", Id: 1}, + pb.Request{Method: "BADMETHOD", ID: 1}, Response{err: ErrUnknownMethod}, []action{}, }, @@ -409,7 +409,7 @@ func testServer(t *testing.T, ns int64) { for i := 1; i <= 10; i++ { r := pb.Request{ Method: "PUT", - Id: int64(i), + ID: int64(i), Path: "/foo", Val: "bar", } @@ -448,10 +448,10 @@ func testServer(t *testing.T, ns int64) { func TestDoProposal(t *testing.T) { tests := []pb.Request{ - pb.Request{Method: "POST", Id: 1}, - pb.Request{Method: "PUT", Id: 1}, - pb.Request{Method: "DELETE", Id: 1}, - pb.Request{Method: "GET", Id: 1, Quorum: true}, + pb.Request{Method: "POST", ID: 1}, + pb.Request{Method: "PUT", ID: 1}, + pb.Request{Method: "DELETE", ID: 1}, + pb.Request{Method: "GET", ID: 1, Quorum: true}, } for i, tt := range tests { @@ -502,7 +502,7 @@ func TestDoProposalCancelled(t *testing.T) { done := make(chan struct{}) var err error go func() { - _, err = srv.Do(ctx, pb.Request{Method: "PUT", Id: 1}) + _, err = srv.Do(ctx, pb.Request{Method: "PUT", ID: 1}) close(done) }() cancel() @@ -543,7 +543,7 @@ func TestDoProposalStopped(t *testing.T) { done := make(chan struct{}) var err error go func() { - _, err = srv.Do(ctx, pb.Request{Method: "PUT", Id: 1}) + _, err = srv.Do(ctx, pb.Request{Method: "PUT", ID: 1}) close(done) }() srv.Stop() @@ -711,7 +711,7 @@ func TestTriggerSnap(t *testing.T) { s.Start() for i := 0; int64(i) < s.SnapCount; i++ { - s.Do(ctx, pb.Request{Method: "PUT", Id: 1}) + s.Do(ctx, pb.Request{Method: "PUT", ID: 1}) } time.Sleep(time.Millisecond) s.Stop() diff --git a/raft/raftpb/raft.pb.go b/raft/raftpb/raft.pb.go index a2852b71a..5d5deb1ab 100644 --- a/raft/raftpb/raft.pb.go +++ b/raft/raftpb/raft.pb.go @@ -99,7 +99,7 @@ func (x *ConfChangeType) UnmarshalJSON(data []byte) error { } type Info struct { - Id int64 `protobuf:"varint,1,req,name=id" json:"id"` + ID int64 `protobuf:"varint,1,req" json:"ID"` XXX_unrecognized []byte `json:"-"` } @@ -204,7 +204,7 @@ func (m *Info) Unmarshal(data []byte) error { } b := data[index] index++ - m.Id |= (int64(b) & 0x7F) << shift + m.ID |= (int64(b) & 0x7F) << shift if b < 0x80 { break } @@ -845,7 +845,7 @@ func (m *ConfChange) Unmarshal(data []byte) error { func (m *Info) Size() (n int) { var l int _ = l - n += 1 + sovRaft(uint64(m.Id)) + n += 1 + sovRaft(uint64(m.ID)) if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -959,7 +959,7 @@ func (m *Info) MarshalTo(data []byte) (n int, err error) { _ = l data[i] = 0x8 i++ - i = encodeVarintRaft(data, i, uint64(m.Id)) + i = encodeVarintRaft(data, i, uint64(m.ID)) if m.XXX_unrecognized != nil { i += copy(data[i:], m.XXX_unrecognized) } diff --git a/raft/raftpb/raft.proto b/raft/raftpb/raft.proto index 2c3b9d637..d22e12474 100644 --- a/raft/raftpb/raft.proto +++ b/raft/raftpb/raft.proto @@ -9,7 +9,7 @@ option (gogoproto.goproto_getters_all) = false; option (gogoproto.goproto_enum_prefix_all) = false; message Info { - required int64 id = 1 [(gogoproto.nullable) = false]; + required int64 ID = 1 [(gogoproto.nullable) = false]; } enum EntryType { diff --git a/wal/wal.go b/wal/wal.go index 0f48cd7dd..01d5cd9da 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -170,11 +170,11 @@ func (w *WAL) ReadAll() (id int64, state raftpb.HardState, ents []raftpb.Entry, state = mustUnmarshalState(rec.Data) case infoType: i := mustUnmarshalInfo(rec.Data) - if id != 0 && id != i.Id { + if id != 0 && id != i.ID { state.Reset() return 0, state, nil, ErrIDMismatch } - id = i.Id + id = i.ID case crcType: crc := decoder.crc.Sum32() // current crc of decoder must match the crc of the record. diff --git a/wal/wal_test.go b/wal/wal_test.go index e4e3dc48f..b18a42b51 100644 --- a/wal/wal_test.go +++ b/wal/wal_test.go @@ -165,7 +165,7 @@ func TestRecover(t *testing.T) { if err != nil { t.Fatal(err) } - i := &raftpb.Info{Id: int64(0xBAD0)} + i := &raftpb.Info{ID: int64(0xBAD0)} if err = w.SaveInfo(i); err != nil { t.Fatal(err) } @@ -191,8 +191,8 @@ func TestRecover(t *testing.T) { t.Fatal(err) } - if id != i.Id { - t.Errorf("id = %d, want %d", id, i.Id) + if id != i.ID { + t.Errorf("id = %d, want %d", id, i.ID) } if !reflect.DeepEqual(entries, ents) { t.Errorf("ents = %+v, want %+v", entries, ents) @@ -282,7 +282,7 @@ func TestRecoverAfterCut(t *testing.T) { if err != nil { t.Fatal(err) } - info := &raftpb.Info{Id: int64(0xBAD1)} + info := &raftpb.Info{ID: int64(0xBAD1)} if err = w.SaveInfo(info); err != nil { t.Fatal(err) } @@ -328,8 +328,8 @@ func TestRecoverAfterCut(t *testing.T) { t.Errorf("#%d: err = %v, want nil", i, err) continue } - if id != info.Id { - t.Errorf("#%d: id = %d, want %d", i, id, info.Id) + if id != info.ID { + t.Errorf("#%d: id = %d, want %d", i, id, info.ID) } for j, e := range entries { if e.Index != int64(j+i) {