Skip to content

Conversation

@rmichela
Copy link
Contributor

@rmichela rmichela commented Feb 8, 2017

HandlerRegistry.lookupMethod(String methodName, String authority) is never never invoked with a non-null authority string. Per the discussion on the mailing list, I implemented this method.

https://groups.google.com/forum/#!topic/grpc-io/1RPka9CKAvE

@grpc-kokoro
Copy link

Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@rmichela
Copy link
Contributor Author

rmichela commented Feb 8, 2017

@ejona86 I've implemented this PR per your recommendations on IRC.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Only small changes necessary.

It could use two tests or so.

@GuardedBy("this")
private Set<InProcessStream> streams = new HashSet<InProcessStream>();
@GuardedBy("this")
private String authority;
Copy link
Member

Choose a reason for hiding this comment

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

Make this final, and no need for the @GuardedBy then. (See comment below about the setter)

public void setAuthority(String string) {
// TODO(ejona): Do something with this? Could be useful for testing, but can we "validate"
// it?
authority = string;
Copy link
Member

Choose a reason for hiding this comment

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

This set only impacts this one stream. So add another field for the authority to the stream. You can initialize it from the transport's value.

private String getOrUpdateAuthority(AsciiString authority) {
if (authority == null) {
return "";
} else if (lastKnownAuthority == null || !lastKnownAuthority.equals(authority)) {
Copy link
Member

Choose a reason for hiding this comment

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

If you invert the equals check you can avoid the null check. !authority.equals(lastKnownAuthority)

}

@Override
public String getAuthority() {
Copy link
Member

Choose a reason for hiding this comment

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

Given that HandlerRegistry is the only thing that is using the value from getAuthority() currently, and it is @Nullable, I would still feel better by defaulting to null. Here and in NettyServerHandler.

It's something we can change in the future though. We'll probably deal with it when we expose getAuthority() on ServerCall. At that point we may make it non-null where empty string is explicitly called out in the API.

@rmichela
Copy link
Contributor Author

rmichela commented Feb 8, 2017

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

private Set<InProcessStream> streams = new HashSet<InProcessStream>();

public InProcessTransport(String name) {
public InProcessTransport(String name, String authority) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be API breaking.

Copy link
Member

Choose a reason for hiding this comment

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

No, it isn't. InProcessTransport itself is package-private.

public void setAuthority(String string) {
// TODO(ejona): Do something with this? Could be useful for testing, but can we "validate"
// it?
InProcessStream.this.authority = string;
Copy link
Contributor

Choose a reason for hiding this comment

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

This would not be thread safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InProcessStream.this.authority is now volatile. Setting and reading references are atomic in Java. Strings are immutable. This should be thread safe now, right?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it was fine as it was before (without volatile). setAuthority "May only be called before start."

@rmichela
Copy link
Contributor Author

rmichela commented Feb 9, 2017

@ejona86 @carl-mastrangelo Test cases added and feedback addressed.

@rmichela
Copy link
Contributor Author

rmichela commented Feb 9, 2017

I can't reproduce the serverNotListening test failure. I think it's a flapping test.

@ejona86
Copy link
Member

ejona86 commented Feb 9, 2017

Jenkins, okay to test.

@ejona86
Copy link
Member

ejona86 commented Feb 10, 2017

okay to test

lastKnownAuthority = authority;
}

// AsciiString.toString() is internally cached, so subsequent calls will not
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not efficient enough. If the client changes the authority every request and the server doesn't read from it, it will unnecessarily convert it. Why not do the conversion when getAuthority is called?

Copy link
Member

Choose a reason for hiding this comment

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

getAuthority() is always called.

This is plenty efficient enough. It doesn't hinder the common case at all.

Most clients, by far, won't change the authority every request. And even if they do change constantly, then any optimization here would probably be in the noise.

I'd rather get to a point we can call good enough for now and any future optimization for edge cases gets included with the HPACK tricks we're planning.

Copy link
Member

Choose a reason for hiding this comment

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

I talked with Carl. He showed me that getAuthority() isn't always called, since it is only called when the immutable lookup fails. But we also agreed that it will 99% of the time always be the same authority. And we also believe that the HPACK table will even make it the same AsciiString instance. So Carl is now okay with this. He would still like to have our nice HPACK stuff, but that's orthogonal and future work.

@ejona86 ejona86 merged commit 4029b3f into grpc:master Feb 11, 2017
@ejona86
Copy link
Member

ejona86 commented Feb 11, 2017

Thank you for implementing this! I'm sorry that I didn't do it initially, but I'm glad you were able to.

@rmichela rmichela deleted the feature/HandlerRegistry-authority2 branch February 13, 2017 17:33
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants