Commit Graph

508 Commits

Author SHA1 Message Date
Eric Anderson a40b686891 Revert "Refactor ExponentialBackoffPolicy"
This reverts commit a98f8afbbe.

There was no expectation across the languages that we would support
other policies for connection retry (changing a parameter would be on
the table, though).
2016-03-25 10:23:58 -07:00
Carl Mastrangelo e63bbaf8fb Merge pull request #1587 from lukaszx0/add-backoff-to-builder
Add backoffPolicyProvider to managed chan builder
2016-03-24 16:58:33 -07:00
Lukasz Strzalkowski a98f8afbbe Refactor ExponentialBackoffPolicy
This will allow new, custom, providers in the future.

We're also moving it out of internal package because it'll be
intended to use by users for providing their custom backoff
policies - `backoffPolicyProvider` method was added in order to do
that.
2016-03-25 00:12:18 +01:00
Kun Zhang 3be48b42e3 Refresh name resolution if all addresses failed to connect. 2016-03-24 14:37:49 -07:00
Eric Anderson c480cdf62f Remove cancel(Status) since it is now unused 2016-03-24 10:52:46 -07:00
Eric Anderson 3ead41141e Use stream.cancel() instead of cancel() in ClientCallImpl
Using cancel() sets cancelCalled=true which causes methods like
sendMessage() to throw IllegalStateException. This results in spurious
exceptions that are impossible to avoid. The API was designed to only
throw IllegalStateException when the caller called methods in the wrong
order, which is not the case here.

Fixes #1531
2016-03-24 10:44:50 -07:00
Carl Mastrangelo 65d3847d14 Remove references to Throwable.propagate 2016-03-22 15:47:52 -07:00
buchgr 1ff6ecbb21 Fix flaky DeadlineTest.runOnEventualExpirationIsExecuted()
The test fails frequently on my MBP. I ran the test 10
times and the deadline took at most 63ms to expire. So I
bumped the timeout to 70ms.
2016-03-22 17:46:53 +01:00
Xiao Hang 37f45e332f Add idempotent related getter and setter to MethodDescriptor 2016-03-21 15:43:26 -07:00
Lukasz Strzalkowski 14bc16e8eb Update Attributes.Key conventions
We don't need to require namespacing it's not necessery anymore
since object is used by the key, not key name.
2016-03-17 19:46:26 -04:00
Lukasz Strzalkowski c3011b0798 Move server call keys to ServerCall class 2016-03-17 19:46:26 -04: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
Lukasz Strzalkowski b37ebd6482 Add Key#of and Key#keys, use key object as map key, add tests 2016-03-16 15:39:42 -07:00
Carl Mastrangelo 12dfecba62 Chnage mispeling of jvaadoc in wihtLogiD 2016-03-16 10:38:27 -07:00
elandau 053a18e209 Use Attributes as the affinity data for LB.
- Remove RequestKey.
- Rename withRequestKey() to withAffinity(), which accepts an Attributes.
2016-03-14 15:13:42 -07:00
Kun Zhang 08c74d46f5 Only link delayed transport AFTER real transport has called transportReady().
If TransportSet fails to connect a transport (i.e., transportShutdown()
called without transportReady()), TransportSet will automatically
schedule reconnection for the next address, unless it has reached the end
of the address list, in which case it will fail the delayed transport.

This will reduce stream errors caused by bad addresses appearing before
good addresses in the resolved address list.

Before this change, TransportSet would return the real transport on the
first call of obtainActiveTransport(). After this change, it will return
the delayed transport instead.
2016-03-11 14:46:44 -08:00
Eric Anderson eccd231131 Don't hold a lock in DelayedStream when calling realStream
Our current lock ordering rules prohibit holding a lock when calling the
channel and stream. This change avoids the lock for both
DelayedClientTransport and DelayedStream. It is effectively a rewrite of
DelayedStream.

The fixes to ClientCallImpl were to ensure sane state in DelayedStream.

Fixes #1510
2016-03-09 15:14:00 -08: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
Carl Mastrangelo 8ed0088eff Make Status code use percent encoding 2016-03-07 10:01:44 -08:00
Kun Zhang 2491402036 Remove or use unused variables. 2016-03-04 17:05:23 -08:00
Carl Mastrangelo 946611909e remove unused var 2016-03-04 16:17:31 -08:00
Kun Zhang 0e14516f5a Run createTransportRunnable outside of lock.
Because `scheduleConnection()` is run under lock, if we ran
`createTransportRunnable` inside `scheduleConnection()`,
`savedDelayedTransport.setTransport()` will be under lock which violates
the assumption made in https://github.com/grpc/grpc-java/issues/1408 that

> there is an implicit rule today that channel layer will not hold any lock while calling into transport

and had caused deadlock with `InProcessTransport`.

Also updated tests to

 1. Make it clear that we want the first obtained transport to be the
 real transport instead of the delayed transport, because
 `InProcessTransport` has deadlock issues with delayed
 transport (grpc/grpc-java/pull/1510)

 2. Not rely on identity equity to check whether `TransportSet` has
 switched to a different address. Instead, call `newStream()` and check
 which real transport is actually called, which is more reliable.

 3. Add timeout when checking for real transport creation and
 starting. Tests in general should not check for implementation detail,
 e.g., whether certain work is done synchronously.
2016-03-03 16:35:12 -08:00
William Thurston a574159c81 Add interceptForward methods for Client and Server 2016-03-03 15:32:54 -08:00
Carl Mastrangelo 0e370eb155 Remove static initializer blocks 2016-03-03 09:51:51 -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 643bb2c6b5 Always start from the first address after a successful connection. 2016-02-26 17:21:47 -08:00
Carl Mastrangelo 86bad4ffea Add more log into for cancellation 2016-02-26 13:37:14 -08:00
Louis Ryan 8dad73492a Various naming and documentation clenaups
Remove attachAsCloseable and replace with the immediate run / call methods
Introduce a concrete Deadline type and use it
2016-02-25 16:33:10 -08:00
Eric Anderson b17a249fc4 Create new AbstractTransportTest for Transports
This is lower-level than the existing AbstractTransportTest. It should
be used by all transports, but InProcessTransport is the only one as
part of this commit.
2016-02-25 16:23:17 -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
Eric Anderson 06e3ef5945 Fix bugs and improvements found by static analyser 2016-02-23 17:32:35 -08:00
Kun Zhang 7a29f3993c Pass transports instead of futures of transports for new calls.
This PR finishes the refactoring started by #1395. Resolves #1342.

Major changes:

- All interfaces that return `ListenableFuture<T>` now return `T`
- Stop passing `null` for transports after shut down. Pass
  `FailingClientTransport` instead. This simplifies the interface
  semantics of interfaces that return a transport, as well as their
  callers because they no longer need to check for `null`.
- Add two methods to `TransportManager`:
 - `createInterimTransport()` takes the place of `BlankFutureProvider`
  in `LoadBalancer` implementations.
 - `createFailingTransport()` takes the place of errors in the `Future`
  when `LoadBalancer` implementations propagate errors to the caller.
- `createInterimTransport()` creates a `DelayedClientTransport` tracked
  by `ManagedChannelImpl`, which will not terminate until all
  `DelayedClientTransport`s, in addition to the `TransportSet`s, are
  terminated.
- Removed the transport argument from the ready and shutdown callbacks,
  because if `LoadBalancer` was given a delayed transport earlier, it
  will get the real transport's shutdown event, thus won't be able to
  match the two through identity comparison, which beats the purpose of
  passing the transport.
2016-02-23 09:42:03 -08:00
Xiao Hang 52b3db2c06 Fix a bug ByteReadableBufferWrapper. We should set new buffer's limit before changing the original buffer's position 2016-02-22 16:28:36 -08:00
William Thurston 8d0267fc41 Allow for interceptors to send and receive messages of type InputStream. 2016-02-21 18:01:25 -08:00
Lukasz Strzalkowski af6a2650af Add simple BINARY_BYTE_MARSHALLER 2016-02-20 12:30:20 -08:00
Eric Anderson 6f1261f288 Decrease log verbosity for transport status changes
Most of the time it is just feeling like logspam.

Fixes #1439
2016-02-19 09:26:30 -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
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
Carl Mastrangelo 544cd3a33b pause 2016-02-11 15:45:30 -08:00
Eric Anderson ad301c7e4d Make thread-safety ownership of Metadata explicit 2016-02-11 12:40:38 -08:00
Lukasz Strzalkowski 48b30291ee Add Metadata#keys() which returns set of all keys in the store 2016-02-11 17:32:05 +01:00
Eric Anderson 964963ab1a Replace AUTHORITY_KEY with ClientStream.setAuthority 2016-02-10 17:26:51 -08:00
Eric Anderson 86f2c9f224 Fix InProcessTransport to call onReady
Fixes #875
2016-02-10 10:01:15 -08:00
Solomon Duskis f6aba497ae Fixing a typo in Http2ClientStream. 2016-02-03 09:58:32 -08:00
Eric Anderson e475d388b9 Cancel server context when call is cancelled
Context was being closed when the server was closing the RPC, but not if
the client cancelled.
2016-02-01 14:20:08 -08:00
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