Commit Graph

462 Commits

Author SHA1 Message Date
Kun Zhang ece7402dc8 Clarify specs for target strings, especially for IPv6.
See the javadocs of ManagedChannelBuilder.forTarget().

The most interesting case is passing an IPv6 address as target. It can
be either be passed as an authority, where brackets should not be
escaped ([::1]), or as a path of a full URI, where brackets must be
escaped (dns:///%5B::1%5D).

Previously, dns:///[::1], being an invalid URI (brackets not allowed in
path), would be converted to dns:////dns:///%5B::1%5D and passed to
DnsNameResolver. Though it would fail eventually, the error would be
very confusing to users. I changed the logic so that it would try with
dns:/// only if the target string doesn't look like an intended URI
target.

I have restricted the "URI target" to be absolute and hierarchical,
i.e., must start with scheme://. I couldn't find a way to better tell if
a string is intended to be a URI, but I am open to other options.

Refactored tests:

- Move the tests for getNameResolver() into a separate file
  ManagedChannelImplGetNameResolverTest, because those tests are not
  quite compatible with the facility provided by ManagedChannelImplTest.
- Create DnsNameResolverTest. Move DnsNameResolver out of the factory
  class to accommodate for the test.
2015-11-23 09:06:17 -08:00
Carl Mastrangelo 7de6c04d14 Move decompressor setting to the AbstractServerStream 2015-11-20 13:27:27 -08:00
buchgr 602473d786 Add directExecutor() to Channel and Server Builders. Fixes #368.
When using a direct executor we don't need to wrap calls in a
serializing executor and can thus also avoid the overhead that
comes with it.

Benchmarks show that throughput can be improved substantially.
On my MBP I get a 24% improvement in throughput with also
significantly better latency throughout all percentiles.

(running qps_client and qps_server with --address=localhost:1234 --directexecutor)

=== BEFORE ===
Channels:                       4
Outstanding RPCs per Channel:   10
Server Payload Size:            0
Client Payload Size:            0
50%ile Latency (in micros):     452
90%ile Latency (in micros):     600
95%ile Latency (in micros):     726
99%ile Latency (in micros):     1314
99.9%ile Latency (in micros):   5663
Maximum Latency (in micros):    136447
QPS:                            78498

