Commit Graph

684 Commits

Author SHA1 Message Date
Louis Ryan 3df1446deb Eliminate MethodDescriptor from startCall and interceptCall for servers
Make the MethodDescriptor a property of ServerCall
Move ServerMethodDefinition into ServerServiceDefinition
2016-06-13 14:39:58 -07:00
Eric Anderson 0b55c81548 core: Move ACCEPT_ENCODING_JOINER to DecompressorRegistry
This removes a reference of io.grpc.internal from io.grpc. It also
optimizes server call handling for outbound grpc-accept-encoding header,
as had already been done for client call.
2016-06-13 13:42:58 -07:00
Jakob Buchgraber 4b127f2231 core: Fix CallOptions 'wait for ready' and toString()
- CallOptions 'wait for ready' was not passed between with*() calls and therefore
it was not possible to enable it via a stub.

- Properly format custom call options in toString() output.
2016-06-13 21:04:25 +02:00
Jakob Buchgraber 7da48ae13e core: log exceptions thrown by Runnable's executed via schedule(..). Fixes #1237 2016-06-13 18:39:26 +02:00
ZHANG Dapeng 9d4a43fb79 core: fail fast implementation
resolves #1759
2016-06-11 09:30:16 -07:00
Kun Zhang 432cec7973 core: CallCredentials
Introduce CallCredentials as a first-class option to allow applications
to set per-call credentials into headers for outgoing RPCs. This will
supersede ClientAuthInterceptor. It has access to more
information (e.g., transport attributes, MethodDescriptor) and allow
results to be returned asynchronously, e.g., from a blocking I/O, which
was problemantic with ClientAuthInterceptor.
2016-06-09 17:46:15 -07:00
William Thurston a05ab57561 core: emit lists of lists from NameResolver 2016-06-09 08:30:55 -07:00
Kun Zhang 05ce5455da core: A missed-out test for #1896 2016-06-07 11:57:25 -07:00
ZHANG Dapeng b88ea27b53 core/internal: add 3-arg newStream method to ClientTransport interface (#1898)
adding 
ClientStream newStream(MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions);
to ClientTransport interface

Created this PR first because both fail fast implementation and another change will be using this interface change
2016-06-06 19:43:15 -07:00
Jakob Buchgraber 53cd333531 core: add test for complete() without close() exception in AbstractServerStream. Fixes #615 2016-06-03 07:27:57 +02:00
Eric Anderson c6fd94ca85 Implement shutdownNow
Fixes #448
2016-06-02 17:39:59 -07:00
Kun Zhang 631a9d5fac Fix URI construction.
This fixes two issues.

1) Use the URI constructor with multiple arguments to construct the placeholder
URI for direct address, so that special characters can be correctly
escaped. This resolves #1883.

It requires the second fix.

2) Stop URI from mistreating paths as authorities.

There is a bug in URI constructors that take multiple arguments.  They simply
concatenate escaped components and try to parse the resulting string.

For example, URI("dns", null, "//127.0.0.1", null), which is what we do
internally when the application passes "/127.0.0.1" as the target, is supposed
to create a [scheme="dns", path="//127.0.0.1"].  Instead, it internally composes
"dns://127.0.0.1", which is parsed into [scheme="dns", authority="127.0.0.1"].

To avoid this issue, we pass empty string instead of null as the authority to
the URI constructor. The constructor would make "dns:////127.0.0.1" internally
which can be parsed correctly.
2016-06-02 17:10:44 -07:00
elandau 90323ad5d4 core: add custom CallOptions 2016-06-02 09:14:48 -07:00
Carl Mastrangelo 2ed39c92eb core: cache decompressor registry encodings, and make it copy on write 2016-06-02 09:10:42 -07:00
Kun Zhang 90506405c9 Differentiate transport to LB services and to servers.
TransportManager has a new method, createOobTransportProvider(), which
accepts an EquivalentAddressGroup and the authority string. This
addresses two requirements:

1. Per GRPCLB protocol, connections to the remote load-balancer may use a
different authority than the channel's (#1137).

