grpc-js: Big refactor in preparation for implementing retries #2243
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes a few related changes:
First, the
Http2CallStream
type is split into 3 composed classes: theResolvingCall
class is responsible for tracking call deadlines and for handling call configs from the name resolver. Once it gets a call config, it creates and delegates to aLoadBalancingCall
. TheLoadBalancingCall
class is responsible for invoking filters, getting headers from call credentials, calculating timeouts from deadlines, and handling pick results from the the LB policy. Once it gets a successful pick, it creates and delegates to aSubchannelCall
, which owns and manages aClientHttp2Stream
and performs most of the work thatHttp2CallStream
was originally responsible for. TheSubchannel
now has acreateCall
method that returns aSubchannelCall
, which replaces thestartCallStream
method that attached a new HTTP2 stream to an existingHttp2CallStream
object.Second, the
InnerChannel
class contains the implementation logic for the channel and methods for other classes in the library to interact with, while theChannel
class contains the public channel API and delegates to theInnerChannel
for all logic. This change and the previous one are both strongly based on the architecture of the C core.Third, pickers from LB policies can no longer provide filters. Instead, they can provide
onCallStarted
andonCallEnded
callbacks to track when individual calls start and end, including the status they end with.In addition, there are a variety of incidental changes. With responsibility for deadlines and call credentials moved out of filters, the filter behavior can be restricted, and they are no longer constructed with a reference to the call. Also, in a few instances, types, functions, and classes that were originally used in only one file are now used in multiple files, so they have been moved into their own separate files.
The first change is the most important one that facilitates adding the retry feature. The goal is to add a
RetryingCall
class thatResolvingCall
can use in place ofLoadBalancingCall
, andRetryingCall
will useLoadBalancingCall
to represent each attempt. In addition, theprogress
field thatLoadBalancingCall
adds to status objects provides information thatRetryingCall
will need to make decisions about retries.I also added retry configs to the service config type definitions. Those will be processed by
RetryingCall
.