Commit Graph

650 Commits

Author SHA1 Message Date
Carl Mastrangelo 71967622d6
core, netty: add io.perfmark Annotations
This add perfmark annotations in some key places, notably on transport/application boundaries, and thread hop locations. Perfmark records to a thread-local buffer the events that happen in each thread. Perfmark is disabled by default, and will compile to a noop unless Perfmark.setEnabled is invoked. This should make it free when disable, and pretty fast when it is enabled.

It is important that started tasks are ended, so several places in our code are moved to either try-finally blocks, or moved into a private method. I realize this is ugly, but I think it is manageable. In the future, we can look at making an agent or compiler plugin that simplifies the recording.

Linking between threads is done with a Link object, which is created on the "outbound" task, and used on the "inbound" task. This is slightly more verbose, and does has a small amount of runtime overhead, even when disabled. (for null checks, slightly higher memory usage, etc.) I think this is okay to, because it makes other optimizations much easier.
2019-06-06 17:58:49 -07:00
Carl Mastrangelo 8536832232
core,netty: expose server stream id 2019-06-06 13:52:22 -07:00
Carl Mastrangelo 7657523b28
all: update to error prone 2.3.3 2019-06-05 15:28:43 -07:00
Carl Mastrangelo 4e5e19f6fd
Revert "netty: change server to new protocol negotiator model" (#5798)
This reverts commit f94b77c87f.
2019-05-28 21:12:25 -07:00
Eric Anderson 2cbc540cb3 Remove deprecated enableKeepAlive API from transports
As mentioned in 5188[1], the default used with the enableKeepAlive API
conflicted with the default server enforcement. Instead of fixing it,
remove it. These APIs were deprecated in v1.3.0 in April 2017.

1. https://github.com/grpc/grpc-java/issues/5188#issuecomment-482269303
2019-05-28 16:37:02 -07:00
Carl Mastrangelo 7834a50525
alts: use new ProtocolNegotiator style for ALTS
This change does a few core things, which result in a lot of churn in other parts.  It's not as bad as it seems.

Core things:

1.  AltsProtocolNegotiator is now a shim class, same as ProtocolNegotiators
2.  The protocol negotiators are now in the new style, where there is at most 1 negotiation handler in the pipe at a time.
3.  TsiHandshakeHandler is rewritten with respect to the above.  All errors and buffering are handled by the WBAEH.
4.  TsiFrameHandler is only installed once the negotiation is successful, eliminating the state handling.


The churn in mainly in GoogleDefaultChannel and the GCE channel, which now reuse the *handlers* rather than the negotiators.  This makes it significantly easier to reason about the pipeline state.  The tests are also a source of churn, which no long need to check for most buffering and error conditions.
2019-05-22 16:33:07 -07:00
Carl Mastrangelo f94b77c87f
netty: change server to new protocol negotiator model
Changes:

* PlaintextProtocolNegotiator is the same between client and server
* ServerTlsHandler is rewritten to not handle errors 
  * Also, it now sets the security level attribute, which I don't think it did previously
* NettyServerTransport now uses WBAEH, similar to the client. I don't think the buffer is needed, but it does  correctly handle errors during the startup
2019-05-16 18:15:47 -07:00
Carl Mastrangelo ae4d7a944a
netty: provide methods for logging protocol negotiation 2019-05-10 18:22:32 -07:00
NickUfer 6807f39155 Removes the class `io.grpc.internal.MoreThrowables` and replaces it with
`com.google.common.base.Throwables`
2019-05-02 14:23:09 -07:00
Jihun Cho f4fb7b40c5
netty: set NettyServer default socket options for all Channels (#5651) 2019-05-01 11:29:03 -07:00
Jihun Cho 6a32c508b8
netty: fix TCP_USER_TIMEOUT to use keepAliveTimeout instead of keepAliveTime (#5645) 2019-04-26 16:02:58 -07:00
Jihun Cho 67ef8c3466
netty: not using reflection to create NioEventLoopGroup (#5630) 2019-04-23 16:45:19 -07:00
Carl Mastrangelo 04e07034f3
all: update to truth 0.44 2019-04-23 10:50:49 -07:00
Jihun Cho dc0171839a
netty: add internal API to fall back to NIO transport (#5611) 2019-04-18 13:49:55 -07:00
Jihun Cho 2cdaac2adc
netty: maybe set TCP_USER_TIMEOUT when epoll and keepalive is enabled (#5599) 2019-04-18 10:12:36 -07:00
Eric Anderson 80c3c992a6 core: Move io.grpc to grpc-api
io.grpc has fewer dependencies than io.grpc.internal. Moving it to a
separate artifact lets users use the API without bringing in the deps.
If the library has an optional dependency on grpc, that can be quite
convenient.

We now version-pin both grpc-api and grpc-core, since both contain
internal APIs.

I had to change a few tests in grpc-api to avoid FakeClock. Moving
FakeClock to grpc-api was difficult because it uses
io.grpc.internal.TimeProvider, which can't be moved since it is a
production class. Having grpc-api's tests depend on grpc-core's test
classes would be weird and cause a circular dependincy. Having
grpc-api's tests depend on grpc-core is likely possible, but weird and
fairly unnecessary at this point. So instead I rewrote the tests to
avoid FakeClock.

Fixes #1447
2019-04-16 21:45:40 -07:00
Carl Mastrangelo f3731eabb3
netty: deflake ping flow control logic 2019-04-16 13:17:59 -07:00
Jihun Cho a48ebb1616
netty: change default transport to Epoll if available, otherwise using Nio (#5581)
Motivation:
To support TCP_USER_TIMEOUT(proposal). Nio doesn't support TCP_USER_TIMEOUT while Epoll and KQueue supports TCP_USER_TIME. Since most users/servers are using linux based system, adding Epoll is necessary. KQueue maybe supported later, but not in this PR.

To make it backward compatible for cases where channelType and eventLoop is mixed in with default and user provided object(s), we will fallback to Nio (NioSocketChannel, NioEventLoop). This ensures not breaking existing code (same as existing behavior). Users not specified both channelType and EventLoops will be affect by this Epoll change if netty-epoll is available.
In later version (possibly 1.22.0), the backward compatible behavior will be removed and it will start to throw exception since this is error prone.
2019-04-15 17:53:14 -07:00
Carl Mastrangelo 21141cc837
netty: make default number of event loops defer to netty 2019-04-12 12:42:18 -07:00
Jihun Cho 3b8088833c
netty, alts: expose ProtectedPromise, and writeBufferedAndRemove methods (#5542) 2019-04-04 19:01:54 -07:00
Eric Anderson 73bade418b netty: ALPN negotiation failure should be UNAVAILABLE, not UNKNOWN 2019-04-04 15:33:06 -07:00
Tim van der Lippe d35fbd7eee all: Update to Mockito 2
This is the public port of cl/238445847

Fixes #5319
2019-03-19 14:17:52 -07:00
Fabio Kung 7df2d5feeb netty: default grace time for RPCs can leak memory
Using Long.MAX_VALUE as the delay for Netty's NioEventLoop#schedule can
cause (long) deadlines for scheduled tasks to wrap into negative values,
which is unspecified behavior. Recent versions of netty are guarding
against overflows, but not all versions of grpc-java are using a recent
enough netty.

When connections are gracefully closed, Netty's Http2ConnectionHandler
sets up a timeout task forcing resources to be freed after a grace
period. When their deadlines wrap into negative values, a race was
observed in production systems (with grpc-java <= 1.12.1) causing Netty
to never properly release buffers associated with active streams in the
connection being (gracefully) closed.
2019-03-18 12:38:54 -07:00
Carl Mastrangelo 5cc71f1de9
netty, core: pass log-only channel logger into transport 2019-03-06 11:49:42 -08:00
Carl Mastrangelo 07d7b99e31
netty: expose methods of ProtocolNegotiationEvent through accessor 2019-03-06 10:59:41 -08:00
Carl Mastrangelo d833767037
netty: expose some of the reusable handlers in ProtocolNegotiators 2019-03-05 11:29:32 -08:00
Carl Mastrangelo 3ffec383e3
netty: make WaitUntilActiveHandler not check if the channel is active 2019-03-05 10:29:38 -08:00
Carl Mastrangelo 801cc5c189
core,netty,okhttp: propagate the subchannel logger to the transport 2019-03-04 15:16:53 -08:00
Carl Mastrangelo 3bae61e83b
netty: switch plaintext upgrade negotiator to new format 2019-03-04 14:48:28 -08:00
Kun Zhang 59a336c3ae
core: add internal transport attribute ATTR_CLIENT_EAG_ATTRS (#5420)
This is needed for GRPCLB pick_first support, which needs to attach
tokens to headers, and the tokens are per server. In pick_first, all
addresses are in a single Subchannel, thus the LoadBalancer needs to
know which backend is used for a new stream.
2019-03-04 12:38:26 -08:00
ZHANG Dapeng 0665af289a
netty: fix lint 2019-03-04 09:40:42 -08:00
Carl Mastrangelo 5cfff5bfce
netty: replace TLS protocol negotiator with new style handlers 2019-03-01 11:37:07 -08:00
Eric Anderson a818c81a71 testing: Move AbstractTransportTest to core to avoid Truth dep
Fixes #5301
2019-02-28 21:33:19 -07:00
Kun Zhang 83b92cfc9f
core: pass transport attributes to ClientStreamTracer.Factory.newClientStreamTracer() (#5380)
This will be a new override.  The old override is now deprecated.

In order to pass new information without adding new overrides, I shoved most information
into an object called StreamInfo.  The Metadata is left out to draw attention because
it's mutable.

Motivation: this is needed for correctly supporting pick_first in GRPCLB.  GRPCLB needs to
add a token to the headers, and the token varies among servers.  With round_robin, GRPCLB
create a Subchannel for each server, thus can attach the token when the Subchannel is picked.
To implement pick_first, all server addresses will be put in a single Subchannel, we will
need to add the header in newClientStreamTracer(), by looking up the server address from
the transport attributes and deciding which token to add.
2019-02-21 11:13:51 -08:00
David Hoover d44d015c44 doc: Fix typo 2019-02-20 16:40:57 -08:00
Jihun Cho 5f60f22b6a netty: prevent IndexOutOfBoundsException when no handler is passed to BufferingHandler 2019-02-15 15:18:48 -08:00
Carl Mastrangelo 8e6fa122a6
netty,alts: hide ProtocolNegotiator behind an accessor, and...
...and move the `close()` method to ProtocolNegotiator rather than Handler.

Since this is a breaking change (for people who ignored our `@Internal` annotations), I wanted to make both changes in the same PR so as to fix them both at the same time.
2019-02-15 13:59:58 -08:00
Carl Mastrangelo bb394132bd
netty: limit access to ProtocolNegotiators 2019-02-12 19:59:15 -08:00
Carl Mastrangelo e5008e53fe
netty: always use double goaway for shutdown 2019-02-12 14:40:52 -08:00
Kun Zhang e875a8c6a3
core: introduce NameResolver.Helper and deprecate the params on newNameResolver() (#5345)
Context: [#4159 (comment)](https://github.com/grpc/grpc-java/issues/4159#issuecomment-415827641)

`Attributes` is appropriate for plumbing optional objects, especially useful for a long plumbing path where components in the middle may not care or see all objects in the container. It's not the case for the `params` on `newNewResolver()`. Both the default port and the proxy detector are guaranteed to be there and the plumbing path is very short. In this case, a first-class object is more appropriate and easier to use.

The `Helper` will also have `getSynchronizationContext()` (#2649) and a method to parse and validate service config. We we also considering merging `Listener` into the `Helper`, to make `NameResolver` match the `LoadBalancer` API.
2019-02-12 10:14:59 -08:00
Kun Zhang 138e958c4a
core: ProxiedSocketAddress on public API (#5344)
Combine the public `ProxyParameters` and the internal `ProxySocketAddress` as `HttpConnectProxiedSocketAddress`. The more specific name signifies the type of the proxy we currently support, and makes room for other proxy types (e.g., SOCKS) in the future. The combination simplifies NameResolver implementation.

Introduce `ProxiedSocketAddress` as the base class that is returned by `ProxyDetector`, mainly for clarification and documentation. Added documentation about proxy in general on `ProxyDetector`.
2019-02-11 09:56:59 -08:00
Carl Mastrangelo dc5ec9743a
netty: add a channel active handler 2019-02-07 10:22:12 -08:00
Carl Mastrangelo f6ec07d87d
core,netty: expose listening on multiple ports 2019-02-06 15:49:59 -08:00
Jihun Cho 71d067e8f5
netty: add channelFactory to NettyChannelBuilder (#5312)
add channelFactory in NettyChannelBuilder & NettyClientTransport
2019-02-04 10:51:23 -08:00
Carl Mastrangelo 3a39b81cf5
all: remove java6 type args 2019-02-04 10:03:50 -08:00
Tim van der Lippe a31473ef20 all: fix usages of any(<Primitive>.class) matchers
In Mockito 2, if a method expects a primitive type, but an any(<Primitive>.class) matcher is used in its place, it will throw an error. To prepare for this upcoming breakage, change
all existing any(<Primitive>.class) matchers to use the correct any<Primitive>() matcher.
2019-02-04 09:01:00 -08:00
Jihun Cho 1c3432c3fb
all: migrate gradle publish from maven to use maven-publish plugin (#5289) 2019-01-31 17:38:43 -08:00
ZHANG Dapeng d0ecc08705
all: fix lint 2019-01-31 09:31:13 -08:00
Carl Mastrangelo ed0a9f3f1d
netty: support listening on multiple ports 2019-01-29 10:13:40 -08:00
Carl Mastrangelo f6689a1f86
all: fix lint errors 2019-01-25 16:09:59 -08:00