Commit Graph

462 Commits

Author SHA1 Message Date
Eric Anderson 6e94cf33db Require a ScheduledExecutorService to be provided to Context
Before the service would be leaked, because when the scheduled future
was cancelled the scheduler wouldn't be released. Also, Future isn't
powerful enough to signal when we should release when cancelling.

Given the nature of Context, it also seems beneficial to not have it own
threads. Since any caller of withDeadline*() is required to cancel the
Context, it shouldn't be too burdensome for them to manage the lifecycle
of the scheduler.
2016-02-01 14:16:11 -08:00
Eric Anderson 4a427b7ac9 Use instance equality for Context.Key
This allows applications to limit the visibility of values simply by not
exposing the Key instance being used.
2016-02-01 14:13:54 -08:00
Carl Mastrangelo a3c79e87ae Add a simple compression API 2016-02-01 12:56:21 -08:00
Eric Anderson 1488010cb1 Use generics for LoadBalancer to avoid ClientTransport exposure
TransportManager.makeTransport() was added to remove the only other
reference to ClientTransport outside of core and the transports.
2016-01-29 17:48:01 -08:00
Carl Mastrangelo 127e7c04a0 Fix executor propagation in CallOptions. 2016-01-29 15:25:24 -08:00
Kun Zhang ba54513f5c Fix a concurrent modification in BlankFutureProvider.
The Set from Collections.synchronizedSet() is not protected against
concurrent modification during iteration. We copy an ArrayList out of it
for iteration.
2016-01-28 11:27:04 -08:00
nmittler b7c4e18dcd Change status of HTTP/2 NO_ERROR to UNAVAILABLE.
Fixes #1355
2016-01-27 11:10:54 -08:00
Eric Anderson f59e04f310 Permit overriding Channel's executor per-call 2016-01-26 12:41:50 -08:00
Eric Anderson fe5e624153 Avoid cancel before start, which is not handled in transports
When triggered, it caused the ClientCall.Listener never to complete.
Fixes #1343

The new test doesn't actually fail on my machine with the old code, but
we would hope it would be flaky. Since a race is involved, I don't
expect a more reliable test.
2016-01-25 13:20:10 -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
Carl Mastrangelo 5205d9cc43 Fix unsynchronized access in InProcessTransport 2016-01-12 13:16:51 -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
Eric Anderson 218865a19e Revert "More information for debugging."
This reverts commit eca1f7c1d6.

We want to preserve the status message identical to what the server
sent. We'll need a better way to communicate debugging details.
2016-01-11 16:35:43 -08:00
Carl Mastrangelo 725209ce6c Fix memory leak with cancellation timeouts 2016-01-06 13:45:48 -08:00
Carl Mastrangelo 3276442d4e Split newStream from start 2016-01-06 11:46:24 -08:00
Kun Zhang eca1f7c1d6 More information for debugging.
- Include transport information in RPC's final status
- Implement toString() of transports
2016-01-05 12:29:26 -08:00
Kun Zhang fb8532a711 Fix issues discovered by internal GRPCLB integration test.
- Set knownAcceptEncodingRegistry in SingleTransportChannel
- Change the package name of load_balancer.proto to be consistent with
  what is used internally.
2015-12-30 14:41:23 -08:00
Carl Mastrangelo 707302d76e Update type and comment in Timeoutmarshaller 2015-12-21 14:03:29 -08:00
Kun Zhang 663a4f4390 Make BlankFutureProvider preserve the order.
Use LinkedHashSet in BlankFutureProvider so that it fulfills the futures
in the same order as they were created. This makes the behavior more
predictable, thus fixes the flakiness of GrpclbLoadBalancerTest and
simplifies BlankFutureProviderTest.
2015-12-18 13:39:05 -08:00
Carl Mastrangelo d3d8adbab6 Allow support for nanosecond timeouts, and use nanoseconds consistently throughout our code 2015-12-17 18:22:47 -08:00
Kun Zhang e83ac98477 The GRPCLB load-balancer.
This LoadBalancer does round-robin on a address list received from a
separate "load-balancer service", via the protocol defined in
load_balancer.proto. Everything is put under a subproject `grpc-grpclb`,
because it has dependency to protobuf.

updateRetainedTransports() now accepts EquivalentAddressGroups.  The
LoadBalancer merges the LB and normal server address groups when calling
it.
2015-12-17 11:10:46 -08:00
Kun Zhang 4abb022375 Cancel the transport future when the call is cancelled.
This is to prevent leaking future objects in BlankFutureProvider.
Resolves #1188
2015-12-17 10:14:58 -08:00
Carl Mastrangelo e0b1149902 Removed unsused variables 2015-12-16 10:20:10 -08:00
Carl Mastrangelo f5d09ff0b2 Disallow compressing zero length messages. 2015-12-16 10:03:17 -08:00
Carl Mastrangelo e967be8d3f More each coverage 2015-12-15 17:12:16 -08:00
Carl Mastrangelo c1800943ff Bump test coverage 2015-12-15 14:19:25 -08:00
Carl Mastrangelo 829735bb25 Fix gaurded by 2015-12-15 12:35:09 -08:00
Carl Mastrangelo b9cacc1553 update tests 2015-12-14 16:09:28 -08:00
Carl Mastrangelo 7ac44928be Fix bug where server wouldn't declare the negotiated compression 2015-12-14 15:48:01 -08:00
Kun Zhang 7ce50f76c7 Revert to lazy-connection.
`TransportSet` won't connect/reconnect until a transport is requested
through `obtainActiveTransport()`.
Lazy connection is safer, and more desirable in mobile environments.
It's also what C core is doing.

