-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpc_api_replication.go
95 lines (79 loc) · 2.13 KB
/
rpc_api_replication.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
package main
import (
"context"
"log"
)
const (
ReplicationServiceName = "ReplicationRPCAPI"
ReplicationProposeFuncName = "Propose"
ReplicationProposeClusterFuncName = "ProposeCluster"
ReplicationCommitFuncName = "Commit"
ReplicationCommitClusterFuncName = "CommitCluster"
ReplicationGetFuncName = "Get"
ReplicationGetClusterFuncName = "GetCluster"
ReplicationStateFuncName = "State"
)
type ReplicationRPCAPI struct {
r *ReplicationService
}
type ProposeArgs struct {
Key string
Value []byte
}
type ProposeReply struct {
Errors PeerErrors
}
func (r *ReplicationRPCAPI) Propose(ctx context.Context, in ProposeArgs, out *struct{}) error {
log.Printf("Received proposal for key: %q", in.Key)
return r.r.Propose(in.Key, in.Value)
}
func (r *ReplicationRPCAPI) ProposeCluster(ctx context.Context, in ProposeArgs, out *ProposeReply) error {
log.Printf("Received proposal cluster for key: %q", in.Key)
out.Errors = r.r.ProposeCluster(in.Key, in.Value)
return nil
}
type CommitArgs struct {
Key string
}
func (r *ReplicationRPCAPI) Commit(ctx context.Context, in CommitArgs, out *struct{}) error {
log.Printf("Received commit for key: %q", in.Key)
return r.r.CommitLocal(in.Key)
}
func (r *ReplicationRPCAPI) CommitCluster(ctx context.Context, in CommitArgs, out *struct{}) error {
log.Printf("Received commit cluster for key: %q", in.Key)
return r.r.CommitCluster(in.Key)
}
type GetArgs struct {
Key string
}
type GetReply struct {
Value []byte
}
func (r *ReplicationRPCAPI) Get(ctx context.Context, in GetArgs, out *GetReply) error {
value, err := r.r.GetLocal(in.Key)
if err != nil {
return err
}
out.Value = value
return nil
}
func (r *ReplicationRPCAPI) GetCluster(ctx context.Context, in GetArgs, out *GetReply) error {
value, err := r.r.GetCluster(in.Key)
if err != nil {
return err
}
out.Value = value
return nil
}
type State struct {
Stored map[string][]byte
Proposed map[string][]byte
}
func (r *ReplicationRPCAPI) State(ctx context.Context, in struct{}, out *State) error {
state, err := r.r.State()
if err != nil {
return err
}
*out = state
return nil
}