Commit Graph

283 Commits

Author SHA1 Message Date
Eric Anderson 27dffdfe03 netty: call transportShutdown immediately on ID exhaustion
Fixes #1819
2016-05-13 13:39:47 -07:00
Kun Zhang 95973827f5 Refactor HandlerRegistry.
See #933

- Create InternalHandlerRegistry, an immutable look-up table. Handlers
  passed to ServerBuilder.addService() go to this registry. This covers
  the most common use cases. By keeping the registry internal we could
  freely change the registry's interface to accommodate optimizations,
  e.g., for hpack.

- The internal registry uses a flat fullMethodName -> handler look-up
  table instead of a hierarchical one used before. It faster because it
  saves one look-up and a substring.

- Introduces the fallback registry, settable by
  ServerBuilder.fallbackHandlerRegistry(), for advanced users who want a
  dynamic registry. Moved the current MutableHandlerRegistryImpl to
  io.grpc.util.MutableHandlerRegistry as a stock implementation of the
  fallback registry. The io.grpc.MutableHandlerRegistry interface is now
  removed.
2016-05-04 17:12:32 -07:00
Carl Mastrangelo bc661e7fbb all: Finish adding tracking issues for ExperimentalApi 2016-05-03 16:15:57 -07:00
Carl Mastrangelo c6faf3541b Add a log message for unknown client streams 2016-05-02 14:04:19 -07:00
ZHANG Dapeng aed886d8de use Jetty ALPN agent instead of Jetty ALPN
#1497
2016-05-02 14:01:36 -07:00
Eric Anderson 80baa631a7 Use return value of Status.augmentDescription 2016-05-01 08:11:45 -07:00
ZHANG Dapeng 804991e80d validate sslContext in Netty channel/server builder #1699 (#1724)
validate sslContext in Netty channel/server builder #1699

resolves #1699
2016-04-27 13:02:43 -07:00
Carl Mastrangelo 38a91f83e1 Fix lint warnings found on internal import 2016-04-26 13:21:25 -07:00
Carl Mastrangelo 00f8f349b2 Don't allocate extra byte for each MessageFramer 2016-04-21 10:48:53 -07:00
Carl Mastrangelo d0d946ec9f new name 2016-04-18 16:21:53 -07:00
Carl Mastrangelo c4e8b1f10f Rename internal.Server to internal.TransportServer 2016-04-18 15:50:20 -07:00
Eric Anderson 6ab27aba13 Update checkstyle version and sync style updates 2016-04-18 09:15:25 -07:00
Carl Mastrangelo 51fd870cfd Add getting the port out of a Server 2016-04-13 13:54:45 -07:00
nmittler 22e719a5f9 Convert Netty IOExceptions to UNAVAILABLE.
Also inspecting the entire causal chain to identify the best possible Status.

Fixes #1053
Fixes #1522
2016-04-13 11:47:58 -07:00
Carl Mastrangelo 0ed059a408 Add rst error detail in OkHttp 2016-04-08 13:19:14 -07:00
Carl Mastrangelo 7d889b6911 Reuse metadata array when making http2 headers, and reduce some array copies 2016-04-08 13:08:07 -07:00
Kun Zhang 6a55e2990b Force thread group on threads created by Netty's DefaultThreadFactory.
As a workaround for https://github.com/netty/netty/issues/5084
2016-04-06 14:30:21 -07:00
Eric Anderson 2a5a41b600 Fix UNAVAILABLE codes missing descriptions
All status codes we generate from the library should have more
information available, either in the description or as a cause.
2016-03-31 09:51:33 -07:00
Kun Zhang 49b462784f Raise visibility of NettyTransportFactory to protected.
It's needed by internal code.
2016-03-29 12:06:18 -07:00
Carl Mastrangelo 65d3847d14 Remove references to Throwable.propagate 2016-03-22 15:47:52 -07:00
Lukasz Strzalkowski c3011b0798 Move server call keys to ServerCall class 2016-03-17 19:46:26 -04:00
buchgr d927180a63 Use Netty's DefaultThreadFactory instead of Guava's ThreadFactoryBuilder.
So far, we have passed a custom Executor to the NioEventLoopGroup constructor,
in order to get custom thread names and be compatible with both Netty 4 and
Netty 5. However, Netty 5 is no more (RIP) and Netty's DefaultThreadFactory
includes some optimizations around thread local storage, that Guava's executor
does not have.

The thread names will be a bit different, as DefaultThreadExecutor additionally
puts in the thread pool id after the name prefix.

For example:

Before:
grpc-default-boss-ELG-0
grpc-default-worker-ELG-0
grpc-default-worker-ELG-1

After:
grpc-default-boss-ELG-0-0
grpc-default-worker-ELG-1-0
grpc-default-worker-ELG-1-1
2016-03-17 00:43:26 +01:00
buchgr 3c68c053f7 Remove ReferenceCounted and add close() to ClientTransportFactory. Fixes #927 2016-03-17 00:31:04 +01:00
Lukasz Strzalkowski 6a67a97a73 Add attributes to ServerCall 2016-03-16 15:39:42 -07:00
Kun Zhang b9c12327eb Add log ID.
To ManagedChannelImpl, TransportSet and all client transport
implementations, so they can be correlated in the logs. Also added more
life-cycle logging in general.
2016-03-09 13:52:32 -08:00
Eric Anderson d192f1a6cb netty: GOAWAY should trigger transportShutdown
Long-lived streams or lengthy RPCs can keep the transport open for
minutes after a GOAWAY is received. Previously, during this time any new
RPCs would fail with a message like:

> Cannot create stream 5 since this endpoint has received a GOAWAY frame
> with last stream id 3

All usages of goAwayStatus were replaced with lifecycleManager. Although
note that previously goAwayStatus() would never return null because it
would generate a Status if the current field was null.
getShutdownStatus() does not have this feature, so some code was
rearranged to guarantee the Status is non-null before retrieving it.

The listener handling was simplified by 1) avoiding the need for
thread-safety and 2) moving state keeping into a small class for easy
comprehensibility and simplified usage in tests.

NettyClientTransport.shutdown() no longer calls transportShutdown()
because it lies (because the message can be delayed for quite some time)
and because it was the only usage of lifecycleManager not on the event
loop.

Fixes #1359
2016-03-07 09:35:18 -08:00
Eric Anderson 3528467612 Treat ClosedChannelException as UNAVAILABLE to squelch test failures
Our tests are detecting cases where we are still getting
ClosedChannelException. We need to fix that because it is a useless
status, but until it is fixed we want a stable CI.

Fixes #1513 and NettyTransportTest.serverNotListening failures
2016-03-03 14:18:34 -08:00
Eric Anderson 1170afd168 Add transport test for Netty
Netty client shutdown would race with the negotiation handling and
circumvent AbstractBufferingHandler. Use a new command in order to
leave channel.close() available for abrupt killing of the connection
when connecting.

ping_afterTermination was previously racey that made it succeed. After
fixing the test, Netty would consistently fail to call callback. After
fixing Netty to fail the callback it was not using the right status
because when Netty's channel is closed none of our handlers are run.
This reliably fails the future with ClosedChannelException, which is
useless, so now we special-case that exception and fill in the reason
for shutdown.

To prevent accidentally reporting Status.OK, the transports no longer
use OK when calling transportShutdown. The OK status was already no
longer being consumed, since keying off whether transportReady was
called is more helpful.

This fixes #1330
2016-03-01 17:43:30 -08:00
Kun Zhang d86dfc9552 Merge DelayedStream's setError() into cancel()
DelayedClientTransport.PendingStream will override cancel(), which has a
clearer semantic.

Also permitting all status codes except OK in ClientStream.cancel(),
instead of just 4 codes.
2016-02-25 11:28:48 -08:00
nmittler 86fd2523ec Update to latest netty and tcnative. 2016-02-20 14:50:06 -08:00
nmittler 5cef321b78 Use Netty's StreamBufferingEncoder
Fixes #1060
2016-02-19 11:29:28 -08:00
Trask Stalnaker c10f5781b9 Fix sporadic NullPointerException
Fixes #1426
2016-02-18 21:43:43 -08:00
Eric Anderson 8d43880356 hpack is no longer a direct dependency
It isn't even a dependency of Netty, now that Netty has forked the code.
2016-02-16 14:54:17 -08:00
Eric Anderson b752e76858 Automated readability/efficiency tweaks
Although the changes were determined automatically, they were manually
applied to the codebase.

ClientCalls actually has a bug fix, since the suggestion to add
interrupt() made it obvious that interrupted() was inappropriate.
2016-02-16 14:15:23 -08:00
Eric Anderson a3303b51ec Delete unused CancelStreamCommand 2016-02-16 11:45:29 -08:00
Carl Mastrangelo 2d2398ce3a d'oh, really raise the visibility 2016-02-16 10:55:24 -08:00
Carl Mastrangelo acdcd5b114 Raise visibility of netty Channel Builder, and provide a way to pass in a custom protocol negotiator per transport 2016-02-16 10:39:20 -08:00
Kun Zhang cf787bddf2 DelayedClientTransport and fix TransportSet.shutdown() semantics.
Always return a completed future from `TransportSet`. If a (real) transport has not been created (e.g., in reconnect back-off), a `DelayedClientTransport` will be returned.

Eventually we will get rid of the transport futures everywhere, and have streams always __owned__ by some transports.

DelayedClientTransport
----------------------

After we get rid of the transport future, this is what `ClientCallImpl` and `LoadBalancer` get when a real transport has not been created yet. It buffers new streams and pings until `setTransport()` is called, after which point all buffered and future streams/pings are transferred to the real transport.

If a buffered stream is cancelled, `DelayedClientTransport` will remove it from the buffer list, thus #1342 will be resolved after the larger refactoring is complete.

