Commit Graph

244 Commits

Author SHA1 Message Date
Eric Anderson 613439c97e stub: Reorder blocking request()s for message throughput
This can provide a ~2x performance increase to Netty and 40% increase
for OkHttp. Netty async saw a ~3x gain from MigratingDeframer, so
blocking trails behind a bit. But OkHttp's async gains from
MigratingDeframer were also 40%, so this provides the same gain to
blocking.
2020-06-18 15:48:29 -05:00
Eric Anderson c3ea8e7c91 stub: Document blocking exceptions and async extension types
invoke() needed to be re-defined for Javadoc to display the method.
2020-06-10 16:19:13 -05:00
Eric Anderson 0201c5a9a7
stub: Have disableAutoRequest() on server-side
This splits server-side flow control from client-side, but tailors the API for
each case. Client-side continues having disableAutoRequestWithInitial(). While
client-side could have disableAutoRequest(), it seems like it will only rarely
be used and disableAutoRequestWithInitial(0) isn't that bad. So we leave it off
for now; we can always add it in the future.
2020-05-29 15:05:46 -07:00
Ran c5740f893c
Stub: add an util method for setting StubType. (#7045) 2020-05-15 11:45:17 -07:00
Jihun Cho 24823c741f
stub: default impl for disableAutoRequestWithInitial(int) (#7018) 2020-05-07 12:47:28 -07:00
DRayX a9250c1f99
stub: Add disableAutoRequestWithInitial that disables all automatic inbound flow-control requests
Add a new disableAutoRequest method that disables all automatic requests while disableAutoInboundFlowControl maintains existing behavior.

The default behavior of requesting initial messages is applied even if disableAutoInboundFlowControl is called. ServerCalls disables all automatic flow control which is much more useful in case the user can't handle incoming messages until some time after the call has started.  This change creates a new StartableListener that has an onStart method that is invoked when the call is started which makes initial requests if necessary.

See #6806
2020-05-06 10:19:41 -07:00
Eric Anderson 4674b27736 api,stub: Improve waitForReady documentation 2020-04-30 16:03:52 -07:00
Ran 37913fd3b1
stub: add Blocking StubType to blocking ClientCalls methods. (#6900) 2020-04-06 10:55:24 -07:00
Chengyuan Zhang 2734e22ef5
context, stub: check result of CountDownLatch.await() in test (#6664) 2020-01-31 15:03:22 -08:00
Roman Leventov 589a645a38 stub,examples: Clarify CallStreamObserver's Javadoc (#6561)
* Clarify CallStreamObserver's Javadoc
* Remove unnecessary AtomicBoolean and clarify a comment in ManualFlowControlServer
2020-01-28 11:32:09 -08:00
Jihun Cho 16ba163291 stub: fix javadoc to indicate correct version(1.25.0 -> 1.26.0) 2019-12-16 17:08:04 -08:00
Jihun Cho 7db873f1f6
Roll-forward of stub,compiler: generated stub extends Abstract{Async,Future,Blocking}Stub #6196 (#6458)
This reverts commit 2eb3f8c34e (#6317).
2019-11-25 09:41:16 -08:00
Eric Anderson 44b26dab9d stub: Provide bread-crumb to user how to configure StreamObserver before start
This is already in the documentation in CallStreamObserver, but if the user
gets here the error didn't provide an actionable next step. The message now
provides more help of how they should have called the methods instead of
feeling more like a brick wall.
2019-11-20 15:10:39 -08:00
Ran 258a95d0c4
Revert "stub: ignore unary response msg if status is not OK (#6288)" (#6342)
This reverts commit fe46edac
2019-10-28 10:05:28 -07:00
sanjaypujare 7dbf12fe2a
api,stub : fix 2 typos (CallCredentials2 to CallCredentials and javadoc comment in AbstractStub) (#6343) 2019-10-28 10:03:49 -07:00
Jihun Cho 2eb3f8c34e
stub,compiler: Rollback Abstract{Future,Blocking,Async}Stub (#6317)
rollback of #6304 & #6196
2019-10-22 13:27:30 -07:00
Jihun Cho ae11b9facc
api,core,stub: fix lint errors (#6305) 2019-10-18 17:30:00 -07:00
Jihun Cho ecbc5e4f47
stub: add RunWith for AbstractStub tests (#6304) 2019-10-18 16:30:48 -07:00
Ran fe46edacea
stub: ignore unary response msg if status is not OK (#6288)
* stub: ignore unary response msg if status is not OK

* stub: throw if no msg with OK status

* address the comment, improve tests.

* fix error message

* fix error message

* improve naming of the tests

* call onCompleted on success unary flow

* fix test

* handle errors for delayed unary message sending

* clean up the onCompleted/onError logic

* use hasMessageThat to produce better error message when fail
2019-10-17 14:49:53 -07:00
Jihun Cho 45d49a56cc
stub,compiler: generated stub extends Abstract{Async,Future,Blocking}Stub (#6196) 2019-10-17 14:49:24 -07:00
Chengyuan Zhang 0ec31c683e
Revert "Revert "stub: Wait for onClose when blocking stub is interrupted"" (#6255)
This reverts commit 0604e14154.
2019-10-07 11:40:20 -07:00
Carl Mastrangelo 148b7de357
stub: avoid race in onHalfClose server StreamObserver 2019-07-19 12:24:34 -07:00
Carl Mastrangelo 7657523b28
all: update to error prone 2.3.3 2019-06-05 15:28:43 -07:00
Eric Anderson bc2e1764f6 api,stub: Clarify isReady()/onReady() interaction semantics 2019-05-29 17:28:45 -07:00
Jihun Cho d50c8d4ec1
stub: improve error message for Client/ServerCalls (#5656) 2019-05-01 17:13:07 -07:00
Eric Anderson 0604e14154 Revert "stub: Wait for onClose when blocking stub is interrupted"
This reverts commit 6d44f46f18.

This is causing a test to hang internally. I am currently expecting that
the shutdown logic of the test is broken, but it will take time to
diagnose. Thus, revert this for the moment.
2019-04-26 08:59:45 -07:00
Vladimir Gordiychuk f631b3d249 stub: release server-streaming reference on request after method call 2019-04-26 08:58:42 -07:00
Eric Anderson 6d44f46f18
stub: Wait for onClose when blocking stub is interrupted
Interceptors need to see the onClose to clean up properly.

This also changes an isInterrupted() to interrupted(), since previously
the interrupted flag was still set when InterruptedException was thrown.
This caused an infinite loop with the new code. Previously, all callers
immediately re-set the interrupted flag, so there was no issue.

Fixes #5576
2019-04-22 16:32:06 -07:00
Nick Hill 5f88bc42bf stub: optimize ThreadlessExecutor used for blocking calls
The `ThreadlessExecutor` currently used for blocking calls uses `LinkedBlockingQueue` which is relatively heavy both in terms of allocations and synchronization overhead (e.g. when compared to `ConcurrentLinkedQueue`). It accounts for ~10% of allocations and ~5% of allocated bytes per-call in the `TransportBenchmark` when using in-process transport with [stats and tracing disabled](https://github.com/grpc/grpc-java/issues/5510).

Changing to use a `ConcurrentLinkedQueue` results in a ~5% speedup of that benchmark.

Before:
```
Benchmark                         (direct)  (transport)  Mode  Cnt      Score     Error  Units
TransportBenchmark.unaryCall1024      true    INPROCESS  avgt   60   1877.339 ±  46.309  ns/op
TransportBenchmark.unaryCall1024     false    INPROCESS  avgt   60  12680.525 ± 208.684  ns/op
```

After:
```
Benchmark                         (direct)  (transport)  Mode  Cnt      Score     Error  Units
TransportBenchmark.unaryCall1024      true    INPROCESS  avgt   60   1779.188 ±  36.769  ns/op
TransportBenchmark.unaryCall1024     false    INPROCESS  avgt   60  12532.470 ± 238.271  ns/op
```
2019-03-29 10:45:23 -07:00
Eric Anderson 656dcc1c7c core,stub: Document grpc performs compression nego on server 2019-03-11 15:36:21 -06:00
Carl Mastrangelo 3a39b81cf5
all: remove java6 type args 2019-02-04 10:03:50 -08:00
Kun Zhang 8706a37a3b
doc: fix a javadoc warning (#5136) 2018-12-06 21:51:34 -08:00
Ze'ev Klapow 9111602d7c StreamObservers: make sure onComplete only gets called once from onReadyHandler
Fixes #4558
2018-12-05 12:59:09 -08:00
Venil Noronha 3f4c3f0406 stub: disable exception if onCancelHandler set
This restrains a cancellation Exception when an onCancelHandler
is set in ServerCallStreamObserverImpl.

Signed-off-by: Venil Noronha <veniln@vmware.com>
2018-11-30 18:36:12 -06:00
ST-DDT 417c41b6cb stub: fix null check in MetadataUtils.
Fixes #5045
2018-11-13 08:35:47 -08:00
Carl Mastrangelo b0f423295b
all: use Java7 brackets 2018-09-14 13:52:29 -07:00
ZHANG Dapeng a18abfbf9f
stub: stablize AbstractStub.withExecutor API
Resolves #3605
2018-08-29 11:58:13 -07:00
zpencer 0d79e7a13c
stub: disableAutoInboundFlowControl javadoc correction (#4785)
The docs refer to the wrong places where this feature is ignored.
2018-08-23 15:54:47 -07:00
Carl Mastrangelo 6d4841a8c2
stub: update docs about Call lifetime + minor cleanups
* Reflowed some method parameters to be on the same line, else one
  parameter per line
* Used `@link` where appropriate
* Made some parameters non-final where it had no effect
* Renamed some parameters to be consistent
2018-08-13 14:36:32 -07:00
Carl Mastrangelo 85448189ee
all: add tracking issues for all experimental APIs and make it required
Additionally, make Status*Exception.getTrailers() non experimental
2018-07-31 15:28:48 -07:00
Eric Anderson 15a5ba2698 Remove DoNotMock annotation in favor of JavaDoc
DoNotMock was removed from error_prone_annotations in 2.1.3, because
there was no enforcement mechanism (which is in google/error-prone#572).
Guava and Trust also depend on error_prone_annotations and are beginning
to use newer versions, so our usage of DoNotMock is causing diamond
dependency problems. This allows us to update to 2.2.0.

The annotations were useful internally; we're solving that in cl/205294089.
2018-07-20 14:03:55 -07:00
Carl Mastrangelo 146b6006b3
compiler,stub: update RpcMethod docs and usage 2018-07-12 17:01:47 -07:00
jbingham-google ffcb3b964b compiler, stub: Rename inputType and outputType in @RpcMethod 2018-07-10 13:24:50 -07:00
jbingham-google 9229e30287 compiler, stub: Add @RpcMethod annotation
This annotation will enable Java APT to generate code.

Addresses part of #3173.
2018-07-06 17:02:01 -07:00
Carl Mastrangelo 7edb41a4ef
stub: clarify StreamObservers interaction 2018-06-26 15:43:13 -07:00
Grant Oakley dbf9bd2158 stub: add @CheckReturnValue to AbstractStub 2018-05-04 15:46:34 -07:00
Carl Mastrangelo 60a0b0c471
all: normalize copyright header 2018-05-03 14:55:21 -07:00
ZHANG Dapeng d50c191aca
core/stub: fix lint warnings 2018-05-02 10:37:32 -07:00
Grant Oakley fcb48ff216 core,stub: Add toString() to ClientCallImpl and GrpcFuture 2018-05-01 16:49:56 -07:00
Eric Anderson 4bc0c95d0b Update ErrorProne to 2.1.3 and fix failures
The fixes could have subtle side-effects, but I did take care when making them.
2018-01-09 12:40:55 -08:00
Carl Mastrangelo c9b02db276
all: add Status messages to all statuses 2017-12-04 19:00:16 -08:00
Eric Anderson 5a87a6fff6 stub: Improve threading expectation docs
This mainly copies documentation from other places, like StreamObserver
and ClientCall, but does fix some missing important threading notes.

Fixes #3413
2017-11-10 13:10:17 -08:00
Carl Mastrangelo de408e0a86
stub: update ServerCalls to include status messages
Additionally:

* Prefer RuntimeException from status
* remove redundant "static" on interfaces
* use checkState to shorten code
2017-11-02 14:03:17 -07:00
Carl Mastrangelo 37a67bf041
stub: clean up call cancellation 2017-11-01 17:15:37 -07:00
ZHANG Dapeng c90f27f454 stub: add withExecutor API 2017-10-24 14:00:45 -07:00
Carl Mastrangelo 765a40c7e6 stub: avoid mocking stub classes 2017-10-05 11:01:57 -07:00
Eric Anderson 9be41ba0e8 core,auth: Stabilize auth flow using CallCredentials
As discussed in #1914, we need CallCredentials and MoreCallCredentials
to be stable, but there's less of a strong need for the contents of
CallCredentials to be stable. We're willing to commit to the name,
without needing to commit to the plumbing.
2017-07-27 18:07:18 -07:00
Ryan Michela 3731a5dfcc Implemented ClientCallStreamObserver.cancel() 2017-07-25 14:36:51 -07:00
Carl Mastrangelo f735fc1907 stub: name more anonymous classes 2017-07-14 13:38:27 -07:00
Carl Mastrangelo 193fd057a5 stub: clean up client calls to avoid synthetic class 2017-07-14 13:38:04 -07:00
Carl Mastrangelo d387bfe72f stub: Use named classes rather than anonymous in ServerCalls
This has a number of small benefits.  First, it makes stack traces
easier to read.  For example:

Old class names:
```
ServerCalls$1$1.class
ServerCalls$1.class
ServerCalls$2$1.class
ServerCalls$2.class
```

New class names:
```
ServerCalls$StreamingServerCallHandler.class
ServerCalls$StreamingServerCallHandler$StreamingServerCallListener.class
ServerCalls$UnaryServerCallHandler.class
ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.class
```

This is much easier to read quickly, espcially if line numbers don't
match between HEAD and the code that prints the stack trace.

Another benefit of this is that it drops a class file from the jar
(`EmptyServerCallListener`).

Lastly, it makes it easier in the future to test, since the specific
class can be referenced from a test.  Traditionally this class
hasn't been easy to test.
2017-07-13 14:33:25 -07:00
ZHANG Dapeng 29befc131d doc: update external link 2017-07-12 16:31:55 -07:00
Mehrdad Afshari 68d73fa4d6 doc: Uppercase Java 2017-07-12 14:35:56 -07:00
Mehrdad Afshari 8ce0bc25b6 Canonicalize URL prefixes to https://grpc.io 2017-07-10 16:30:09 -07:00
ZHANG Dapeng b7e50ddd05 testing: move NoopClientCall & NoopServerCall to internal
one step for #3105
2017-06-22 15:10:58 -07:00
zpencer 532450996a core: detect invalid states on server side (eg zero responses for unary) (#3068)
The current check in ServerCallImpl is theoretically unsafe (#3059). Move that check into the stub, and expand the unit tests to cover other interesting edge cases on the server side:

client sends one, but zero requests received at onHalfClose
client sends one, but > 1 requests received at onHalfClose
server sends one, but zero responses sent at onComplete
server sends one, but > 1 responses sent via onNext
fixes #2243
fixes #3059
2017-06-15 09:33:01 -07:00
Carl Mastrangelo 166108a943 all: fix licence whitespace 2017-06-01 14:28:37 -07:00
Carl Mastrangelo 3bfd630bff all: update to Apache 2 licence
Also, update the authors.
2017-05-31 13:29:01 -07:00
Eric Anderson eb6acfe186 Javadoc improvements, especially to Context 2017-05-15 10:12:44 -07:00
ZHANG Dapeng bb978bac31 doc: initiate some package javadoc
Initated package javadoc for 
* `io.grpc.stub`, 
* `io.grpc.auth`, 
* `io.grpc.util`, 
* `io.grpc.protobuf`, 
* `io.grpc.protobuf.lite`,
* `io.grpc.protobuf.nano`
2017-05-10 11:29:07 -07:00
ZHANG Dapeng b2b6745868 stub: rm redundant call field in StreamObserverToCallListenerAdapter
All that the `call` field was used for was to call `request` and nothing else. The `request` can be done by the `adapter` field, so the `call` field is redundant.
2017-04-27 13:10:53 -07:00
Carl Mastrangelo 6d44f2ffa4 stub: document withChannel and document method history 2017-03-15 13:31:09 -07:00
Carl Mastrangelo 89bc2cd3b2 all: update to latest import ordering 2017-01-26 13:43:06 -08:00
Carl Mastrangelo efbcd1f1b9 core: change method descriptor to be builder based 2017-01-23 12:29:35 -08:00
ZHANG Dapeng 018e2d5307 all: make some api non-experimental for 1.1 2017-01-20 16:34:56 -08:00
Carl Mastrangelo 8e463ce1a8 core,stub: remove deprecated deadline methods 2017-01-10 15:54:38 -08:00
Carl Mastrangelo 8d49df28ee all: add max message size to client calls 2017-01-05 17:23:34 -08:00
Carl Mastrangelo f15ed05260 stub: remove a reference to internal 2016-12-02 09:13:37 -08:00
ZHANG Dapeng 6dc4633bdd stub: add withWaitForReady 2016-11-28 18:13:22 -08:00
Carl Mastrangelo 893ef44b4c all/tests: add a ClientCall and ServerCall suitable for use in tests 2016-09-02 17:09:49 -07:00
Carl Mastrangelo 48c6b3d398 all/tests: unmock ClientCall and ServerCall 2016-08-30 09:58:02 -07:00
Carl Mastrangelo 8894769cdf stub: make more classes final 2016-08-26 15:39:43 -07:00
Carl Mastrangelo 1285477133 all: add parameter name to checkNotNull
After debugging #2153, it would have been nice to know what the exact
parameter was that was null. This change adds a name for each
checkNotNull (and tries to normalized on static imports in order to
shorten lines)
2016-08-12 14:55:00 -07:00
Eric Anderson fb8402fcb1 stub: Avoid double-wrapping status
780b2696 caused all failures for blocked unary stubs to have a
StatusRuntimeException as the cause of the StatusRuntimeException, with
the two exceptions having almost the same status.
2016-08-01 09:53:57 -07:00
Carl Mastrangelo 297af4425e netty: always flush at least once, even if there were no writes 2016-07-19 11:18:54 -07:00
nmittler 780b2696c1 Ensure that trailers are not lost when making blocking calls.
Fixes #2036
2016-07-18 15:47:57 -07:00
Eric Anderson 32fd329e1c core: Rename withCredentials to withCallCredentials on CallOptions
It was withCallCredentials on the stub to avoid confusion with channel
credentials (which don't exist in Java at this time, but do in other
languages), and having the method names be different doesn't add value.
2016-07-01 11:18:38 -07:00
Eric Anderson 29776ca947 core: Fix onReady race by adding DelayedStreamListener
onReady/isReady previously could disagree causing a sort of deadlock
where the application isn't sending because grpc said not to, but won't
be informed to send via onReady later.

This is a stack trace from inprocessTransportOutboundFlowControl. The
line numbers are from this commit but with the changes to DelayedStream
disabled:

at io.grpc.internal.DelayedStream.isReady(DelayedStream.java:306)
  (That is isReady returning false because fallThrough == false)
at io.grpc.internal.ClientCallImpl.isReady(ClientCallImpl.java:382)
at io.grpc.stub.ClientCalls$CallToStreamObserverAdapter.isReady(ClientCalls.java:289)
at io.grpc.stub.ClientCallsTest$8$1.run(ClientCallsTest.java:403)
  (And yet that was the onReady callback, and it won't be called again)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onReady(ClientCalls.java:377)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$4.runInContext(ClientCallImpl.java:481)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializeReentrantCallsDirectExecutor.execute(SerializeReentrantCallsDirectExecutor.java:65)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.onReady(ClientCallImpl.java:478)
at io.grpc.internal.DelayedStream$DelayedStreamListener.onReady(DelayedStream.java:366)
at io.grpc.inprocess.InProcessTransport$InProcessStream$InProcessServerStream.request(InProcessTransport.java:284)
at io.grpc.internal.ServerCallImpl.request(ServerCallImpl.java:99)
at io.grpc.stub.ServerCalls$ServerCallStreamObserverImpl.request(ServerCalls.java:345)
at io.grpc.stub.ClientCallsTest.inprocessTransportOutboundFlowControl(ClientCallsTest.java:432)

Fixes #1932
2016-06-27 13:35:52 -07:00
Carl Mastrangelo b55a2bfb3f core: clarify StreamObserver documentation
Fixes #986
2016-06-27 08:20:21 -07:00
Eric Anderson 5487ea8f54 Remove unused variables
This fixed a threading issue in ServerImpl because the unused variable
should have been used.
2016-06-24 12:11:03 -07:00
Eric Anderson 66ab956f9e Reapply "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit ef178304cb, which
itself was a revert.
2016-06-23 09:27:47 -07:00
Eric Anderson ef178304cb Revert "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit 3df1446deb.

The commit was adding to the difficulty of integration for testing. By
itself it isn't bad, so this is a temporary revert until the many other
commits are absorbed and then it will be reapplied.

This does have a manual edit for ClientCallsTest.
2016-06-20 15:18:18 -07:00
Eric Anderson 26fb347f40 stub: Disable flaky test in ClientCallsTest (#1938)
The test has found a legitimate flake caused by a race in DelayedStream
related to onReady. Disable it until the fix arrives to prevent CI
failure noise.
2016-06-15 21:30:26 -07:00
Eric Anderson 93c34ef008 stub: Improve ClientCall test to fail more obviously
If the timoutout expires, the test will almost certainly fail now due to
responses not matching expected responses, but it isn't as obvious why
the test fails. Swapping to ArrayList prints the entire list when they
don't match, which also makes it easier to diagnose.

This is, in part, to help diagnose #1932
2016-06-15 17:03:20 -07:00
Louis Ryan b681a07f6c Introduce ClientResponseObsever to capture call initiation and to allow
for capture of the CallStreamObserver
2016-06-14 10:18:48 -07:00
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
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
elandau 90323ad5d4 core: add custom CallOptions 2016-06-02 09:14:48 -07:00
Eric Anderson 7052d8b5e9 core: Promote Deadline API to stable
Fixes #1706
2016-05-26 13:33:48 -07:00
nmittler c102dd4e4f Add trailers to Status for BlockingResponseStream
Fixes #1861
2016-05-25 12:04:55 -07:00