=== AFTER ===
Channels:                       4
Outstanding RPCs per Channel:   10
Server Payload Size:            0
Client Payload Size:            0
50%ile Latency (in micros):     399
90%ile Latency (in micros):     429
95%ile Latency (in micros):     453
99%ile Latency (in micros):     650
99.9%ile Latency (in micros):   1265
Maximum Latency (in micros):    33855
QPS:                            97552
2015-11-19 20:50:02 +01:00
Carl Mastrangelo c3e179be60 Split out server call impl, add explicit tests and remove an impossible case 2015-11-17 11:16:29 -08:00
Kun Zhang 01bf56bf8d Fix placeholder in the error message of Preconditions.
Only '%s' is allowed.
2015-11-13 14:58:35 -08:00
Louis Ryan c40d702068 Switch to use Executor instead of ExecutorService where we don't need it 2015-11-12 15:30:15 -08:00
Carl Mastrangelo b0c626c359 Update Load balancing URI parsing and add tests 2015-11-11 17:50:30 -08:00
Kun Zhang 5529b6489b Create BlankFutureProvider which is reused among LoadBalancers.
If a LoadBalancer is requested for a transport future before it can get
one from TransportManager, e.g., before name resolution is completed,
LoadBalancer will return a blank future created by BlankFutureProvider
and to be linked with real futures later.
2015-11-11 15:20:09 -08:00
Carl Mastrangelo 05b7d75029 Re add support for periods in metadata key names 2015-11-10 15:59:42 -08:00
Carl Mastrangelo 3b82484281 Minor cleanup of ClientCallImpl header normalization 2015-11-10 13:52:06 -08:00
Carl Mastrangelo dc375500d6 Update -bin header restrictions, and re introduce string interning. 2015-11-10 13:40:02 -08:00
Carl Mastrangelo 2ad35b8269 Add Header name character restrictions 2015-11-10 11:20:04 -08:00
Louis Ryan 49b513504c Remove notion of stack from thread-local binding, use simple swapping instead.
This allows for binding state to be reset to known-good states precisely which in turn
facilitates making it safe to have 'detach' not throw exceptions and instead log
a severe error that attach/detach calls were not correctly balanced.
2015-11-09 13:17:18 -08:00
Carl Mastrangelo d2046b637d Allow commas in Metadata values 2015-11-09 12:39:53 -08:00
Eric Anderson a5d9e34bd6 Add Executor wrapping to Context 2015-11-09 10:59:53 -08:00
Kun Zhang 38ba586e0c Migrating from Objects.ToStringHelper to MoreObjects.ToStringHelper.
The former is deprecated.
2015-11-04 10:04:12 -08:00
Eric Anderson 7767138c96 Use assertEquals instead of assertTrue(Range.contains)
It likely will produce a better error message and doesn't require using
as large of an API/impl.
2015-11-02 11:07:25 -08:00
Xudong Ma 750b1977ca Make the header list size limit configurable on both client and server side. 2015-10-30 10:52:47 -07:00
Kun Zhang a4f319f0c3 Clarify the audience of internal API. 2015-10-29 16:32:00 -07:00
Carl Mastrangelo b287d1dbc8 Deflake Call Options test 2015-10-28 13:44:25 -07:00
Kun Zhang ac02e206e8 Fix javadocs of NameResolver 2015-10-28 11:50:42 -07:00
Kun Zhang b5b79642c5 Fix a NPE in ManagedChannelImpl.
The error occurs when name resolution completes after the channel is
shut down. What ManagedChannelImpl doing right now is violating the
TransportManager interface, because TransportManager.getTransport()
should never return null.
2015-10-28 11:32:15 -07:00
Carl Mastrangelo 122f93c26d Add unit tests for SizeEnforcingInputStream 2015-10-28 09:34:46 -07:00
Eric Anderson 353aabce51 Increase coverage for CallOptions 2015-10-28 09:31:42 -07:00
Kun Zhang edd57c941e Support default port in NameResolver.
- Channel builders decide the default port based on whether TLS is used.
- Channel builders populate the default port via an Attributes object
  passed to NameResolver.Factory#newNameResolver
2015-10-27 13:54:36 -07:00
Eric Anderson 63f1482ad6 Increase code coverage of Context
A few minor bugs were discovered and fixed.
2015-10-27 11:22:56 -07:00
Eric Anderson 2c2d7171ec Assert that timeouts didn't occur in Context tests
Although it is unlikely the awaits return false, it would be useful
information to know about the failure if they did.