To warm up connections, `LoadBalancer` can call
`TransportManager.getTransport()`, even periodically if it wants to
maintain live connections.
2015-12-11 10:40:19 -08:00
Xudong Ma d41a0fa38e Use getClassLoader() instead of Thread.currentThread().getContextClassLoader() for android.
See #1272 for more details.
2015-12-10 15:06:47 -08:00
Kun Zhang 16247153f6 Move default scheme decision from ManagedChannelImpl to NameResolver.Factory.
This makes it possible to use a default scheme other than "dns" by
installing a custom NameResolver.Factory to the channel builder.
2015-12-10 14:40:46 -08:00
Carl Mastrangelo 4b18f49330 Move ServerCall unary check and add tests 2015-12-10 13:01:48 -08:00
Carl Mastrangelo 82a79d8f93 Expose compression on ClientCall and Server Call 2015-12-08 10:49:27 -08:00
Carl Mastrangelo 529b14c07b Add compressor registry, and auto negotiate compression 2015-12-07 10:56:16 -08:00
Xudong Ma 8d0b5b0c4d Replace name in TODO to a known name, otherwise MOE will complain about it 2015-12-04 16:51:48 -08:00
Xudong Ma a7398dba38 Create a No-op stream in ClientCallImpl.start() if the Context has been cancelled. 2015-12-04 16:03:09 -08:00
Eric Anderson f83a6b8761 Don't leak streams when using DelayedStream
Locking is necessary to avoid race with setStream() since the
application may be calling cancel() in another thread, and we must not
call listener.close() multiple times.
2015-12-04 14:57:41 -08:00
Eric Anderson f6a29241e8 Call ClientStreamListener directly from current thread
ClientStreamListener is intended to be called directly from the
transport, so it is safe to hold locks during the call and run on the
network thread.
2015-12-04 14:51:56 -08:00
Eric Anderson 33db8adda4 Remove outdated and misleading JavaDoc
"onHeaders always is called" is from the initial gRPC design where
0-many context frames were sent before the first message. That is why it
was possible for "no headers were received". That has long-since not
been true, but in the various refactorings this language was
accidentally left. The language "Headers always precede messages" is
correct since headers are only guaranteed if messages were sent.
2015-12-04 14:47:54 -08:00
Xudong Ma c3e7541731 Add missing @RunWith, it is required internally 2015-12-03 17:22:36 -08:00
Eric Anderson 53cc86aafc Remove unused variable 2015-12-03 14:36:08 -08:00
Carl Mastrangelo e0ea1a10fc Move DelayedStream to its own file 2015-12-03 11:24:49 -08:00
Eric Anderson f8ff71d933 Shut down LB and NameResolver when shutting down Channel 2015-12-03 09:56:05 -08:00
Louis Ryan be6008666e Initial basic implementation of context binding for clients with some limited testing
Adds utility functions for working with Contexts and interceptors
Use 'name' as Context.Key.toString to make conversion to Metadata simpler
2015-12-02 15:33:58 -08:00
Kun Zhang ad70a28d21 Move the pick-first logic from SimpleLoadBalancer to TransportSet.
TransportSet (as well as TransportManager) accepts a group of equivalent
addresses (EquivalentAddressGroup) instead of a single address.
TransportSet will move down the address list when reconnecting, and
applies back-off only after the entire list has been tried.

Main benefits:
- It will stop channel from trying to reconnect addresses that have been
  failed to connect to and moved away from. (#1212)
- It will make future implementation of Happy Eyeballs possible, inside
  TransportSet.

Tested: covered by TransportSetTest and
ManagedChannelImplTransportManagerTest.
2015-12-01 13:17:52 -08:00
Xudong Ma 88491c064f [okhttp] Use upper layer passed-in resolved address instead of resolving the hostname by itself. 2015-11-25 16:48:58 -08:00
Carl Mastrangelo 1a32366242 Expose message compression on Server Call 2015-11-24 16:48:25 -08:00
Xudong Ma cda83191d9 Update the out of date Java doc for ClientTransport.newStream(), and update the caller. 2015-11-24 11:07:51 -08:00
Louis Ryan 73e2a235e7 Notify listeners before notifying child contexts of cancellation
Improve performance of isCancellable check
2015-11-23 13:42:46 -08:00