Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics #156

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ type asyncCallState struct {
// AsyncCall starts an asynchronous quorum call, returning an Async object that can be used to retrieve the results.
//
// This function should only be used by generated code.
func (c RawConfiguration) AsyncCall(ctx context.Context, d QuorumCallData) *Async {
expectedReplies := len(c)
func (c RawConfiguration[NODE, QSPEC]) AsyncCall(ctx context.Context, d QuorumCallData) *Async {
expectedReplies := len(c.nodes)
md := &ordering.Metadata{MessageID: c.getMsgID(), Method: d.Method}
replyChan := make(chan response, expectedReplies)

for _, n := range c {
for _, n := range c.nodes {
msg := d.Message
if d.PerNodeArgFn != nil {
msg = d.PerNodeArgFn(d.Message, n.id)
msg = d.PerNodeArgFn(d.Message, n.AsRaw().id)
if !msg.ProtoReflect().IsValid() {
expectedReplies--
continue // don't send if no msg
}
}
n.channel.enqueue(request{ctx: ctx, msg: &Message{Metadata: md, Message: msg}}, replyChan, false)
n.AsRaw().channel.enqueue(request{ctx: ctx, msg: &Message{Metadata: md, Message: msg}}, replyChan, false)
}

fut := &Async{c: make(chan struct{}, 1)}
Expand All @@ -73,7 +73,7 @@ func (c RawConfiguration) AsyncCall(ctx context.Context, d QuorumCallData) *Asyn
return fut
}

func (c RawConfiguration) handleAsyncCall(ctx context.Context, fut *Async, state asyncCallState) {
func (c RawConfiguration[NODE, QSPEC]) handleAsyncCall(ctx context.Context, fut *Async, state asyncCallState) {
defer close(fut.c)

var (
Expand Down
10 changes: 5 additions & 5 deletions benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type (
serverFunc func(context.Context, *TimedMsg)
)

func runQCBenchmark(opts Options, cfg *Configuration, f qcFunc) (*Result, error) {
func runQCBenchmark(opts Options, cfg Configuration, f qcFunc) (*Result, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
msg := &Echo{Payload: make([]byte, opts.Payload)}
Expand Down Expand Up @@ -103,7 +103,7 @@ func runQCBenchmark(opts Options, cfg *Configuration, f qcFunc) (*Result, error)
return result, nil
}

func runAsyncQCBenchmark(opts Options, cfg *Configuration, f asyncQCFunc) (*Result, error) {
func runAsyncQCBenchmark(opts Options, cfg Configuration, f asyncQCFunc) (*Result, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
msg := &Echo{Payload: make([]byte, opts.Payload)}
Expand Down Expand Up @@ -187,7 +187,7 @@ func runAsyncQCBenchmark(opts Options, cfg *Configuration, f asyncQCFunc) (*Resu
return result, nil
}

func runServerBenchmark(opts Options, cfg *Configuration, f serverFunc) (*Result, error) {
func runServerBenchmark(opts Options, cfg Configuration, f serverFunc) (*Result, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
payload := make([]byte, opts.Payload)
Expand Down Expand Up @@ -241,7 +241,7 @@ func runServerBenchmark(opts Options, cfg *Configuration, f serverFunc) (*Result
}

// GetBenchmarks returns a list of Benchmarks that can be performed on the configuration
func GetBenchmarks(cfg *Configuration) []Bench {
func GetBenchmarks(cfg Configuration) []Bench {
m := []Bench{
{
Name: "QuorumCall",
Expand Down Expand Up @@ -270,7 +270,7 @@ func GetBenchmarks(cfg *Configuration) []Bench {
}

// RunBenchmarks runs all the benchmarks that match the given regex with the given options
func RunBenchmarks(benchRegex *regexp.Regexp, options Options, cfg *Configuration) ([]*Result, error) {
func RunBenchmarks(benchRegex *regexp.Regexp, options Options, cfg Configuration) ([]*Result, error) {
benchmarks := GetBenchmarks(cfg)
var results []*Result
for _, b := range benchmarks {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark.pb.go

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

121 changes: 71 additions & 50 deletions benchmark/benchmark_gorums.pb.go

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

2 changes: 1 addition & 1 deletion cmd/benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (f *listFlag) Get() []string {

func listBenchmarks() {
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
benchmarks := benchmark.GetBenchmarks(nil)
benchmarks := benchmark.GetBenchmarks(benchmark.Configuration{})
for _, b := range benchmarks {
fmt.Fprintf(tw, "%s:\t%s\n", b.Name, b.Description)
}
Expand Down
Loading