Skip to content

Commit 429ea54

Browse files
refactor(protoc): incorporated replySpec into qSpec
1 parent 5b734e0 commit 429ea54

10 files changed

+55
-34
lines changed

broadcastTypes.go

+6
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ func WithoutUniquenessChecks() BroadcastOption {
151151
}
152152
}
153153

154+
// not sure if this is necessary because the implementer
155+
// can decide to run the broadcast in a go routine.
156+
func WithoutWaiting() BroadcastOption {
157+
return func(b *BroadcastOptions) {}
158+
}
159+
154160
type BroadcastOptions struct {
155161
ServerAddresses []string
156162
GossipPercentage float32

cmd/protoc-gen-gorums/dev/config.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
// procedure calls may be invoked.
99
type Configuration struct {
1010
gorums.RawConfiguration
11-
nodes []*Node
12-
qspec QuorumSpec
13-
srv *clientServerImpl
14-
replySpec ReplySpec
11+
nodes []*Node
12+
qspec QuorumSpec
13+
srv *clientServerImpl
1514
}
1615

1716
// ConfigurationFromRaw returns a new Configuration from the given raw configuration and QuorumSpec.

cmd/protoc-gen-gorums/dev/server.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type clientServerImpl struct {
5959
grpcServer *grpc.Server
6060
}
6161

62-
func (c *Configuration) RegisterClientServer(listenAddr string, replySpec ReplySpec, opts ...grpc.ServerOption) error {
62+
func (c *Configuration) RegisterClientServer(listenAddr string, opts ...grpc.ServerOption) error {
6363
srvImpl := &clientServerImpl{
6464
grpcServer: grpc.NewServer(opts...),
6565
}
@@ -71,6 +71,5 @@ func (c *Configuration) RegisterClientServer(listenAddr string, replySpec ReplyS
7171
go srvImpl.grpcServer.Serve(lis)
7272
srvImpl.ClientServer = srv
7373
c.srv = srvImpl
74-
c.replySpec = replySpec
7574
return nil
7675
}

cmd/protoc-gen-gorums/dev/zorums_broadcastcall_gorums.pb.go

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/protoc-gen-gorums/dev/zorums_clientserver_gorums.pb.go

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/protoc-gen-gorums/dev/zorums_qspec_gorums.pb.go

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/protoc-gen-gorums/gengorums/template_broadcastcall.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ func (c *Configuration) {{.Method.GoName}}(ctx context.Context, in *{{in .GenFil
3232
if c.srv == nil {
3333
return nil, fmt.Errorf("a client server is not defined. Use configuration.RegisterClientServer() to define a client server")
3434
}
35-
if c.replySpec == nil {
36-
return nil, fmt.Errorf("a reply spec is not defined. Use configuration.RegisterClientServer() to define a reply spec")
35+
if c.qspec == nil {
36+
return nil, fmt.Errorf("a qspec is not defined.")
3737
}
38-
doneChan, cd := c.srv.AddRequest(ctx, in, gorums.ConvertToType(c.replySpec.{{.Method.GoName}}))
38+
doneChan, cd := c.srv.AddRequest(ctx, in, gorums.ConvertToType(c.qspec.{{.Method.GoName}}QF))
3939
c.RawConfiguration.Multicast(ctx, cd, gorums.WithNoSendWaiting())
4040
response, ok := <-doneChan
4141
if !ok {

cmd/protoc-gen-gorums/gengorums/template_clientserver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ type ReplySpec interface {
5757
{{- end}}
5858
`
5959

60-
var clientServer = clientServerVariables + clientServerInterface + clientServerDesc + clientServerImplInterface
60+
var clientServer = clientServerVariables + clientServerInterface + clientServerDesc

cmd/protoc-gen-gorums/gengorums/template_qspec.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ type QuorumSpec interface {
2424
// supplied to the {{$method}} method at call time, and may or may not
2525
// be used by the quorum function. If the in parameter is not needed
2626
// you should implement your quorum function with '_ *{{$in}}'.
27+
{{- if isBroadcastCall .}}
28+
{{.GoName}}QF(replies []*{{$out}}) (*{{$out}}, bool)
29+
{{- else}}
2730
{{$method}}QF(in *{{$in}}, replies map[uint32]*{{$out}}) (*{{$customOut}}{{withCorrectable . ", int"}}, bool)
31+
{{- end}}
2832
{{end}}
2933
}
3034
{{end}}
@@ -34,8 +38,8 @@ type QuorumSpec interface {
3438
// a quorum function; that is, all except multicast and plain gRPC methods.
3539
func qspecMethods(methods []*protogen.Method) (s []*protogen.Method) {
3640
for _, method := range methods {
37-
if hasMethodOption(method, gorums.E_Multicast, gorums.E_Unicast, gorums.E_Broadcastcall) || !hasGorumsCallType(method) {
38-
// ignore multicast, broadcast and non-Gorums methods
41+
if hasMethodOption(method, gorums.E_Multicast, gorums.E_Unicast) || !hasGorumsCallType(method) {
42+
// ignore multicast and non-Gorums methods
3943
continue
4044
}
4145
s = append(s, method)

cmd/protoc-gen-gorums/gengorums/template_static.go

+5-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)