-
Notifications
You must be signed in to change notification settings - Fork 23
/
service_rpcx.go
187 lines (156 loc) · 5.29 KB
/
service_rpcx.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
package basalt
import (
"context"
"github.com/smallnest/rpcx/server"
)
// ConfigRpcxOption defines the rpcx config function.
type ConfigRpcxOption func(*Server, *server.Server)
// RpcxBitmapService provides the rpcx service for Bitmaps.
type RpcxBitmapService struct {
s *Server
confChangeCallback ConfChange
}
// BitmapValueRequest contains the name of bitmap and value.
type BitmapValueRequest struct {
Name string
Value uint32
}
// BitmapValuesRequest contains the name of bitmap and values.
type BitmapValuesRequest struct {
Name string
Values []uint32
}
// BitmapStoreRequest contains the name of destination and names of bitmaps.
type BitmapStoreRequest struct {
Destination string
Names []string
}
// BitmapPairRequest contains the name of two bitmaps.
type BitmapPairRequest struct {
Name1 string
Name2 string
}
// BitmapDstAndPairRequest contains destination and the name of two bitmaps.
type BitmapDstAndPairRequest struct {
Destination string
Name1 string
Name2 string
}
// Add adds a value in the bitmap with name.
func (s *RpcxBitmapService) Add(ctx context.Context, req *BitmapValueRequest, reply *bool) error {
s.s.bitmaps.Add(req.Name, req.Value, true)
*reply = true
return nil
}
// AddMany adds multiple values in the bitmap with name.
func (s *RpcxBitmapService) AddMany(ctx context.Context, req *BitmapValuesRequest, reply *bool) error {
s.s.bitmaps.AddMany(req.Name, req.Values, true)
*reply = true
return nil
}
// Remove removes a value in the bitmap with name.
func (s *RpcxBitmapService) Remove(ctx context.Context, req *BitmapValueRequest, reply *bool) error {
s.s.bitmaps.Remove(req.Name, req.Value, true)
*reply = true
return nil
}
// RemoveBitmap removes the bitmap.
func (s *RpcxBitmapService) RemoveBitmap(ctx context.Context, name string, reply *bool) error {
s.s.bitmaps.RemoveBitmap(name, true)
*reply = true
return nil
}
// ClearBitmap clears the bitmap and set it to be empty.
func (s *RpcxBitmapService) ClearBitmap(ctx context.Context, name string, reply *bool) error {
s.s.bitmaps.ClearBitmap(name, true)
*reply = true
return nil
}
// Exists checks whether the value exists.
func (s *RpcxBitmapService) Exists(ctx context.Context, req *BitmapValueRequest, reply *bool) error {
*reply = s.s.bitmaps.Exists(req.Name, req.Value)
return nil
}
// Card gets number of integers in the bitmap.
func (s *RpcxBitmapService) Card(ctx context.Context, name string, reply *uint64) error {
*reply = s.s.bitmaps.Card(name)
return nil
}
// Inter gets the intersection of bitmaps.
func (s *RpcxBitmapService) Inter(ctx context.Context, names []string, reply *[]uint32) error {
*reply = s.s.bitmaps.Inter(names...)
return nil
}
// InterStore gets the intersection of bitmaps and stores into destination.
func (s *RpcxBitmapService) InterStore(ctx context.Context, req *BitmapStoreRequest, reply *bool) error {
s.s.bitmaps.InterStore(req.Destination, req.Names...)
*reply = true
return nil
}
// Union gets the union of bitmaps.
func (s *RpcxBitmapService) Union(ctx context.Context, names []string, reply *[]uint32) error {
*reply = s.s.bitmaps.Union(names...)
return nil
}
// UnionStore gets the union of bitmaps and stores into destination.
func (s *RpcxBitmapService) UnionStore(ctx context.Context, req *BitmapStoreRequest, reply *bool) error {
s.s.bitmaps.UnionStore(req.Destination, req.Names...)
*reply = true
return nil
}
// Xor gets the symmetric difference between bitmaps.
func (s *RpcxBitmapService) Xor(ctx context.Context, names *BitmapPairRequest, reply *[]uint32) error {
*reply = s.s.bitmaps.Xor(names.Name1, names.Name2)
return nil
}
// XorStore gets the symmetric difference between bitmaps and stores into destination.
func (s *RpcxBitmapService) XorStore(ctx context.Context, names *BitmapDstAndPairRequest, reply *bool) error {
s.s.bitmaps.XorStore(names.Destination, names.Name1, names.Name2)
*reply = true
return nil
}
// Diff gets the difference between two bitmaps.
func (s *RpcxBitmapService) Diff(ctx context.Context, names *BitmapPairRequest, reply *[]uint32) error {
*reply = s.s.bitmaps.Diff(names.Name1, names.Name2)
return nil
}
// DiffStore gets the difference between two bitmaps and stores into destination.
func (s *RpcxBitmapService) DiffStore(ctx context.Context, names *BitmapDstAndPairRequest, reply *bool) error {
s.s.bitmaps.DiffStore(names.Destination, names.Name1, names.Name2)
*reply = true
return nil
}
// Stats get the stats of bitmap `name`.
func (s *RpcxBitmapService) Stats(ctx context.Context, name string, reply *Stats) error {
stats := s.s.bitmaps.Stats(name)
*reply = stats
return nil
}
// Save persists bitmaps.
func (s *RpcxBitmapService) Save(ctx context.Context, dummy string, reply *bool) error {
err := s.s.Save()
if err == nil {
*reply = true
}
return err
}
type AddNodeRequest struct {
ID uint64
Addr string
}
// AddNode adds a raft node.
func (s *RpcxBitmapService) AddNode(ctx context.Context, req *AddNodeRequest, reply *bool) error {
if s.confChangeCallback != nil {
s.confChangeCallback.AddNode(req.ID, []byte(req.Addr))
}
*reply = true
return nil
}
// RemoveNode removes a raft node.
func (s *RpcxBitmapService) RemoveNode(ctx context.Context, req uint64, reply *bool) error {
if s.confChangeCallback != nil {
s.confChangeCallback.RemoveNode(req)
}
*reply = true
return nil
}