This should provide more clues in case the test flakes again (#1146)
2015-10-23 14:31:12 -07:00
nmittler 6f64999821 Addressing concurrency issue in MessageFramer.
Fixes (hopefully): #991
2015-10-23 13:00:23 -07:00
Carl Mastrangelo f39b67c0e8 Add uri checking 2015-10-23 11:13:03 -07:00
Kun Zhang efac679abc NameResolverRegistry and better-defined target string.
- NameResolverRegistry contains all the official NameResolvers. Users
  can also add custom NameResolvers to it. It looks up NameResolver by
  try-and-fail. It is the default NameResolver.Factory for builders.
  DnsNameResolver.
- Pass target as Strings instead of URIs from the channel builder to
  ManagedChannelImpl. A target string is not necessarily a valid URI, in
  which case ManagedChannelImpl will add "dns:///" to the beginning of
  the target and use it as URI.
- DnsNameResolver will require scheme "dns" to be present. It no longer
  allows scheme-absent URIs.
2015-10-23 09:37:22 -07:00
Kun Zhang 17597ce9cf Pass the initial transportFuture to DelayedStream.
Otherwise, when DelayedStream is created it ends up calling
clientTransportProvider a second time. However, we already have a
transportFuture available, we should just use it instead.
2015-10-22 17:00:35 -07:00
Eric Anderson 33e26cdaa4 Delete ManagedChannelImplTest.transportFailsOnStart
transportFailsOnStart was still flaky. By looking at history, it became
obvious that transportFailsOnStart was created to test two cases we no
longer support: the transport throwing an exception during start and the
transport calling listener.transportShutdown during start. The part of
the test checking throwing an exception was removed earlier.
2015-10-22 15:42:50 -07:00
Eric Anderson 16c4c49e94 Fix flake in ManagedChannelImplTest.transportFailsOnStart
The scheduling on another thread led to a race where sometimes the
future wasn't completed by the time isDone() was checked in
ClientCallImpl causing the usage of DelayedStream, which really messed
up what the test was trying to do.
2015-10-22 12:53:30 -07:00
Kun Zhang 942f4c99d8 Load-balancing ManagedChannelImpl.
- Add NameResolver and LoadBalancer interfaces.
- ManagedChannelImpl now uses NameResolver and LoadBalancer for
  transport selection, which may return transports to multiple
  addresses.
- Transports are still owned by ManagedChannelImpl, which implements
  TransportManager interface that is provided to LoadBalancer, so that
  LoadBalancer doesn't worry about Transport lifecycles.
- Channel builders can be created by forTarget() that accepts the fully
  qualified target name, which is an URI. (TODO) it's not tested.
- The old address-based construction pattern is supported by using
  AbstractManagedChannelImplBuilder.DirectAddressNameResolver.
- (TODO) DnsNameResolver and SimpleLoadBalancer are currently
  incomplete. They merely work for the single-address scenario.
2015-10-20 17:28:44 -07:00
Carl Mastrangelo ce93051aad Cover more low hanging fruit 2015-10-16 15:27:59 -07:00
Carl Mastrangelo 8138308cdb Up code coverage for Metadata 2015-10-13 16:21:44 -07:00
Xudong Ma 72a0a38182 [okhttp] Make sure transportShutdown() always be called before calling transportTerminated(). 2015-10-12 16:34:55 -07:00
Kun Zhang bb113ad721 Use timeout when verifying setDecompressionRegistry()
because setDecompressionRegistry() could be called from a different
thread than the test thread.
2015-10-01 17:35:04 -07:00
Kun Zhang be400d3ea8 Stub mockTransport.newStream() to prevent NPE. 2015-10-01 16:16:35 -07:00
Kun Zhang 89288465c4 Prepare channel layer for upcoming load-balancing changes.
- ListenableFutures of transports, instead of actual transports, are
  passed through multiple layers to ClientCallImpl, so that name
  resolution and load-balancing, which may delay the creation of
  transports, won't block the creation of ClientCall. This also
  simplifies reconnect logic.
- Moved Transport management for a single address to a separate class
  TransportSet. Later, ManagedChannelImpl will own multiple
  TransportSets instead of one.
- ClientCallImpl will buffer requests in DelayedStream until transport
  is ready.
2015-09-29 18:49:38 -07:00
Carl Mastrangelo 46c18ea237 Move decompressor setting down into the AbstractStream 2015-09-28 10:25:58 -07:00
nmittler 7c2ff632cd Fixing flaky test Http2NettyTest.deadlineExceeded()
This test occasionally flakes due to the way the deadline timer cancels the stream. Stream cancellation immediately closes the outbound status, disallowing the sending of further messages.  The true cancellation is done sometime later in the transport thread in Netty. So there is a race between closing the outbound status and performing the actual cancellation where sent messages will fail with the wrong status.
2015-09-24 16:22:46 -07:00
Éamonn McManus 9e690f8ddf Make io.grpc.Status.STATUS_LIST be static final, not just static. 2015-09-21 11:02:19 -07:00
Carl Mastrangelo 5dad18c54b Pass decompressor registry around and make it less static 2015-09-18 12:47:41 -07:00
Eric Anderson 4cc103ac6a Mark Status*Exception.getStatus() final
This further limits our API.
2015-09-17 14:10:53 -07:00
Carl Mastrangelo 4572b197e0 Add a message accept encoding header 2015-09-17 12:30:04 -07:00
Eric Anderson 6e0651643e Mark more server-side pieces experimental
You can't make an interceptor without calling ServerCallHandler, so it
is now marked experimental.
2015-09-14 15:24:24 -07:00
Eric Anderson 491a98afc5 Restrict more of the API: Metadata, ServerCall, Status 2015-09-14 15:24:22 -07:00
Carl Mastrangelo 4b27e542e0 Don't let server start if already shutting down 2015-09-14 11:39:28 -07:00
Eric Anderson 1cfba96d17 Enforce sending headers before messages on server
ServerCall already had "headers must be sent before any messages, which
must be sent before closing," but the implementation did not enforce it
and our async server handler didn't obey.

The benefit of forcing sending headers first is that it removes the only
implicit call in our API and interceptors dealing just with metadata
don't need to override sendMessage. The implicit behavior was bug-prone
since it wasn't obvious you were forgetting that headers may not be
sent.
2015-09-11 17:39:40 -07:00
Eric Anderson f894339923 request() is thread-safe
It is typically used for receiving, but is on the sending object. It
would be a pain for users to coordinate, and the implementation is
already thread-safe because we always thought it would be thread-safe.
So make it part of the documentation.
2015-09-11 17:36:23 -07:00
Eric Anderson 9cb36c6e20 Mark some APIs codegen uses experimental to allow for optimizations
Fixes #975
2015-09-11 11:13:27 -07:00
Carl Mastrangelo f6582d822d Add a hook to set TLS 2015-09-11 10:03:30 -07:00
Eric Anderson 538cf215f0 Add usePlaintext to ManagedChannelBuilder 2015-09-11 09:57:42 -07:00
Eric Anderson 5b2a03a02e Add overrideAuthority to ManagedChannelBuilder
We want to allow overriding authority in the ManagedChannelBuilder for
testing. In doing that, we basically require that all Channels support
authority. In reality, this simplifies things and is already being done
by the C implementation, as their unix domain socket support uses
"localhost" just like our in-process transport now does.

We can debate some whether "localhost" is really the most appropriate
authority for the in-process transport, but that should probably happen
later since "localhost" is "good enough" for now.
2015-09-11 09:37:49 -07:00
Eric Anderson 3ae18eaef1 Add overrideAuthority to NettyChannelBuilder
Although the functionality is currently available by passing a
manually-created InetAddress, that requires that the user do I/O before
calling our API and does not work with naming in the future.
2015-09-11 09:37:43 -07:00
Eric Anderson a6621daca2 Private ServerMethodDefinition constructor; avoid create() in codegen
There is no need to use ServerMethodDefinition in codegen. The create()
method itself could be helpful to a dynamic HandlerRegistry
implementation, so we won't remove it.
2015-09-11 09:25:24 -07:00
Carl Mastrangelo 416b745d8d Add a Server Provider 2015-09-10 12:23:17 -07:00
Eric Anderson df7bf44687 Enable license header checking in checkstyle 2015-09-10 11:29:00 -07:00
Carl Mastrangelo e969a900a0 Add proper generics to ManagedChannelProvider 2015-09-10 09:52:13 -07:00
Eric Anderson 31394aa9df Let transports be channel service providers for generic usage
This provides an API for applications to use gRPC without using
ExperimentalApis. It also allows swapping out a transport implementation
in the future.
2015-09-09 11:06:35 -07:00
Carl Mastrangelo 3cf76326a2 Move decompressor setting to Server Impl 2015-09-08 13:03:27 -07:00
Carl Mastrangelo 950fe1d108 Use ReqT and RespT for generics 2015-09-08 12:51:03 -07:00
Kun Zhang ae4ee40711 Fix flow-control documentation on Stream 2015-09-08 10:20:07 -07:00
Carl Mastrangelo 1ad2bf9eda Add a way to distinguish between advertised message encodings, and add tests 2015-09-04 14:42:45 -07:00
Carl Mastrangelo ebe8a0d703 Remove Metadata.Headers and Metadata.Trailers 2015-09-03 15:22:45 -07:00
Carl Mastrangelo f612746b97 Update comment in MethodDescriptor.Marshaller 2015-09-03 15:10:18 -07:00
Carl Mastrangelo 28d51c5e3e Add an authority header to HandlerRegistry.lookupMethod 2015-09-03 15:03:02 -07:00
Carl Mastrangelo 5d34599390 Daemonize InProcess threads 2015-09-03 14:57:20 -07:00
Louis Ryan 6a782a035e Use Executor in stable builder APIs instead of ExecutorService 2015-09-03 14:38:13 -07:00
Carl Mastrangelo f641e081a0 Daemonize shared threads, and make sure each thread has a name 2015-09-03 14:25:53 -07:00
Eric Anderson 6122dafee0 Add a missing channel builder methods not copied in b687bdc 2015-09-03 12:21:47 -07:00
nmittler b687bdc742 Refactoring channel API.
Client:
* New ManagedChannel abstract class.
* Adding ping to Channel.
* Moving builders and implementations to internal.

Server:
* Added lifecycle management API to Server (mirroring ManagedChannel).
* Moved ServerImpl, AbstractServerBuilder and handler registries to internal.
* New ServerBuilder abstract class (mirroring ManagedChannelBuilder).

Fixes #545
2015-09-03 11:22:29 -07:00
Kun Zhang 65b4e0b1f2 Document valid characters allowed in metadata keys 2015-09-03 10:49:04 -07:00
Xudong Ma 00e024c684 Fix Travis breakage caused by checkStyle failure. 2015-09-03 09:46:22 -07:00
Kun Zhang 609f31a578 Document valid characters for AsciiMarshaller 2015-09-02 15:57:07 -07:00
Carl Mastrangelo f8a87eecce Remove HandlerRegistry.Method 2015-09-02 14:37:44 -07:00
Eric Anderson 01ba973dd4 Prevent status from impacting how ServerCall.Listener is invoked
Fixes #639
2015-09-02 09:48:05 -07:00
Eric Anderson 210114d4a2 Ease use of JWT by passing URI to auth library
The URI no longer needs to be provided to the Credential explicitly,
which prevents needing to know a magic string and allows using the same
Credential with multiple services.
2015-09-01 15:42:58 -07:00
nmittler 6a526ecc93 Adding missing RunWith annotation for tests. 2015-09-01 11:40:17 -07:00
nmittler d3ab427fca Enforce content-type on client and server.
Fixes #360
2015-09-01 06:59:46 -07:00
Eric Anderson 949b6d7da8 Fields in MethodDescriptor can't be null 2015-08-31 17:48:05 -07:00
Carl Mastrangelo 396f0606f3 Add test to prove RST closes stream, and remove hack from transport to force closure. 2015-08-31 13:26:49 -07:00
Carl Mastrangelo d678498ca7 Add unit tests for AbstractServerStream 2015-08-28 13:00:27 -07:00
Stanley Cheung e4987cd1f2 update reference to grpc-common to examples 2015-08-27 16:10:33 -07:00
Carl Mastrangelo 080190c753 Make ServerCall.Listener methods Nops 2015-08-27 13:13:42 -07:00
Carl Mastrangelo 5ade1b726f Make ClientCall listener methods noops 2015-08-27 11:36:59 -07:00
nmittler bcdef34c52 Removing unused method in ServerImpl 2015-08-27 10:26:56 -07:00
nmittler 15f02ba19c Adding maxMessageSize config option
Fixes #832
2015-08-26 15:32:33 -07:00
Carl Mastrangelo 4221f5a81c Change ExperimentalApi field 'comment' to 'value' 2015-08-26 13:40:11 -07:00
Carl Mastrangelo cb734e3049 Document equals and hashCode on Status 2015-08-26 13:31:13 -07:00
Carl Mastrangelo b5eaaf378e Add @ExperimentalApi annotation to compression methods 2015-08-26 13:25:21 -07:00
Kun Zhang 8225d2a6a6 Add comment field to ExperimentalApi 2015-08-26 10:42:08 -07:00
Carl Mastrangelo 0d9ac41bdd Minor cleanup in deframer 2015-08-26 09:58:15 -07:00
nmittler 777e928536 Removing transport shutdown hooks from channel builder
The current process of building a channel is a bit complicated in that transports have to provide a own shutdown hook to the channel builder in order to close shared executors. This somewhat entagled creation pattern makes it difficult to separate the process of channel building from transport building. Better separating these two should make the code more readable and maintainable moving forward.
2015-08-25 08:38:39 -07:00
Xudong Ma 2247ad2a2b Makes application-provided string comes first in User-Agent 2015-08-24 19:42:16 -07:00
Kun Zhang 68c82bc2f3 Make ServerImpl constructor pakcage-private 2015-08-24 15:13:25 -07:00
Xudong Ma c5ea5c78cf Update Java doc for a508c1d4f5 2015-08-24 13:49:51 -07:00
Carl Mastrangelo a508c1d4f5 Remove Headers 2015-08-24 11:41:10 -07:00
Kun Zhang 7b6a498eff Annotate ServerEssentials, buildEssentials() and ServerImpl's constructor with @Internal 2015-08-24 10:17:00 -07:00