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

Add strict mode and remove complete promise #73

Merged
merged 3 commits into from
Sep 29, 2023
Merged
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
2 changes: 1 addition & 1 deletion cmd/dst.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var dstRunCmd = &cobra.Command{

// instatiate api/aio
api := api.New(config.API.Size, metrics)
aio := aio.NewDST()
aio := aio.NewDST(r)

// instatiate aio subsystems
network := network.NewDST(config.AIO.Subsystems.NetworkDST.Config, rand.New(rand.NewSource(r.Int63())))
Expand Down
1 change: 0 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ var serveCmd = &cobra.Command{
system.AddOnRequest(types.ResolvePromise, coroutines.ResolvePromise)
system.AddOnRequest(types.RejectPromise, coroutines.RejectPromise)
system.AddOnRequest(types.CancelPromise, coroutines.CancelPromise)
system.AddOnRequest(types.CompletePromise, coroutines.CompletePromise)
system.AddOnRequest(types.ReadSubscriptions, coroutines.ReadSubscriptions)
system.AddOnRequest(types.CreateSubscription, coroutines.CreateSubscription)
system.AddOnRequest(types.DeleteSubscription, coroutines.DeleteSubscription)
Expand Down
8 changes: 6 additions & 2 deletions internal/aio/aio_dst.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ package aio

import (
"fmt"
"math/rand" // nosemgrep

"github.com/resonatehq/resonate/internal/kernel/bus"
"github.com/resonatehq/resonate/internal/kernel/types"
"github.com/resonatehq/resonate/internal/util"
)

type aioDST struct {
r *rand.Rand
sqes []*bus.SQE[types.Submission, types.Completion]
cqes []*bus.CQE[types.Submission, types.Completion]
subsystems map[types.AIOKind]Subsystem
done bool
}

func NewDST() *aioDST {
func NewDST(r *rand.Rand) *aioDST {
return &aioDST{
r: r,
subsystems: map[types.AIOKind]Subsystem{},
}
}
Expand Down Expand Up @@ -54,7 +57,8 @@ func (a *aioDST) Done() bool {
}

func (a *aioDST) Enqueue(sqe *bus.SQE[types.Submission, types.Completion]) {
a.sqes = append(a.sqes, sqe)
i := a.r.Intn(len(a.sqes) + 1)
a.sqes = append(a.sqes[:i], append([]*bus.SQE[types.Submission, types.Completion]{sqe}, a.sqes[i:]...)...)
}

func (a *aioDST) Dequeue(n int) []*bus.CQE[types.Submission, types.Completion] {
Expand Down
10 changes: 5 additions & 5 deletions internal/app/coroutines/cancelPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to read promise or read subscriptions", "req", req, "err", err)
slog.Error("failed to read promise", "req", req, "err", err)

Check warning on line 40 in internal/app/coroutines/cancelPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/cancelPromise.go#L40

Added line #L40 was not covered by tests
res(t, nil, err)
return
}
Expand Down Expand Up @@ -160,11 +160,11 @@
})
}
} else {
var status types.ResponseStatus
if p.State == promise.Canceled && p.Value.Ikey.Match(req.CancelPromise.Value.Ikey) {
status := types.ResponseForbidden
strict := req.CancelPromise.Strict && p.State != promise.Canceled

if !strict && p.Value.Ikey.Match(req.CancelPromise.Value.Ikey) {
status = types.ResponseOK
} else {
status = types.ResponseForbidden
}

res(t, &types.Response{
Expand Down
183 changes: 0 additions & 183 deletions internal/app/coroutines/completePromise.go

This file was deleted.

8 changes: 4 additions & 4 deletions internal/app/coroutines/createPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func CreatePromise(t int64, req *types.Request, res func(int64, *types.Response,
return
}

var status types.ResponseStatus
if p.Param.Ikey.Match(req.CreatePromise.Param.Ikey) {
status := types.ResponseForbidden
strict := req.CreatePromise.Strict && p.State != promise.Pending

if !strict && p.Param.Ikey.Match(req.CreatePromise.Param.Ikey) {
status = types.ResponseOK
} else {
status = types.ResponseForbidden
}

if p.State == promise.Pending && t >= p.Timeout {
Expand Down
10 changes: 5 additions & 5 deletions internal/app/coroutines/rejectPromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to read promise or read subscriptions", "req", req, "err", err)
slog.Error("failed to read promise", "req", req, "err", err)

Check warning on line 40 in internal/app/coroutines/rejectPromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/rejectPromise.go#L40

Added line #L40 was not covered by tests
res(t, nil, err)
return
}
Expand Down Expand Up @@ -160,11 +160,11 @@
})
}
} else {
var status types.ResponseStatus
if p.State == promise.Rejected && p.Value.Ikey.Match(req.RejectPromise.Value.Ikey) {
status := types.ResponseForbidden
strict := req.RejectPromise.Strict && p.State != promise.Rejected

if !strict && p.Value.Ikey.Match(req.RejectPromise.Value.Ikey) {
status = types.ResponseOK
} else {
status = types.ResponseForbidden
}

res(t, &types.Response{
Expand Down
10 changes: 5 additions & 5 deletions internal/app/coroutines/resolvePromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

c.Yield(submission, func(t int64, completion *types.Completion, err error) {
if err != nil {
slog.Error("failed to read promise or read subscriptions", "req", req, "err", err)
slog.Error("failed to read promise", "req", req, "err", err)

Check warning on line 40 in internal/app/coroutines/resolvePromise.go

View check run for this annotation

Codecov / codecov/patch

internal/app/coroutines/resolvePromise.go#L40

Added line #L40 was not covered by tests
res(t, nil, err)
return
}
Expand Down Expand Up @@ -159,11 +159,11 @@
})
}
} else {
var status types.ResponseStatus
if p.State == promise.Resolved && p.Value.Ikey.Match(req.ResolvePromise.Value.Ikey) {
status := types.ResponseForbidden
strict := req.ResolvePromise.Strict && p.State != promise.Resolved

if !strict && p.Value.Ikey.Match(req.ResolvePromise.Value.Ikey) {
status = types.ResponseOK
} else {
status = types.ResponseForbidden
}

res(t, &types.Response{
Expand Down
Loading