-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to invoke Thrift service impls from BlockingTaskExecutor
#5619
Conversation
if (useBlockingTaskExecutor) { | ||
ctx.blockingTaskExecutor().execute( | ||
() -> invoke(ctx, serializationFormat, seqId, f, decodedReq, httpRes) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we think invoke()
is only thing that we should wrap with ctx.blockingTaskExecutor()
.
If not, please share to us~! 🙇
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/THttpService.java
Outdated
Show resolved
Hide resolved
@Override | ||
public void get(TestServiceRequest request, | ||
AsyncMethodCallback resultHandler) throws TException { | ||
resultHandler.onComplete(new TestServiceResponse(request.getMessage())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could we check whether the current thread is the blocking task executor?
- Should we also check
TestService.Iface
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check whether the current thread is the blocking task executor?
I checked it here
Line 81 in 6649eee
assertThat(blocking).isFalse(); |
Should we also check TestService.Iface?
Fixed it. Because of Iface, only verified the current thread is blocking executor without adding useBlockingTaskExecutor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. 👍
Left minor suggestions. 😉
...ft/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpServiceBlockingTest.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpServiceBlockingTest.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/THttpService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, @ChangguHan 👍 👍 👍
Thanks!
Oops, I realized that we also need to fix ThriftCallService not to use blocking task executor twice: armeria/thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java Line 186 in 10424c7
private static void invoke(
ServiceRequestContext ctx,
Object impl, ThriftFunction func, List<Object> args, CompletableRpcResponse reply) {
try {
final TBase<?, ?> tArgs = func.newArgs(args);
if (func.isAsync()) {
invokeAsynchronously(impl, func, tArgs, reply);
} else if (ctx.eventLoop().inEventLoop()) {
invokeSynchronously(ctx, impl, func, tArgs, reply);
} else {
invokeSynchronously0(ctx, impl, func, tArgs, reply);
}
} catch (Throwable t) {
reply.completeExceptionally(t);
}
}
private static void invokeSynchronously(
ServiceRequestContext ctx, Object impl,
ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
ctx.blockingTaskExecutor().execute(() -> invokeSynchronously0(ctx, impl, func, args, reply));
}
private static void invokeSynchronously0(
ServiceRequestContext ctx, Object impl,
ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
...
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether to delegate the call to the blocking task executor should be decided by ThriftCallService
, not THttpService
.
...ft/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpServiceBlockingTest.java
Outdated
Show resolved
Hide resolved
@trustin armeria/thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java Lines 125 to 139 in 0963905
|
@minwoox Thank you for your review. |
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks almost done once @trustin 's comments are addressed 👍
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
*/ | ||
public ThriftCallServiceBuilder addService(String key, Object implementation) { | ||
requireNonNull(implementation, "implementation"); | ||
this.implementations.put(key, ImmutableList.of(implementation)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.implementations.put(key, ImmutableList.of(implementation)); | |
implementations.put(key, ImmutableList.of(implementation)); |
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java
Show resolved
Hide resolved
...ft/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpServiceBlockingTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left minor comments. 👍
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
...ft/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallServiceBuilder.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/thrift/ThriftDynamicTimeoutTest.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/thrift/ThriftDynamicTimeoutTest.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/thrift/ThrottlingRpcServiceTest.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/thrift/ThrottlingRpcServiceTest.java
Outdated
Show resolved
Hide resolved
thrift/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpClientTest.java
Outdated
Show resolved
Hide resolved
assertTrue(service.entries().containsKey("")); | ||
final Iterator<?> defaultIterator = service.entries().get("").implementations.iterator(); | ||
assertEquals(defaultServiceImpl, defaultIterator.next()); | ||
assertFalse(defaultIterator.hasNext()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the assertion logic of this test method is not easy to read. How about building a map that contains the expected keys and values and just compare it to the return value of service.entries()
? e.g.
final Map<String, List<Object>> actualEntries = service.entries().entrySet().stream()....collect(...);
final Map<String, List<Object>> expectedEntries = ImmutableMap.builder()...build();
assertThat(actualEntries).isEqualsTo(expectedEntries);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it.
Would you check this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me once the build reliably passes 👍 👍 👍
resultHandler.onComplete(name); | ||
blocking.set(Thread.currentThread().getName().startsWith(BLOCKING_EXECUTOR_PREFIX)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; swapping these two may help with flakiness. Otherwise, the response may be sent back and the main test thread may proceed before the blocking value is set
resultHandler.onComplete(name); | |
blocking.set(Thread.currentThread().getName().startsWith(BLOCKING_EXECUTOR_PREFIX)); | |
blocking.set(Thread.currentThread().getName().startsWith(BLOCKING_EXECUTOR_PREFIX)); | |
resultHandler.onComplete(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrhee17 Thank you for your comment. I applied it.
By the way, how can I know which test is failed from failed build?
I cannot find the failed tests from CI/CD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChangguHan You can check the build scan reports here: #5619 (comment) which are updated when builds are complete. Open the report and go to the 'Tests' section to browse the test result report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, there's only one failed job and it failed due to a flaky test which seems irrelevant to your work, so it's all good! 🟢 https://ge.armeria.dev/s/yq5kpsjeqryju/tests/overview
...ft/thrift0.13/src/test/java/com/linecorp/armeria/server/thrift/THttpServiceBlockingTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ChangguHan! 🙇♂️👍
"barMap", ImmutableList.of(barServiceImpl), | ||
"fooIterableMap", ImmutableList.of(fooServiceImpl, barServiceImpl)); | ||
|
||
assertThat(actualEntries).isEqualTo(expectedEntries); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for cleaning this up!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @ChangguHan! 🙇
BlockingTaskExecutor
Revised and cleaned up the PR description and commit message. |
Nice work @ChangguHan !!! 👍👍 |
Related issue: #4917
Motivation:
There's currently no way to make Thrift services run from
the
BlockingTaskExecutor
.Modifications:
useBlockingTaskExecutor
propertyThriftCallServiceBuilder
to buildThriftCallService
fluentlyThriftCallService
now calls the service implementation fromthe
BlockingTaskExecutor
if configured so.Result:
from the
BlockingTaskExecutor
for Thrift services.