2. For idle state determination, Channel needs to exclude the transport to
the LB service when looking at live RPCs and (#1276).
2016-06-01 18:23:09 -07:00
Carl Mastrangelo 676bf4854f core: fix nags from linter 2016-06-01 13:58:07 -07:00
Carl Mastrangelo 02eb24b3bd core,netty,okhttp: move user agent removal closer to where it is set 2016-06-01 12:55:21 -07:00
Jakob Buchgraber 028d0844dd core: add test for deframer closed exception. fixes #1795 2016-06-01 20:44:29 +02:00
Kun Zhang c08d74fec4 TransportSet shutdown() also shuts down the pending transport.
Previously TransportSet.shutdown() only shuts down the active transport,
which means a transport will not be shutdown if it's not ready yet. This
issue was introduced by #1494 that postponed the assignment of the
active transport till transport ready.
2016-05-29 15:45:03 -07:00
ZHANG Dapeng 361936401f core/internal: fix regex pattern 2016-05-26 14:02:15 -07:00
Eric Anderson 7052d8b5e9 core: Promote Deadline API to stable
Fixes #1706
2016-05-26 13:33:48 -07:00
Carl Mastrangelo 4204eb8cd9 core: allocate less garbage iterators in Metadata.serialize
Before:
HeadersBenchmark.convertClientHeaders             10  sample   99004   806.749 ±   4.692  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  105673  1540.814 ±  86.361  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  188978  3347.881 ±  71.778  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  189913  6626.884 ±  94.348  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  107884   766.328 ±  49.338  ns/op
HeadersBenchmark.convertServerHeaders             20  sample  122568  1303.501 ±   8.820  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  109281  2920.586 ±  93.654  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  196784  6429.566 ± 108.588  ns/op

After:
HeadersBenchmark.convertClientHeaders             10  sample  113274   715.382 ±  5.412  ns/op
HeadersBenchmark.convertClientHeaders             20  sample  128654  1294.677 ± 67.867  ns/op
HeadersBenchmark.convertClientHeaders             50  sample  112598  2814.925 ± 62.291  ns/op
HeadersBenchmark.convertClientHeaders            100  sample  116920  5383.146 ± 90.205  ns/op
HeadersBenchmark.convertServerHeaders             10  sample  130004   626.243 ±  3.528  ns/op
HeadersBenchmark.convertServerHeaders             20  sample  142054  1185.193 ± 80.272  ns/op
HeadersBenchmark.convertServerHeaders             50  sample  115153  2795.715 ± 92.956  ns/op
HeadersBenchmark.convertServerHeaders            100  sample  119520  5249.636 ± 56.089  ns/op
2016-05-25 15:12:40 -07:00
Carl Mastrangelo 1cc76d8132 core,netty,okhttp: move user agent out of client call and into the transport 2016-05-25 15:11:42 -07:00
Eric Anderson 641cb357c6 Tweak -Xlint warnings
This now catches a few more places we needed -Xlint:-options.
InProcessSocketAddress is technically already in our stable API, so I
maintained its current serialVersionUID.
2016-05-24 15:04:07 -07:00
Eric Anderson e4ea237597 core: Refactor TransportSet in prep for fail fast
This is functionally equivalent. Some tests needed changes because they
were verifying internal behavior.
2016-05-24 14:40:07 -07:00
Carl Mastrangelo 5e30b2f7ba netty: speed up header conversion by caching user agent string
Performance gain seems to be about 100-200ns based on a a couple trials.

Benchmark                                 (headerCount)  (validate)    Mode     Cnt     Score    Error  Units
HeadersBenchmark.convertClientHeadersOld             10       false  sample  187490   858.234 ±  3.992  ns/op
HeadersBenchmark.convertClientHeadersOld             20       false  sample  113589  1407.557 ± 45.178  ns/op
HeadersBenchmark.convertClientHeadersOld             50       false  sample  100725  3141.936 ± 55.175  ns/op
HeadersBenchmark.convertClientHeadersOld            100       false  sample  109742  5707.748 ± 38.222  ns/op
HeadersBenchmark.convertHeaders                      10       false  sample  109137   748.486 ±  4.060  ns/op
HeadersBenchmark.convertHeaders                      20       false  sample  133639  1238.528 ± 51.914  ns/op
HeadersBenchmark.convertHeaders                      50       false  sample  107914  2915.602 ± 10.017  ns/op
HeadersBenchmark.convertHeaders                     100       false  sample  110305  5682.404 ± 44.032  ns/op
2016-05-23 17:49:30 -07:00
Łukasz Strzałkowski ac9a5a5679 Make Code.status() public, add Status#fromCode()
Closes #1722
2016-05-23 17:03:48 -07:00
Eric Anderson 8033cdd3a7 core: Add unit test for Contexts.interceptCall 2016-05-23 13:51:10 -07:00
Eric Anderson 6382015f9d internal: Split-state AbstractStream; sending and receiving
This introduces an AbstractStream2 that is intended to replace the
current AbstractStream. Only server-side is implemented in this commit
which is why AbstractStream remains. This is mostly a reorganization of
AbstractStream and children, but minor internal behavioral changes were
required which makes it appear more like a reimplementation.

A strong focus was on splitting state that is maintained on the
application's thread (with Stream) and state that is maintained by the
transport (and used for StreamListener). By splitting the state it makes
it much easier to verify thread-safety and to reason about interactions.

I consider this a stepping stone for making even more changes to
simplify the Stream implementations and do not think some of the changes
are yet at their logical conclusion. Some of the changes may also
immediately be replaced with something better. The focus was to improve
readability and comprehesibility to more easily make more interesting
changes.

The only thing really removed is some state checking during sending
which is already occurring in ServerCallImpl.
2016-05-23 12:33:49 -07:00
Carl Mastrangelo e19848092d core, interop-testing: always set message encoding, and use it in interop tests
This change updates the behavior of the core compression semantics.  Previously,
if the codec was "identity", nothing was set on the wire.  This is allowed by
the spec, but doesn't match what wrapped languages do.

Additionally, the interop tests will now attempt to honor the requested
compression.
2016-05-18 12:04:25 -07:00
Carl Mastrangelo 4e268da29b core: Don't lose server call exception when message fails to close 2016-05-13 15:59:06 -07:00
nmittler 951b5a4ca2 Adding metadata to Status exceptions.
Fixes #681
2016-05-13 15:52:06 -07:00
Jakob Buchgraber ce002bd449 core: allow ClientCall.cancel before start. Fixes #1536 (#1822) 2016-05-13 22:20:02 +02:00
nmittler d9d4d8b70f Updating status codes to match the spec.
Fixes #1605
2016-05-09 13:55:50 -07:00
Kun Zhang 91b087e526 Remove an obsolete comment on ServerServiceDefinition.
Commit 9597382 introduced InternalHandlerRegistry as the main registry,
which uses a flat map from fullMethodNames to handlers, thus addressed
the original intention of this comment.
2016-05-05 09:25:04 -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 dc80b52da6 context: Remove tests for Key Equality. 2016-05-04 16:39:55 -07:00
Carl Mastrangelo bc661e7fbb all: Finish adding tracking issues for ExperimentalApi 2016-05-03 16:15:57 -07:00
Carl Mastrangelo 0f9e3fa2ea all: Add issues for many of the experimental API annotations 2016-05-03 13:24:28 -07:00
Eric Anderson b5e6d420a3 Return Context from fork instead of CancellableContext
It is trivial to call withCancellation() after the fork().
CancellableContexts are required to be cancelled eventually, so
returning Context instead is easier when cancellation is not necessary.

Fixes #1626
2016-05-03 09:19:31 -07:00
ZHANG Dapeng dda4ad7441 remove the dependency on Guava's Throwables.getCausalChain #1663 (#1749)
resolves #1663
2016-04-29 19:43:21 -07:00
Jakob Buchgraber 46eefe34fb Strip cause from InProcessTransport between client and server. Fixes #1716 2016-04-29 23:36:59 +02:00
Carl Mastrangelo f7dc4d2cc6 Try to use ScheduledThreadpoolExecutor 2016-04-29 13:59:28 -07:00
Jakob Buchgraber 9de87e3acd Add tests for call.cancel() from within messageRead. 2016-04-29 18:16:58 +02:00
Jakob Buchgraber 645bb24c6c Add private constructor to Contexts and mark statusFromCancelled experimental. Fixes #1737 and #1736. (#1738) 2016-04-28 17:12:14 +02:00
Eric Anderson b0ed77ad81 Specify Status*Exception is to be used in StreamObserver.onError 2016-04-27 16:45:05 -07:00
Kun Zhang 16e168951a Allow application to pass cancellation details.
Resolves #1221

Add ClientCall.cancel(String, Throwable) and deprecate
ClientCall.cancel(). Will delete cancel() after all known third-party
overriders have switched to overriding the new one.
2016-04-27 09:38:18 -07:00
Carl Mastrangelo 00f8f349b2 Don't allocate extra byte for each MessageFramer 2016-04-21 10:48:53 -07:00
Carl Mastrangelo 5baee2d935 Fix some corner cases with MessageFramer 2016-04-21 10:45:07 -07:00
Kun Zhang 8502730d07 Attach an exception to client-initiated CANCELLED.
This tells us where is the cancellation initiated, which is important
information for debugging.
2016-04-20 17:38:01 -07:00
wangyuntao 7d8ee1e9d8 some spelling mistakes 2016-04-19 08:39:20 -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
Sky Ao 1d8aefad69 create AuthorityOverridingTransportFactory instance only when authorityOverride is set 2016-04-18 08:43:30 -07:00
Kun Zhang 0f86671f8d Handle exceptions from LoadBalancer.handleResolvedAddresses()
And pass the exception to LoadBalancer.handleNameResolutionError(), in
the hope that it canb e propagated to the application, instead of
leaving the RPC hang forever.

Resolves #1407
2016-04-14 16:23:36 -07:00
Kun Zhang 7659f6ed68 Handle empty address list from NameResolver.
Passing an empty list to NameResolver.Listener.onUpdate() will trigger
onError(). It is documented in the javadoc and enforced by
ManagedChannelImpl.

Forbid empty address list in EquivalentAddressGroup.

Resolves #1657
2016-04-14 13:43:07 -07:00
Carl Mastrangelo 51fd870cfd Add getting the port out of a Server 2016-04-13 13:54:45 -07:00
Kun Zhang 43439325bc Delayed transport creates real streams in executor.
setTransport() is called by the transportReady() callback, which is run
inside transport thread. When it creates real streams, it also
serializes all buffered requests, which is not supposed to be done in
transport thread. This change offloads the work to the application
executor.

Resolves #1606

Also fix ManagedChannelImplTest flakes by adding timeouts to all
verify()s on mockStream.start().
2016-04-12 16:33:58 -07:00
buchgr fd8fd517d2 Context deadline propagation should cascade. Fixes #1205
A call's timeout as specified in its metadata should be set depending
on the deadline of the call's context. If a call has an explicit deadline
set (through CallOptions), then the smaller deadline (from context and call options)
should be used to compute the timeout.

Also, a new method Contexts.statusFromCancelled(Context) was introduced that attempts
to map a canceled context to a gRPC status.
2016-04-12 21:43:49 +02:00
Carl Mastrangelo 7d889b6911 Reuse metadata array when making http2 headers, and reduce some array copies 2016-04-08 13:08:07 -07:00
Łukasz Strzałkowski 90fbf9b274 Adapt BindableService in ServerBuilder#addService
Makes binding services to server as simple as it can get.
2016-04-08 11:14:26 -07:00
Eric Anderson 30d4f95a58 Deflake CallOptionsTest.withDeadlineNanoTime
Two prong approach: increase the tolerance and decrease code between
nanoTime() calls.

Fixes #1645
2016-04-08 10:35:40 -07:00
Carl Mastrangelo 2c3a63fe75 Remove some array copies in metadata 2016-04-07 12:58:44 -07:00
Eric Anderson bd87b3f739 Allow nanoTime to wrap around in Deadline
A nanoTime result must be subtracted from another result to be useful;
you must do t1 - t2 < 0 instead of t1 < t2.
2016-04-06 12:08:31 -07:00
Eric Anderson d36a03c7b1 Use ticker in Deadline testing to remove flakes 2016-04-06 12:05:14 -07:00
Carl Mastrangelo b3bc7fc499 Try out using Truth library 2016-04-05 11:33:20 -07:00
Carl Mastrangelo 5c4ff7ad08 Remove unused method 2016-04-01 14:04:55 -07:00
Carl Mastrangelo f64a02f2ef Remove Flakes caused by assertEquals 2016-03-31 16:20:40 -07:00
Kun Zhang 877e1e11eb Provide default implementation for NameResolver.refresh().
It is an optional operation anyway. In a pushing name system, refresh()
wouldn't be necessary.
2016-03-29 17:07:55 -07:00
Kun Zhang 2d15af53c7 Retry DNS resolution when there is an error. 2016-03-29 16:15:39 -07:00
Kun Zhang 575df76a8f Trigger name resolution when a live connection closed.
In addition to when all addresses have failed to connect. This is to
cover the case where some addresses have changed in the name system
while some are still there and usable. Without this change, the client
would try to connect old addresses each time it reconnects.
2016-03-29 13:50:25 -07:00
Lukasz Strzalkowski 3ea153634f Retrun InProcessSocketAddr for InProcess server streams 2016-03-25 16:17:45 -07:00
Eric Anderson 5c4817723e Warn users shutdownNow doesn't behave as documented
This just places back a warning that was mistakenly removed in b687bdc.

Fixes #1500
2016-03-25 14:34:16 -07:00
buchgr 6e679401ea Allow Deadline.timeRemaining() to return a negative time offset. 2016-03-25 22:15:30 +01:00
buchgr 32ddf9f381 Make CallOptions and AbstractStub use Deadline.
- Made CallOptions use the Deadline type instead of a
  long to represent a deadline.
- Added new methods CallOptions.withDeadline(Deadline) and
  AbstractStub.withDeadline(Deadline). The methods are
  marked experimental, as the Deadline class is marked
  experimental. These methods are meant to replace
  CallOptions.withDeadlineNanoTime(Long) and
  AbstractStub.withDeadlineNanoTime(Long), which have
  been deprecated.
- Updated CallOptions.toString() to include all fields.
2016-03-25 22:15:22 +01:00
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
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