/
server.pb.go
497 lines (441 loc) · 15.9 KB
/
server.pb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: rafts/server.proto
package rafts
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// node 节点信息
type Node struct {
// 节点ID
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// 节点地址
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Node) Reset() { *m = Node{} }
func (m *Node) String() string { return proto.CompactTextString(m) }
func (*Node) ProtoMessage() {}
func (*Node) Descriptor() ([]byte, []int) {
return fileDescriptor_08ce3bd0eb6eb3b8, []int{0}
}
func (m *Node) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Node.Unmarshal(m, b)
}
func (m *Node) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Node.Marshal(b, m, deterministic)
}
func (m *Node) XXX_Merge(src proto.Message) {
xxx_messageInfo_Node.Merge(m, src)
}
func (m *Node) XXX_Size() int {
return xxx_messageInfo_Node.Size(m)
}
func (m *Node) XXX_DiscardUnknown() {
xxx_messageInfo_Node.DiscardUnknown(m)
}
var xxx_messageInfo_Node proto.InternalMessageInfo
func (m *Node) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Node) GetUrl() string {
if m != nil {
return m.Url
}
return ""
}
// hBeat 用于Leader节点复制日志给其他节点,也作为心跳
//
// prevLogIndex和prevLogTerm表示上一次发送的日志的索引和任期,用于保证收到的日志是连续的
type HBeat struct {
// Leader节点的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// Leader节点的ID
LeaderId string `protobuf:"bytes,2,opt,name=leaderId,proto3" json:"leaderId,omitempty"`
// 当前配置版本 index 递增
Version int32 `protobuf:"varint,4,opt,name=version,proto3" json:"version,omitempty"`
// 当前term同步配置信息
Config []byte `protobuf:"bytes,5,opt,name=config,proto3" json:"config,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *HBeat) Reset() { *m = HBeat{} }
func (m *HBeat) String() string { return proto.CompactTextString(m) }
func (*HBeat) ProtoMessage() {}
func (*HBeat) Descriptor() ([]byte, []int) {
return fileDescriptor_08ce3bd0eb6eb3b8, []int{1}
}
func (m *HBeat) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_HBeat.Unmarshal(m, b)
}
func (m *HBeat) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_HBeat.Marshal(b, m, deterministic)
}
func (m *HBeat) XXX_Merge(src proto.Message) {
xxx_messageInfo_HBeat.Merge(m, src)
}
func (m *HBeat) XXX_Size() int {
return xxx_messageInfo_HBeat.Size(m)
}
func (m *HBeat) XXX_DiscardUnknown() {
xxx_messageInfo_HBeat.DiscardUnknown(m)
}
var xxx_messageInfo_HBeat proto.InternalMessageInfo
func (m *HBeat) GetTerm() int32 {
if m != nil {
return m.Term
}
return 0
}
func (m *HBeat) GetLeaderId() string {
if m != nil {
return m.LeaderId
}
return ""
}
func (m *HBeat) GetVersion() int32 {
if m != nil {
return m.Version
}
return 0
}
func (m *HBeat) GetConfig() []byte {
if m != nil {
return m.Config
}
return nil
}
// hBeatReturn 接收者实现逻辑
//
// 返回false,如果收到的任期比当前任期小
//
// 返回false,如果不包含之前的日志条目(没有匹配prevLogIndex和prevLogTerm)
//
// 如果存在index相同但是term不相同的日志,删除从该位置开始所有的日志
//
// 追加所有不存在的日志
//
// 如果leaderCommit>commitIndex,将commitIndex设置为commitIndex = min(leaderCommit, index of last new entry)
type HBeatReturn struct {
// 当前任期号,用于Leader节点更新自己的任期(应该说是如果这个返回值比Leader自身的任期大,那么Leader需要更新自己的任期)
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// 如果Follower节点匹配prevLogIndex和prevLogTerm,返回true
Success bool `protobuf:"varint,2,opt,name=success,proto3" json:"success,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *HBeatReturn) Reset() { *m = HBeatReturn{} }
func (m *HBeatReturn) String() string { return proto.CompactTextString(m) }
func (*HBeatReturn) ProtoMessage() {}
func (*HBeatReturn) Descriptor() ([]byte, []int) {
return fileDescriptor_08ce3bd0eb6eb3b8, []int{2}
}
func (m *HBeatReturn) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_HBeatReturn.Unmarshal(m, b)
}
func (m *HBeatReturn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_HBeatReturn.Marshal(b, m, deterministic)
}
func (m *HBeatReturn) XXX_Merge(src proto.Message) {
xxx_messageInfo_HBeatReturn.Merge(m, src)
}
func (m *HBeatReturn) XXX_Size() int {
return xxx_messageInfo_HBeatReturn.Size(m)
}
func (m *HBeatReturn) XXX_DiscardUnknown() {
xxx_messageInfo_HBeatReturn.DiscardUnknown(m)
}
var xxx_messageInfo_HBeatReturn proto.InternalMessageInfo
func (m *HBeatReturn) GetTerm() int32 {
if m != nil {
return m.Term
}
return 0
}
func (m *HBeatReturn) GetSuccess() bool {
if m != nil {
return m.Success
}
return false
}
// reqVote 用于Candidate获取选票
type ReqVote struct {
// Candidate的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// Candidate的ID
CandidateId string `protobuf:"bytes,2,opt,name=candidateId,proto3" json:"candidateId,omitempty"`
// Candidate的URL
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
// Candidate最后Leader节点的ID
LastLeaderId string `protobuf:"bytes,4,opt,name=lastLeaderId,proto3" json:"lastLeaderId,omitempty"`
// Candidate最后一条日志的版本
LastVersion int32 `protobuf:"varint,5,opt,name=lastVersion,proto3" json:"lastVersion,omitempty"`
// Candidate最后一条日志的任期
LastTerm int32 `protobuf:"varint,6,opt,name=lastTerm,proto3" json:"lastTerm,omitempty"`
// 时间戳ns
Timestamp int64 `protobuf:"varint,7,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReqVote) Reset() { *m = ReqVote{} }
func (m *ReqVote) String() string { return proto.CompactTextString(m) }
func (*ReqVote) ProtoMessage() {}
func (*ReqVote) Descriptor() ([]byte, []int) {
return fileDescriptor_08ce3bd0eb6eb3b8, []int{3}
}
func (m *ReqVote) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReqVote.Unmarshal(m, b)
}
func (m *ReqVote) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReqVote.Marshal(b, m, deterministic)
}
func (m *ReqVote) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReqVote.Merge(m, src)
}
func (m *ReqVote) XXX_Size() int {
return xxx_messageInfo_ReqVote.Size(m)
}
func (m *ReqVote) XXX_DiscardUnknown() {
xxx_messageInfo_ReqVote.DiscardUnknown(m)
}
var xxx_messageInfo_ReqVote proto.InternalMessageInfo
func (m *ReqVote) GetTerm() int32 {
if m != nil {
return m.Term
}
return 0
}
func (m *ReqVote) GetCandidateId() string {
if m != nil {
return m.CandidateId
}
return ""
}
func (m *ReqVote) GetUrl() string {
if m != nil {
return m.Url
}
return ""
}
func (m *ReqVote) GetLastLeaderId() string {
if m != nil {
return m.LastLeaderId
}
return ""
}
func (m *ReqVote) GetLastVersion() int32 {
if m != nil {
return m.LastVersion
}
return 0
}
func (m *ReqVote) GetLastTerm() int32 {
if m != nil {
return m.LastTerm
}
return 0
}
func (m *ReqVote) GetTimestamp() int64 {
if m != nil {
return m.Timestamp
}
return 0
}
// 接收者的实现逻辑
//
// 返回false,如果收到的任期比当前任期小
//
// 如果本地状态中votedFor为null或者candidateId,且candidate的日志等于或多余(按照index判断)接收者的日志,则接收者投票给candidate,即返回true
type ReqVoteReturn struct {
// 当前任期,用于Candidate更新自己的任期
Term int32 `protobuf:"varint,1,opt,name=term,proto3" json:"term,omitempty"`
// true表示给Candidate投票
VoteGranted bool `protobuf:"varint,2,opt,name=voteGranted,proto3" json:"voteGranted,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ReqVoteReturn) Reset() { *m = ReqVoteReturn{} }
func (m *ReqVoteReturn) String() string { return proto.CompactTextString(m) }
func (*ReqVoteReturn) ProtoMessage() {}
func (*ReqVoteReturn) Descriptor() ([]byte, []int) {
return fileDescriptor_08ce3bd0eb6eb3b8, []int{4}
}
func (m *ReqVoteReturn) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ReqVoteReturn.Unmarshal(m, b)
}
func (m *ReqVoteReturn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ReqVoteReturn.Marshal(b, m, deterministic)
}
func (m *ReqVoteReturn) XXX_Merge(src proto.Message) {
xxx_messageInfo_ReqVoteReturn.Merge(m, src)
}
func (m *ReqVoteReturn) XXX_Size() int {
return xxx_messageInfo_ReqVoteReturn.Size(m)
}
func (m *ReqVoteReturn) XXX_DiscardUnknown() {
xxx_messageInfo_ReqVoteReturn.DiscardUnknown(m)
}
var xxx_messageInfo_ReqVoteReturn proto.InternalMessageInfo
func (m *ReqVoteReturn) GetTerm() int32 {
if m != nil {
return m.Term
}
return 0
}
func (m *ReqVoteReturn) GetVoteGranted() bool {
if m != nil {
return m.VoteGranted
}
return false
}
func init() {
proto.RegisterType((*Node)(nil), "rafts.node")
proto.RegisterType((*HBeat)(nil), "rafts.hBeat")
proto.RegisterType((*HBeatReturn)(nil), "rafts.hBeatReturn")
proto.RegisterType((*ReqVote)(nil), "rafts.reqVote")
proto.RegisterType((*ReqVoteReturn)(nil), "rafts.reqVoteReturn")
}
func init() { proto.RegisterFile("rafts/server.proto", fileDescriptor_08ce3bd0eb6eb3b8) }
var fileDescriptor_08ce3bd0eb6eb3b8 = []byte{
// 344 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x4a, 0xc3, 0x40,
0x10, 0x35, 0x6d, 0xd2, 0xb4, 0x93, 0x5a, 0x64, 0x10, 0x09, 0xc5, 0x43, 0xc8, 0x29, 0xa7, 0x16,
0x14, 0x4f, 0xde, 0x04, 0x11, 0xc1, 0x53, 0x90, 0xde, 0xb7, 0xd9, 0xa9, 0x0d, 0xb4, 0x49, 0xbb,
0x3b, 0xe9, 0x7f, 0xfa, 0x47, 0x92, 0x31, 0x89, 0x29, 0x14, 0x6f, 0xfb, 0xde, 0xee, 0xcb, 0x9b,
0xf7, 0x32, 0x80, 0x46, 0x6d, 0xd8, 0x2e, 0x2d, 0x99, 0x13, 0x99, 0xc5, 0xc1, 0x94, 0x5c, 0xa2,
0x27, 0x5c, 0x9c, 0x80, 0x5b, 0x94, 0x9a, 0x70, 0x06, 0x83, 0x5c, 0x87, 0x4e, 0xe4, 0x24, 0x93,
0x74, 0x90, 0x6b, 0xbc, 0x81, 0x61, 0x65, 0x76, 0xe1, 0x40, 0x88, 0xfa, 0x18, 0xe7, 0xe0, 0x6d,
0x5f, 0x48, 0x31, 0x22, 0xb8, 0x4c, 0x66, 0x2f, 0x8f, 0xbd, 0x54, 0xce, 0x38, 0x87, 0xf1, 0x8e,
0x94, 0x26, 0xf3, 0xae, 0x1b, 0x4d, 0x87, 0x31, 0x04, 0xff,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 0x65, 0xeb, 0x91, 0xac, 0xda, 0xe3, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff,
0x76, 0xcb, 0xe5, 0x90, 0x80, 0x02, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// RaftClient is the client API for Raft service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RaftClient interface {
// HeartBeat 发送心跳
Heartbeat(ctx context.Context, in *HBeat, opts ...grpc.CallOption) (*HBeatReturn, error)
// RequestVote 发起选举,索要选票
RequestVote(ctx context.Context, in *ReqVote, opts ...grpc.CallOption) (*ReqVoteReturn, error)
}
type raftClient struct {
cc *grpc.ClientConn
}
func NewRaftClient(cc *grpc.ClientConn) RaftClient {
return &raftClient{cc}
}
func (c *raftClient) Heartbeat(ctx context.Context, in *HBeat, opts ...grpc.CallOption) (*HBeatReturn, error) {
out := new(HBeatReturn)
err := c.cc.Invoke(ctx, "/rafts.Raft/heartbeat", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *raftClient) RequestVote(ctx context.Context, in *ReqVote, opts ...grpc.CallOption) (*ReqVoteReturn, error) {
out := new(ReqVoteReturn)
err := c.cc.Invoke(ctx, "/rafts.Raft/requestVote", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RaftServer is the server API for Raft service.
type RaftServer interface {
// HeartBeat 发送心跳
Heartbeat(context.Context, *HBeat) (*HBeatReturn, error)
// RequestVote 发起选举,索要选票
RequestVote(context.Context, *ReqVote) (*ReqVoteReturn, error)
}
func RegisterRaftServer(s *grpc.Server, srv RaftServer) {
s.RegisterService(&_Raft_serviceDesc, srv)
}
func _Raft_Heartbeat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HBeat)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RaftServer).Heartbeat(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rafts.Raft/Heartbeat",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RaftServer).Heartbeat(ctx, req.(*HBeat))
}
return interceptor(ctx, in, info, handler)
}
func _Raft_RequestVote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ReqVote)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RaftServer).RequestVote(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/rafts.Raft/RequestVote",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RaftServer).RequestVote(ctx, req.(*ReqVote))
}
return interceptor(ctx, in, info, handler)
}
var _Raft_serviceDesc = grpc.ServiceDesc{
ServiceName: "rafts.Raft",
HandlerType: (*RaftServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "heartbeat",
Handler: _Raft_Heartbeat_Handler,
},
{
MethodName: "requestVote",
Handler: _Raft_RequestVote_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "rafts/server.proto",
}