This PR only makes `TransportSet` use `DelayedClientTransport`. Follow-up changes will be made to allow `LoadBalancer.pickTransport()` to return null, in which case `ManagedChannelImpl` will give `ClientCallImpl` a `DelayedClientTransport`.

Changes to ClientTransport shutdown semantics
---------------------------------------------

Previously when shutdown() is called, `ClientTransport` should not accept newStream(), and when all existing streams have been closed, `ClientTransport` is terminated. Only when a transport is terminated would a transport owner (e.g., `TransportSet`) remove the reference to it.

`DelayedClientTransport` brings about a new case: when `setTransport()` is called, we switch to the real transport and no longer need the delayed transport. This is achieved by calling `shutdown()` on the delayed transport and letting it terminate. However, as the delayed transport has already been handed out to users, we would like `newStream()` to keep working for them, even though the delayed transport is already shut down and terminated.

In order to make it easy to manage the life-cycle of `DelayedClientTransport`, we redefine the shutdown semantics of transport:
- A transport can own a stream. Typically the transport owns the streams
  it creates, but there may be exceptions. `DelayedClientTransport` DOES
  NOT OWN the streams it returns from `newStream()` after `setTransport()`
  has been called. Instead, the ownership would be transferred to the
  real transport.
- After `shutdown()` has been called, the transport stops owning new
  streams, and `newStream()` may still succeed. With this idea,
  `DelayedClientTransport`, even when terminated, will continue
  passing `newStream()` to the real transport.
- When a transport is in shutdown state, and it doesn't own any stream,
  it then can enter terminated state.

ManagedClientTransport / ClientTransport
----------------------------------------

Remove life-cycle interfaces from `ClientTransport`, and put them in its subclass - `ManagedClientTransport`, with the same idea that we have `Channel` and `ManagedChannel`. Only the one who creates the transport will get `ManagedClientTransport` thus is able to start and shutdown the transport. The users of transport, e.g., `LoadBalancer`, can only get `ClientTransport` thus are not alter its state. This change clarifies the responsibility of transport life-cycle management.

Fix TransportSet shutdown semantics
-----------------------------------

Currently, if `TransportSet.shutdown()` has been called, it no longer create new transports, which is wrong.

The correct semantics of `TransportSet.shutdown()` should be:
- Shutdown all transports, thus stop new streams being created on them
- Stop `obtainActiveTransport()` from returning transports
- Streams that already created, including those buffered in delayed transport, should continue. That means if delayed transport has buffered streams, we should let the existing reconnect task continue.
2016-02-12 09:36:25 -08:00
Eric Anderson 964963ab1a Replace AUTHORITY_KEY with ClientStream.setAuthority 2016-02-10 17:26:51 -08:00
Carl Mastrangelo 3f9e486e0d Raise visibility of Netty Channel Builder Ctor 2016-02-10 10:52:18 -08:00
Eric Anderson 5b9726ea7d netty: release buffered objects when failed
Releasing on failure prevents memory leak.

Fixes #1401
2016-02-10 09:36:54 -08:00
Eric Anderson 3d3fd11378 Negotiation Handlers should implement ChannelHandler
Having Handler implement ChannelInboundHandler is overspecifying and
unnecessary, as the code compiles fine just by changing "implements
ChannelInboundHandler" to "implements ChannelHandler".

PlaintextHandler was swapped to ChannelHandlerAdapter instead of
ChannelDuplexHandler because it just needs the ChannelHandler methods.
2016-02-04 14:02:57 -08:00
Carl Mastrangelo 04a6c8395b Remove deprecated call and TODO in Protocol negotiators 2016-02-04 13:39:56 -08:00
Eric Anderson 7e3d0fe9cc Mark ChannelHandler.exceptionCaught implementation deprecated to fix warning
This just propagates the deprecated annotation from ChannelHandler. Note
that exceptionCaught is _not_ deprecated for ChannelInboundHandler and
ChannelDuplexHandler.
2016-02-01 13:14:13 -08:00
Carl Mastrangelo a3c79e87ae Add a simple compression API 2016-02-01 12:56:21 -08:00
Carl Mastrangelo ba4a6ca47b Update to netty 4.1.0.CR1 2016-01-29 17:55:18 -08:00
nmittler 70ef5b1172 Make handling of GoAwayClosedStreamException more consistent. 2016-01-26 11:39:06 -08:00
Carl Mastrangelo 0486af6a88 Raise method visibility in Channel Providers 2016-01-14 11:12:53 -08:00
Eric Anderson bcb5fcdf82 Propagate headers/trailers if response isn't gRPC
This provides more structured data into the application for it to do
special handling.

In general, we would hope most people don't need this functionality, but
it is a good escape hatch to allow users to workaround infrastructure
problems.
2016-01-13 18:27:16 -08:00
Eric Anderson 9cb79292aa Add toString to transports for debugging.
This is a partial re-application of eca1f7c, but using super.toString()
to distinguish different transports that go to the same endpoint.
2016-01-12 11:28:40 -08:00