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

Minogrpc refactoring #47

Merged
merged 9 commits into from
May 25, 2020
Merged

Minogrpc refactoring #47

merged 9 commits into from
May 25, 2020

Conversation

Gilthoniel
Copy link
Contributor

This refactors minogrpc to reduce the amount of code. It also implements an infinite buffered receiver to prevent the relay from stalling. Finally, it adds unit tests.

@Gilthoniel Gilthoniel added enhancement New feature or request mod/mino About the Mino module R4M 🚀 The PR is ready to be reviewed and merged labels May 19, 2020
@Gilthoniel Gilthoniel requested a review from nkcr May 20, 2020 12:27
Copy link
Contributor

@nkcr nkcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some random thoughts, to be discussed in live

server *Server
namespace string
// rootAddress is the address of the orchestrator of a protocol. When Stream is
// called, the caller takes this address so that participants now how to route
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// called, the caller takes this address so that participants now how to route
// called, the caller takes this address so that participants know how to route

return rootAddress{}
}

// Equal implements mino.Address. It returns true the other address is also a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Equal implements mino.Address. It returns true the other address is also a
// Equal implements mino.Address. It returns true if the other address is also a

mino/minogrpc/mod.go Show resolved Hide resolved
mino/minogrpc/routing/routing.go Show resolved Hide resolved
},
}

if s.me != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why s.me would be nil?

}

func (q *NonBlockingQueue) pushAndWait() {
q.working.Add(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now it's only used in the tests but the purpose is to make sure the go routine has stopped.

@@ -60,46 +97,129 @@ type AddressFactory struct{}
// FromText implements mino.AddressFactory. It returns an instance of an
// address from a byte slice.
func (f AddressFactory) FromText(text []byte) mino.Address {
return address{id: string(text)}
if len(text) == 0 {
return newRootAddress()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making an empty address default to the root address looks a bit dangerous to me. IMO the root address should be explicit and a not the default option when an address is empty. For example someone could provide an address that for some unwanted reason is empty but not intended to be used as the root. But in this case there won't be any error but there might be a side effect difficult to debug.

}

// NewMinogrpc sets up the grpc and http servers. URL should
func NewMinogrpc(serverURL *url.URL, rf routing.Factory) (*Minogrpc, error) {
// Minogrpc represents a grpc service restricted to a namespace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- implements mino.Mino

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the struct definition.

closing: make(chan error, 1),
}

// Counter needs to be above 1 for asynchronous call to Add.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Counter needs to be above 1 for asynchronous call to Add.
// Counter needs to be >=1 for asynchronous call to Add.

rpc Call(Envelope) returns (Envelope) {}
rpc Stream(stream Envelope) returns (stream Envelope) {}
rpc Call(Message) returns (Message) {}
rpc Relay(stream Envelope) returns (stream Envelope) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would keep stream as the name

mino/minogrpc/routing/routing.go Show resolved Hide resolved
errs <- xerrors.Errorf("couldn't unmarshal message: %v", err)
continue
}
req := mino.Request{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am suddenly wondering: why don't we use the same type of return for streaming? Right now its

Recv(context.Context) (Address, proto.Message, error)

but shouldn't it be

Recv(context.Context) (Request, error)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, will do after the PR.

}

sendMsg := &Envelope{
Message: m,
apiURI := headers[headerURIKey]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri := uriFromContext(ctx)
...

Comment on lines 189 to 190
// This should never and it will panic if it does as this will provoke
// several issues later on.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This should never and it will panic if it does as this will provoke
// several issues later on.
// This should never happen and it will panic if it does as this will
// provoke several issues later on.

Comment on lines 268 to 263
func (o overlay) setupStream(stream relayer, sender *sender, receiver *receiver, addr mino.Address) {
// Relay sender for that connection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (o overlay) setupStream(stream relayer, sender *sender, receiver *receiver, addr mino.Address) {
// Relay sender for that connection.
func (o overlay) setupStream(stream relayer, sender *sender, receiver *receiver,
addr mino.Address) {
// Relay sender for that connection.

mino/minogrpc/stream.go Show resolved Hide resolved
@nkcr nkcr merged commit ed91ef5 into master May 25, 2020
@nkcr nkcr deleted the minogrpc_relay branch May 25, 2020 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mod/mino About the Mino module R4M 🚀 The PR is ready to be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants