Commit Graph

728 Commits

Author SHA1 Message Date
Carl Mastrangelo 8d49df28ee all: add max message size to client calls 2017-01-05 17:23:34 -08:00
Carl Mastrangelo 6ed3cbb143 core: fix API breakage in ServerBuilder 2017-01-05 17:22:47 -08:00
Kun Zhang cce8eac56d core: upgrade census (now named instrumentation) to 0.3.0 (#2565)
In upstream, Census is renamed to "Instrumentation". `com.google.census` is renamed to `com.google.instrumentation.stats`.

In gRPC, "census" in every name is replaced by "stats".
2017-01-05 10:48:13 -08:00
Kun Zhang 322eb8c5c5 grpclb: re-implement GrpclbLoadBalancer in v2 API. (#2557)
Besides API changes, this implementation is also up-to-date with the
latest design:

1. Delegate to round-robin and pick-first policies if requested by
the naming system.

2. OOB channels to LoadBalancer always use the LB authority provided by
the naming system.

3. Never send application RPCs to balancer addresses, even if the
address returns UNIMPLEMENTED error.
2016-12-29 15:00:04 -08:00
Kun Zhang 4693492fda style: fix styles and error-prones (#2560)
"Because of spurious wakeups, wait() must always be called in a loop".
Got rid of wait().

"If you return or throw from a finally, then values returned or thrown from the try-catch block will be ignored. Consider using try-with-resources instead."
Ignored the exception thrown from finally.
2016-12-29 11:20:49 -08:00
Łukasz Strzałkowski 661413c2df core: Port PickFirst & RoundRobin LBs to v2 API (#2479) 2016-12-21 10:03:25 -08:00
Kun Zhang a6ecece6f5 doc: more guidelines for LoadBalancer2 implementations. (#2501) 2016-12-16 15:18:59 -08:00
Carl Mastrangelo ce9d152dff all: update to guava 20 2016-12-16 15:15:17 -08:00
Kun Zhang f8f569e078 core: InternalSubchannel uses ChannelExecutor. (#2503) 2016-12-16 14:17:38 -08:00
Kun Zhang 1ba66d38d9 doc: update javadocs in DelayedClientTransport2. (#2522)
Resolves #2521
2016-12-15 13:07:19 -08:00
Carl Mastrangelo f394a93ddb core: add full stack trace in Status.toString
* core: add full stack trace in Status.toString
2016-12-15 08:54:56 -08:00
Kun Zhang 946046abaf core: two changes on DelayedClientTransport2. (#2505)
1. Use ChannelExecutor to run callbacks.  Now callbacks are no longer
run under the delayed transport lock.

2. Use explicit picker version instead of relying on identity equality
to detect new pickers.  Rationale: if reprocess() is called again with
the same picker, all pending streams will be reprocessed by this picker
again, thus there is no reason to leave out the racing new stream.
2016-12-15 08:47:33 -08:00
Anuraag Agrawal 221fadcbdd Implement setListener in AbstractServerStream and remove from subclasses. 2016-12-14 12:29:10 -08:00
Carl Mastrangelo 1f2802a11f core: make forTarget(String) non-experimental 2016-12-14 10:15:12 -08:00
Kun Zhang 178b5260c2 core: handle a race in DelayedClientTransport(2). (#2486)
* Fork DelayedClientTransport into DelayedClientTransport2, and fix a race
on it.  Consider the following sequence:

1. Channel is created. Picker is initially null

2. Channel has a new RPC. Because picker is null, the delayed transport
is picked, but newStream() is not called yet.

3. LoadBalancer updates a new picker to Channel. Channel runs
reprocess() but does nothing because no pending stream is there.

4. newStream() called on the delayed transport.

In previous implementation, newStream() on step 4 will not see the
picker. It will only use the next picker.

After this change, delayed transport would save the latest picker and
use it on newStream(), which is the desired behavior.

Also deleted all the code that will not be used after the LB refactor.


* Also fixed a bug: newStream() should always return a failing stream if it's shutdown. Previously it's not doing so if picker is not null.
2016-12-12 09:24:13 -08:00
Kun Zhang fd33a72174 core: thread-less ChannelExecutor. (#2493)
Dedicated for mutating states of ManagedChannelImpl, InternalSubchannel and LoadBalancer.
2016-12-08 18:38:29 -08:00
Kenji Kaneda 21bca9a475 core: Add @Nullable to Metadata#get 2016-12-08 10:25:21 -08:00
Eric Anderson e999f8da62 core: Fix ErrorProne failure for ForOverride
Methods overriding a ForOverride method should not be public.
2016-12-08 10:08:12 -08:00
Carl Mastrangelo cb1ba5bf39 core: remove extra allocation in MessageFramer
OutputStreamAdapter is a private class, and is only ever called by two
places: ByteStreams.copy, which never calls the single byte method, and
DrainTo, which potentially can.  There are two classes that implement
DrainTo, which is primarily ProtoInputStream.  It calls
MessageLite.writeTo(OutputStream) or back again to ByteStreams.copy.

MessageLite.writeTo in turn wraps the OutputStream in a
CodedOutputStream.OutputStreamEncoder, which then never calls the single
byte version.  Thus, all know implementations never call the single
byte override.

Additionally, it is well known that the single byte write is slow, and
is expected to be wrapped in a BufferedOutputStream if there are many
small writes.
2016-12-05 13:11:06 -08:00
Kenji Kaneda 1d5fd1fa35 core: Fix typos in GrpcUtil
- s/IMPLEMENTATION_VERION/IMPLEMENTATION_VERSION
- s/ACCEPT_ENCODING_SPLITER/ACCEPT_ENCODING_SPLITTER
2016-12-05 11:42:16 -08:00
Carl Mastrangelo 209a32fd1a core,netty: add a log id to the server and server transports 2016-12-05 09:47:35 -08:00
Carl Mastrangelo e9779d7c00 all: use a proper log id which can reference channels, subchannels, and transports 2016-12-02 15:35:11 -08:00
Kun Zhang 7ec8167ada core: LoadBalancer2 and DelayedClientTransport.reprocess(). (#2443)
This is the second step of a major refactor for the LoadBalancer-related part of Channel impl (#1600)
2016-12-02 10:31:34 -08:00
Carl Mastrangelo cbadf4b3e8 internal: mark internal subchannel methods for override 2016-12-02 10:25:46 -08:00
Michael Avrukin 4d4d4b386e core: improve error message for adding method (#2460)
Issue: grpc/grpc-java/issues/2437
2016-12-02 07:45:37 -08:00
Carl Mastrangelo e71f2c942f core: make Status reference the correct internal Marshaller 2016-12-01 08:28:16 -08:00
Kenji Kaneda 5ff16dd4c6 core: Make tiny fixes to InUseStateAggregator2 and InternalSubchannel (#2466)
- Remove unused variable terminated from TransportListener#transportTerminated
- Do not mention getLock in the javadoc of InUseStateAggregator2#handleNotInUse
2016-11-30 16:03:21 -08:00
ZHANG Dapeng b24d263192 internal/test: make FakeClock more thread-safe (#2452)
FackeClock used PriorityQueue for storing tasks which is not
thread-safe, and caused flake

> io.grpc.internal.ClientCallImplTest > deadlineExceededBeforeCallStarted FAILED
>     java.lang.ArrayIndexOutOfBoundsException: -1
>         at java.util.PriorityQueue.removeAt(PriorityQueue.java:619)
>         at java.util.PriorityQueue.remove(PriorityQueue.java:378)
>         at io.grpc.internal.FakeClock$ScheduledTask.cancel(FakeClock.java:89)
>         at io.grpc.internal.ClientCallImpl.removeContextListenerAndCancelDeadlineFuture(ClientCallImpl.java:296)
>         at io.grpc.internal.ClientCallImpl.start(ClientCallImpl.java:250)
>         at io.grpc.internal.ClientCallImplTest.deadlineExceededBeforeCallStarted(ClientCallImplTest.java:615)
2016-11-28 18:14:21 -08:00
Kun Zhang c1a798486b core: address data race in StatsTraceContext. (#2454)
Document the threading requirements.

Turn all metrics to volatile because callEnded() may not be synchronized
with other metric-updating methods in the case where the RPC is closed
because of transport error or cancellation from the other side.

Remove precondition checks thus allow metrics updating methods to be
called after callEnded() has been called, which may happen since the
application may not be aware when the RPC is closed by the transport.
2016-11-28 18:05:41 -08:00
Carl Mastrangelo c408eadf22 core: add javadocs to internal methods in MethodDescriptor 2016-11-28 14:09:16 -08:00
Eric Gribkoff c8c9fff679 services: Proto reflection service 2016-11-28 13:20:55 -08:00
Carl Mastrangelo 6c589e1933 core: reverse dependency from core/internal classes, so that it is now one directional. 2016-11-28 10:27:51 -08:00
Kun Zhang 6a04022d7a core: InternalSubchannel: the new TransportSet. (#2427)
This is the first step of a major refactor for the LoadBalancer-related part of Channel impl (#1600). It forks TransportSet into InternalSubchannel and makes changes on it.

What's changed:

- InternalSubchannel no longer has delayed transport, thus will not buffer
  streams when a READY real transport is absent.
- When there isn't a READ real transport, obtainActiveTransport() will
  return null.
- InternalSubchannel is no longer a ManagedChannel
- Overhauled Callback interface, with onStateChange() replacing the
  adhoc transport event methods.
- Call out channelExecutor, which is a serializing executor that runs
  the Callback.

The first commit is an unmodified copy of the files that are being forked. Please review the second commit which changes on the forked files.
2016-11-22 22:32:27 -08:00
ZHANG Dapeng e70f7b421c all: cleanup - errorprone, unused 2016-11-16 19:15:16 -08:00
Kun Zhang 7311572236 core: fix a benign data race in NoopCensusContextFactory. (#2421)
NoopCensusContextFactory used to use a shared zero-sized ByteBuffer,
which has mutable states like positions and thus is not thread-safe.
Sharing it means it will be used by all calls thus may be used from
different threads, which makes TSAN unhappy in tests.

Resolves #2377
2016-11-15 11:19:20 -08:00
ZHANG Dapeng 0d694c80ee core,netty: quick patch for setListener regression
resolves grpc/grpc#8715
now that setListener is called prior to
`JumpToApplicationThreadServerStreamListener` being completely ready to
use. We should not call `AbstractStream2#onStreamAllocated()` inside
`setListener()` anymore, but call it after `ServerImpl#streamCreated()`
is completed.
2016-11-11 19:39:16 -08:00
ZHANG Dapeng 0e27eef168 core: fix bug when stream listener not set before stream closed
Resolves #1936

Two bugs fixed:
- NPE in `ServerImpl#streamCreated()` when stream listener not set before
  stream closed
- It is possible that `internalCancel()` is called during
  `InProcessClientStream#start()` due to early server `onComplete()` or server `onError()`,
  in this case no need to enlist `streams`, otherwise the channel can not be shutdown by `shutdown()`.
2016-11-09 15:21:11 -08:00
ZHANG Dapeng 809cf1bc8c core: MutableHandlerRegistry#addService with BindableService arg 2016-11-04 18:25:46 -07:00
Eric Anderson 2e7e25d1f2 core: Update HTTP status to gRPC status mapping
Proxies can trigger errors, and we'd like to categorize common
proxy-generating errors into gRPC status codes for sane application
handling.

Fixes #2264
2016-11-01 17:35:18 -07:00
Eric Anderson 78107a69c0 core: Do not rely on HTTP 200
We only want to use the HTTP code for errors, when the response is not
grpc. grpc status codes may be mapped to HTTP codes in the future, and
we don't want to break when that happens. We also don't want to ever
accidentally use Status.OK without receiving it from the server, even
for HTTP 200.
2016-11-01 17:35:15 -07:00
Eric Gribkoff abffc76da2 addressing reviewer comments 2016-10-28 08:45:32 -07:00
Eric Gribkoff aff1cac7da Compiler/core changes to support the proto reflection API
core: adds @Nullable Object getAttachedObject() to ServiceDescriptor

compiler: Plumbing necessary to access proto file descriptors via
the reflection service
2016-10-28 08:45:32 -07:00
Carl Mastrangelo fdd062c465 core: make max message size part of the public API 2016-10-27 14:11:44 -07:00
Eric Anderson 496a621da7 core: Use grace period to avoid exitIdleMode in fast path
Fixes #2119
2016-10-25 13:04:26 -07:00
Carl Mastrangelo 894802e3ec compiler: lazily generate ServiceDescriptors 2016-10-19 16:52:47 -07:00
ZHANG Dapeng abb4a2a393 core: Fix a bug for exception handling at messageRead
Found this bug in some unit test in which client-streaming call is hanging because `ServerCallImpl#messageRead()` did not handle RuntimeException properly
2016-10-13 20:12:48 -07:00
Eric Anderson e7ce41dd94 all: Style, unused, and errorprone fixes 2016-10-12 16:57:01 -07:00
Kun Zhang 132f7a9a33 core: Census integration for stats (#2262)
Highlights
==========

StatsTraceContext
-----------------

The bridge between gRPC library and Census. It keeps track of the total
payload sizes and the elapsed time of a Call. The rest of the gRPC code
doesn't invoke Census directly.

Context propagation
-------------------

StatsTraceContext carries CensusContext (and the upcoming TraceContext)
and is attached to the gRPC Context.

1. StatsTraceContext is created by ManagedChannelImpl, by calling
createClientContext(), which inherits the current CensusContext if available.

2. ManagedChannelImpl passes StatsTraceContext to ClientCallImpl, then
to the stream, then to the framer and deframer explicitly.

3. ClientCallImpl propagates the CensusContext to the headers.

1. ServerImpl creates a StatsTraceContext by implementing a new callback
method StatsTraceContext methodDetermined(MethodDescriptor, Metadata) on
ServerTransportListener.

2. NettyServerHandler calls methodDetermined() before creating the
stream, and passes the StatsTraceContext to the stream.

3. When ServerImpl creates the gRPC Context for the new ServerCall, it
calls the new method statsTraceContext() on ServerStream and puts the
StatsTraceContext in the Context.

Metrics recording
-----------------

1. Client-side start time: when ClientCallImpl is created

2. Server-side start time: when methodDetermined() is called

3. Server-side end time: in ServerStreamListener.closed(), but before
calling onComplete() or onCancel() on ServerCall.Listener.

4. Client-side end time: in ClientStreamListener.closed(), but before
calling onClonse() on ClientCall.Listener

Message sizes are recorded in MessageFramer and MessageDeframer. Both
the uncompressed and wire (possibly compressed) payload sizes are
counted.

TODOs
=====

The CensusContext created from headers on the server side should be
attached to the gRPC Context for the call.  It's not done at this moment
because Census lacks the proper API to do it. It only affects tracing
and resource accounting, but doesn't affect stats functionality
2016-10-06 17:15:24 -07:00
dapengzhang0 4e5765a93f all: fix minor JavaStyle errors found in code sync 2016-10-05 09:28:16 -07:00
Eric Anderson cad7124c27 core,netty: split stream state on client-side; AbstractStream2
OkHttp will need to be migrated in a future commit.
2016-10-03 11:10:38 -07:00