-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
60 lines (48 loc) · 1.92 KB
/
service.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
// Copyright (c) 2019 Meng Huang (mhboy@outlook.com)
// This package is licensed under a MIT license that can be found in the LICENSE file.
package raft
// Service represents the RPCs service.
type Service interface {
RequestVote(req *RequestVoteRequest, res *RequestVoteResponse) error
AppendEntries(req *AppendEntriesRequest, res *AppendEntriesResponse) error
InstallSnapshot(req *InstallSnapshotRequest, res *InstallSnapshotResponse) error
GetLeader(req *GetLeaderRequest, res *GetLeaderResponse) error
AddMember(req *AddMemberRequest, res *AddMemberResponse) error
RemoveMember(req *RemoveMemberRequest, res *RemoveMemberResponse) error
SetMeta(req *SetMetaRequest, res *SetMetaResponse) error
GetMeta(req *GetMetaRequest, res *GetMetaResponse) error
}
type service struct {
raft *raft
cluster *cluster
}
func newService(n *node) *service {
return &service{
raft: newRaft(n),
cluster: newCluster(n),
}
}
func (s *service) RequestVote(req *RequestVoteRequest, res *RequestVoteResponse) error {
return s.raft.RequestVote(req, res)
}
func (s *service) AppendEntries(req *AppendEntriesRequest, res *AppendEntriesResponse) error {
return s.raft.AppendEntries(req, res)
}
func (s *service) InstallSnapshot(req *InstallSnapshotRequest, res *InstallSnapshotResponse) error {
return s.raft.InstallSnapshot(req, res)
}
func (s *service) GetLeader(req *GetLeaderRequest, res *GetLeaderResponse) error {
return s.cluster.GetLeader(req, res)
}
func (s *service) AddMember(req *AddMemberRequest, res *AddMemberResponse) error {
return s.cluster.AddMember(req, res)
}
func (s *service) RemoveMember(req *RemoveMemberRequest, res *RemoveMemberResponse) error {
return s.cluster.RemoveMember(req, res)
}
func (s *service) SetMeta(req *SetMetaRequest, res *SetMetaResponse) error {
return s.cluster.SetMeta(req, res)
}
func (s *service) GetMeta(req *GetMetaRequest, res *GetMetaResponse) error {
return s.cluster.GetMeta(req, res)
}