Skip to content

Commit

Permalink
dev,plugins: Fix nil values being added to the reply slice
Browse files Browse the repository at this point in the history
TestPerNodeArg is left failing to demonstrate the issue.
See #35.
  • Loading branch information
s111 authored and meling committed Sep 28, 2017
1 parent 43b6449 commit 1ed8bf1
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 78 deletions.
21 changes: 10 additions & 11 deletions dev/calltype_common_definitions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

{{define "callGRPC"}}
func callGRPC{{.MethodName}}(ctx context.Context, node *Node, arg *{{.FQReqName}}, replyChan chan<- {{.UnexportedTypeName}}) {
if arg == nil {
// send a nil reply to the for-select-loop
replyChan <- {{.UnexportedTypeName}}{node.id, nil, nil}
return
}
reply := new({{.FQRespName}})
start := time.Now()
err := grpc.Invoke(
Expand Down Expand Up @@ -87,12 +82,16 @@ func (c *Configuration) {{.UnexportedMethodName}}(ctx context.Context, a *{{.FQR
{{end}}

{{define "callLoop"}}
replyChan := make(chan {{.UnexportedTypeName}}, c.n)
for _, n := range c.nodes {
expected := c.n
replyChan := make(chan {{.UnexportedTypeName}}, expected)
for _, n := range c.nodes {
{{- if .PerNodeArg}}
go callGRPC{{.MethodName}}(ctx, n, f(*a, n.id), replyChan)
{{else}}
go callGRPC{{.MethodName}}(ctx, n, a, replyChan)
a := f(*a, n.id)
if a == nil {
expected--
continue
}
{{end -}}
}
go callGRPC{{.MethodName}}(ctx, n, a, replyChan)
}
{{end}}
8 changes: 2 additions & 6 deletions dev/calltype_correctable_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dev/calltype_correctable_stream_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions dev/calltype_future_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dev/calltype_quorumcall.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *Configuration) {{.UnexportedMethodName}}(ctx context.Context, a *{{.FQR
{{template "callLoop" .}}

var (
replyValues = make([]*{{.FQRespName}}, 0, c.n)
replyValues = make([]*{{.FQRespName}}, 0, expected)
errCount int
quorum bool
)
Expand All @@ -82,7 +82,7 @@ func (c *Configuration) {{.UnexportedMethodName}}(ctx context.Context, a *{{.FQR
return resp, QuorumCallError{ctx.Err().Error(), errCount, len(replyValues)}
}

if errCount+len(replyValues) == c.n {
if errCount+len(replyValues) == expected {
return resp, QuorumCallError{"incomplete call", errCount, len(replyValues)}
}
}
Expand Down
55 changes: 22 additions & 33 deletions dev/calltype_quorumcall_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions plugins/gorums/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ed8bf1

Please sign in to comment.