Skip to content

Split-state AbstractStream; sending and receiving - #1656

Merged
ejona86 merged 1 commit into
grpc:masterfrom
ejona86:split-abstractstream
May 23, 2016
Merged

ejona86 merged 1 commit into
grpc:masterfrom
ejona86:split-abstractstream

Conversation

@ejona86

@ejona86 ejona86 commented Apr 11, 2016

Copy link
Copy Markdown
Member

Note to reviewers: You may want to start with NettyServerStream to help
give a grounding to understand the other changes.

Note also that I don't consider this to be an alternative to #1135. I feel
this PR is a stepping stone in order to do things like #1135. My main
concern during review is to avoid rabbit holing. I know there's many things
I could have done and that will become more obvious due to this PR.
But I really don't want to get too side-tracked on those things and instead
focus more on whether this PR allows us to discuss and implement those
other things easier.

I know there's places that could use more docs, but I didn't feel they
were likely very necessary during initial review. I'm happy to add more
docs if it seems like the changes are well accepted. Included in that is
porting AbstractStream's tests to AbstractStream2.


This introduces an AbstractStream2 that is intended to replace the
current AbstractStream. Only server-side is implemented in this commit
which is why AbstractStream remains. This is mostly a reorganization of
AbstractStream and children, but minor internal behavioral changes were
required which makes it appear more like a reimplementation.

A strong focus was on splitting state that is maintained on the
application's thread (with Stream) and state that is maintained by the
transport (and used for StreamListener). By splitting the state it makes
it much easier to verify thread-safety and to reason about interactions.

I consider this a stepping stone for making even more changes to
simplify the Stream implementations and do not think some of the changes
are yet at their logical conclusion. Some of the changes may also
immediately be replaced with something better. The focus was to improve
readability and comprehesibility to more easily make more interesting
changes.

The only thing really removed is some state checking during sending
which is already occurring in ServerCallImpl.

this.writeQueue = handler.getWriteQueue();
public NettyServerStream(Channel channel, TransportState state) {
super(new NettyWritableBufferAllocator(channel.alloc()));
this.state = checkNotNull(state, "transportState");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: s/transportState/state/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I purposefully was more verbose in the string, since "state must not be null" can be misunderstood as being useless (which state‽).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok with me. thought it was a leftover from a variable rename. I think either way is fine, as the resulting exception does contain a stacktrace, so it's easy to find out which state.

@buchgr

buchgr commented Apr 11, 2016

Copy link
Copy Markdown
Contributor

@ejona86 I like your changes. Much cleaner. Overall, looks good to me, to the extend that I understand all the implications 😄

*
* @param <IdT> the type of the stream identifier
* Abstract base class for {@link ServerStream} implementations. Extending classes only need to
* implement transportState() and abstractServerStreamSink().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: {@link #transportState}, {@link #abstractServerStreamSink}. I like the naming of abstractServerStreamSink btw ;-).

@ejona86

ejona86 commented May 2, 2016

Copy link
Copy Markdown
Member Author

I've addressed @buchgr's comments. Now that we've done the 0.14 release, I think I'm going to try to push this through a bit more.

@ejona86

ejona86 commented May 3, 2016

Copy link
Copy Markdown
Member Author

@buchgr, from discussing with others you are going to be the "primary" reviewer, in case you want to look a little closer for any reason.

@louiscryan and @nmittler, you may want to take a glance over this.

}

/**
* Only called from transport thread (except for private interactions with AbstractStream2).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: use {@code AbstractStream2} in any javadocs to help with the future rename?

@nmittler

nmittler commented May 3, 2016

Copy link
Copy Markdown

@ejona86 I took a quick look ... AbstractStream2 and TransportState do a reasonable job of clarifying the calling thread. LGTM

@ejona86

ejona86 commented May 3, 2016

Copy link
Copy Markdown
Member Author

@carl-mastrangelo, you may want to take a glance over this.

@@ -0,0 +1,261 @@
/*
* Copyright 2014, Google Inc. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

version

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Believe it or not, this started as copy of AbstractStream.java. The only reason it is a new file is to avoid updating client-side at the same time. I'd just assume leave the year alone.

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