-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbenchmark_gorums.pb.go
486 lines (437 loc) · 18.3 KB
/
benchmark_gorums.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
// Code generated by protoc-gen-gorums. DO NOT EDIT.
// versions:
// protoc-gen-gorums v0.8.0-devel
// protoc v5.29.3
// source: benchmark/benchmark.proto
package benchmark
import (
context "context"
fmt "fmt"
gorums "github.com/relab/gorums"
encoding "google.golang.org/grpc/encoding"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = gorums.EnforceVersion(8 - gorums.MinVersion)
// Verify that the gorums runtime is sufficiently up-to-date.
_ = gorums.EnforceVersion(gorums.MaxVersion - 8)
)
// A Configuration represents a static set of nodes on which quorum remote
// procedure calls may be invoked.
type Configuration struct {
gorums.RawConfiguration
qspec QuorumSpec
nodes []*Node
}
// ConfigurationFromRaw returns a new Configuration from the given raw configuration and QuorumSpec.
//
// This function may for example be used to "clone" a configuration but install a different QuorumSpec:
//
// cfg1, err := mgr.NewConfiguration(qspec1, opts...)
// cfg2 := ConfigurationFromRaw(cfg1.RawConfig, qspec2)
func ConfigurationFromRaw(rawCfg gorums.RawConfiguration, qspec QuorumSpec) (*Configuration, error) {
// return an error if the QuorumSpec interface is not empty and no implementation was provided.
var test interface{} = struct{}{}
if _, empty := test.(QuorumSpec); !empty && qspec == nil {
return nil, fmt.Errorf("config: missing required QuorumSpec")
}
newCfg := &Configuration{
RawConfiguration: rawCfg,
qspec: qspec,
}
// initialize the nodes slice
newCfg.nodes = make([]*Node, newCfg.Size())
for i, n := range rawCfg {
newCfg.nodes[i] = &Node{n}
}
return newCfg, nil
}
// Nodes returns a slice of each available node. IDs are returned in the same
// order as they were provided in the creation of the Manager.
//
// NOTE: mutating the returned slice is not supported.
func (c *Configuration) Nodes() []*Node {
return c.nodes
}
// And returns a NodeListOption that can be used to create a new configuration combining c and d.
func (c Configuration) And(d *Configuration) gorums.NodeListOption {
return c.RawConfiguration.And(d.RawConfiguration)
}
// Except returns a NodeListOption that can be used to create a new configuration
// from c without the nodes in rm.
func (c Configuration) Except(rm *Configuration) gorums.NodeListOption {
return c.RawConfiguration.Except(rm.RawConfiguration)
}
func init() {
if encoding.GetCodec(gorums.ContentSubtype) == nil {
encoding.RegisterCodec(gorums.NewCodec())
}
}
// Manager maintains a connection pool of nodes on
// which quorum calls can be performed.
type Manager struct {
*gorums.RawManager
}
// NewManager returns a new Manager for managing connection to nodes added
// to the manager. This function accepts manager options used to configure
// various aspects of the manager.
func NewManager(opts ...gorums.ManagerOption) *Manager {
return &Manager{
RawManager: gorums.NewRawManager(opts...),
}
}
// NewConfiguration returns a configuration based on the provided list of nodes (required)
// and an optional quorum specification. The QuorumSpec is necessary for call types that
// must process replies. For configurations only used for unicast or multicast call types,
// a QuorumSpec is not needed. The QuorumSpec interface is also a ConfigOption.
// Nodes can be supplied using WithNodeMap or WithNodeList, or WithNodeIDs.
// A new configuration can also be created from an existing configuration,
// using the And, WithNewNodes, Except, and WithoutNodes methods.
func (m *Manager) NewConfiguration(opts ...gorums.ConfigOption) (c *Configuration, err error) {
if len(opts) < 1 || len(opts) > 2 {
return nil, fmt.Errorf("config: wrong number of options: %d", len(opts))
}
c = &Configuration{}
for _, opt := range opts {
switch v := opt.(type) {
case gorums.NodeListOption:
c.RawConfiguration, err = gorums.NewRawConfiguration(m.RawManager, v)
if err != nil {
return nil, err
}
case QuorumSpec:
// Must be last since v may match QuorumSpec if it is interface{}
c.qspec = v
default:
return nil, fmt.Errorf("config: unknown option type: %v", v)
}
}
// return an error if the QuorumSpec interface is not empty and no implementation was provided.
var test interface{} = struct{}{}
if _, empty := test.(QuorumSpec); !empty && c.qspec == nil {
return nil, fmt.Errorf("config: missing required QuorumSpec")
}
// initialize the nodes slice
c.nodes = make([]*Node, c.Size())
for i, n := range c.RawConfiguration {
c.nodes[i] = &Node{n}
}
return c, nil
}
// Nodes returns a slice of available nodes on this manager.
// IDs are returned in the order they were added at creation of the manager.
func (m *Manager) Nodes() []*Node {
gorumsNodes := m.RawManager.Nodes()
nodes := make([]*Node, len(gorumsNodes))
for i, n := range gorumsNodes {
nodes[i] = &Node{n}
}
return nodes
}
// Node encapsulates the state of a node on which a remote procedure call
// can be performed.
type Node struct {
*gorums.RawNode
}
// AsyncQuorumCall asynchronously invokes a quorum call on configuration c
// and returns a AsyncEcho, which can be used to inspect the quorum call
// reply and error when available.
func (c *Configuration) AsyncQuorumCall(ctx context.Context, in *Echo) *AsyncEcho {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.AsyncQuorumCall",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*Echo, len(replies))
for k, v := range replies {
r[k] = v.(*Echo)
}
return c.qspec.AsyncQuorumCallQF(req.(*Echo), r)
}
fut := c.RawConfiguration.AsyncCall(ctx, cd)
return &AsyncEcho{fut}
}
// BenchmarkClient is the client interface for the Benchmark service.
type BenchmarkClient interface {
StartServerBenchmark(ctx context.Context, in *StartRequest) (resp *StartResponse, err error)
StopServerBenchmark(ctx context.Context, in *StopRequest) (resp *Result, err error)
StartBenchmark(ctx context.Context, in *StartRequest) (resp *StartResponse, err error)
StopBenchmark(ctx context.Context, in *StopRequest) (resp *MemoryStatList, err error)
QuorumCall(ctx context.Context, in *Echo) (resp *Echo, err error)
AsyncQuorumCall(ctx context.Context, in *Echo) *AsyncEcho
SlowServer(ctx context.Context, in *Echo) (resp *Echo, err error)
Multicast(ctx context.Context, in *TimedMsg, opts ...gorums.CallOption)
}
// enforce interface compliance
var _ BenchmarkClient = (*Configuration)(nil)
// Reference imports to suppress errors if they are not otherwise used.
var _ emptypb.Empty
// Multicast is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) Multicast(ctx context.Context, in *TimedMsg, opts ...gorums.CallOption) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.Multicast",
}
c.RawConfiguration.Multicast(ctx, cd, opts...)
}
// QuorumSpec is the interface of quorum functions for Benchmark.
type QuorumSpec interface {
gorums.ConfigOption
// StartServerBenchmarkQF is the quorum function for the StartServerBenchmark
// quorum call method. The in parameter is the request object
// supplied to the StartServerBenchmark method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *StartRequest'.
StartServerBenchmarkQF(in *StartRequest, replies map[uint32]*StartResponse) (*StartResponse, bool)
// StopServerBenchmarkQF is the quorum function for the StopServerBenchmark
// quorum call method. The in parameter is the request object
// supplied to the StopServerBenchmark method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *StopRequest'.
StopServerBenchmarkQF(in *StopRequest, replies map[uint32]*Result) (*Result, bool)
// StartBenchmarkQF is the quorum function for the StartBenchmark
// quorum call method. The in parameter is the request object
// supplied to the StartBenchmark method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *StartRequest'.
StartBenchmarkQF(in *StartRequest, replies map[uint32]*StartResponse) (*StartResponse, bool)
// StopBenchmarkQF is the quorum function for the StopBenchmark
// quorum call method. The in parameter is the request object
// supplied to the StopBenchmark method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *StopRequest'.
StopBenchmarkQF(in *StopRequest, replies map[uint32]*MemoryStat) (*MemoryStatList, bool)
// QuorumCallQF is the quorum function for the QuorumCall
// quorum call method. The in parameter is the request object
// supplied to the QuorumCall method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *Echo'.
QuorumCallQF(in *Echo, replies map[uint32]*Echo) (*Echo, bool)
// AsyncQuorumCallQF is the quorum function for the AsyncQuorumCall
// asynchronous quorum call method. The in parameter is the request object
// supplied to the AsyncQuorumCall method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *Echo'.
AsyncQuorumCallQF(in *Echo, replies map[uint32]*Echo) (*Echo, bool)
// SlowServerQF is the quorum function for the SlowServer
// quorum call method. The in parameter is the request object
// supplied to the SlowServer method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *Echo'.
SlowServerQF(in *Echo, replies map[uint32]*Echo) (*Echo, bool)
}
// StartServerBenchmark is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) StartServerBenchmark(ctx context.Context, in *StartRequest) (resp *StartResponse, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.StartServerBenchmark",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*StartResponse, len(replies))
for k, v := range replies {
r[k] = v.(*StartResponse)
}
return c.qspec.StartServerBenchmarkQF(req.(*StartRequest), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*StartResponse), err
}
// StopServerBenchmark is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) StopServerBenchmark(ctx context.Context, in *StopRequest) (resp *Result, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.StopServerBenchmark",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*Result, len(replies))
for k, v := range replies {
r[k] = v.(*Result)
}
return c.qspec.StopServerBenchmarkQF(req.(*StopRequest), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*Result), err
}
// StartBenchmark is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) StartBenchmark(ctx context.Context, in *StartRequest) (resp *StartResponse, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.StartBenchmark",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*StartResponse, len(replies))
for k, v := range replies {
r[k] = v.(*StartResponse)
}
return c.qspec.StartBenchmarkQF(req.(*StartRequest), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*StartResponse), err
}
// StopBenchmark is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) StopBenchmark(ctx context.Context, in *StopRequest) (resp *MemoryStatList, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.StopBenchmark",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*MemoryStat, len(replies))
for k, v := range replies {
r[k] = v.(*MemoryStat)
}
return c.qspec.StopBenchmarkQF(req.(*StopRequest), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*MemoryStatList), err
}
// benchmarks
func (c *Configuration) QuorumCall(ctx context.Context, in *Echo) (resp *Echo, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.QuorumCall",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*Echo, len(replies))
for k, v := range replies {
r[k] = v.(*Echo)
}
return c.qspec.QuorumCallQF(req.(*Echo), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*Echo), err
}
// SlowServer is a quorum call invoked on all nodes in configuration c,
// with the same argument in, and returns a combined result.
func (c *Configuration) SlowServer(ctx context.Context, in *Echo) (resp *Echo, err error) {
cd := gorums.QuorumCallData{
Message: in,
Method: "benchmark.Benchmark.SlowServer",
}
cd.QuorumFunction = func(req protoreflect.ProtoMessage, replies map[uint32]protoreflect.ProtoMessage) (protoreflect.ProtoMessage, bool) {
r := make(map[uint32]*Echo, len(replies))
for k, v := range replies {
r[k] = v.(*Echo)
}
return c.qspec.SlowServerQF(req.(*Echo), r)
}
res, err := c.RawConfiguration.QuorumCall(ctx, cd)
if err != nil {
return nil, err
}
return res.(*Echo), err
}
// Benchmark is the server-side API for the Benchmark Service
type BenchmarkServer interface {
StartServerBenchmark(ctx gorums.ServerCtx, request *StartRequest) (response *StartResponse, err error)
StopServerBenchmark(ctx gorums.ServerCtx, request *StopRequest) (response *Result, err error)
StartBenchmark(ctx gorums.ServerCtx, request *StartRequest) (response *StartResponse, err error)
StopBenchmark(ctx gorums.ServerCtx, request *StopRequest) (response *MemoryStat, err error)
QuorumCall(ctx gorums.ServerCtx, request *Echo) (response *Echo, err error)
AsyncQuorumCall(ctx gorums.ServerCtx, request *Echo) (response *Echo, err error)
SlowServer(ctx gorums.ServerCtx, request *Echo) (response *Echo, err error)
Multicast(ctx gorums.ServerCtx, request *TimedMsg)
}
func RegisterBenchmarkServer(srv *gorums.Server, impl BenchmarkServer) {
srv.RegisterHandler("benchmark.Benchmark.StartServerBenchmark", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*StartRequest)
defer ctx.Release()
resp, err := impl.StartServerBenchmark(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.StopServerBenchmark", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*StopRequest)
defer ctx.Release()
resp, err := impl.StopServerBenchmark(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.StartBenchmark", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*StartRequest)
defer ctx.Release()
resp, err := impl.StartBenchmark(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.StopBenchmark", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*StopRequest)
defer ctx.Release()
resp, err := impl.StopBenchmark(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.QuorumCall", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*Echo)
defer ctx.Release()
resp, err := impl.QuorumCall(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.AsyncQuorumCall", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*Echo)
defer ctx.Release()
resp, err := impl.AsyncQuorumCall(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.SlowServer", func(ctx gorums.ServerCtx, in *gorums.Message, finished chan<- *gorums.Message) {
req := in.Message.(*Echo)
defer ctx.Release()
resp, err := impl.SlowServer(ctx, req)
gorums.SendMessage(ctx, finished, gorums.WrapMessage(in.Metadata, resp, err))
})
srv.RegisterHandler("benchmark.Benchmark.Multicast", func(ctx gorums.ServerCtx, in *gorums.Message, _ chan<- *gorums.Message) {
req := in.Message.(*TimedMsg)
defer ctx.Release()
impl.Multicast(ctx, req)
})
}
type internalEcho struct {
nid uint32
reply *Echo
err error
}
type internalMemoryStat struct {
nid uint32
reply *MemoryStat
err error
}
type internalResult struct {
nid uint32
reply *Result
err error
}
type internalStartResponse struct {
nid uint32
reply *StartResponse
err error
}
// AsyncEcho is a async object for processing replies.
type AsyncEcho struct {
*gorums.Async
}
// Get returns the reply and any error associated with the called method.
// The method blocks until a reply or error is available.
func (f *AsyncEcho) Get() (*Echo, error) {
resp, err := f.Async.Get()
if err != nil {
return nil, err
}
return resp.(*Echo), err
}