Skip to content
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

Dubbo adapter: entry exit with param #1532

Merged
merged 21 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private Result syncInvoke(Invoker<?> invoker, Invocation invocation) {
throw e;
} finally {
if (methodEntry != null) {
methodEntry.exit();
methodEntry.exit(1, invocation.getArguments());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very careful code! How about also update SentinelDubboConsumerFilter in sentinel-dubbo-adaptor module to keep them in line, though they are for different version of dubbo.

Copy link
Contributor Author

@wavesZh wavesZh Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConsumerFilter in sentinel-dubbo-adaptor don't take param when entry currently. Should I add param when entry and exit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does't take param when entry currently, users may feel confused and suggest them to be consistent.

}
if (interfaceEntry != null) {
interfaceEntry.exit();
Expand All @@ -108,32 +108,49 @@ private Result syncInvoke(Invoker<?> invoker, Invocation invocation) {


private Result asyncInvoke(Invoker<?> invoker, Invocation invocation) {
LinkedList<Entry> queue = new LinkedList<>();
LinkedList<EntryHolder> queue = new LinkedList<>();
String methodResourceName = getMethodName(invoker, invocation);
String interfaceResourceName = getInterfaceName(invoker);
try {
queue.push(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT));
queue.push(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()));
queue.push(new EntryHolder(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT), null));
queue.push(new EntryHolder(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()), invocation.getArguments()));
Result result = invoker.invoke(invocation);
result.whenCompleteWithContext(new BiConsumer<Result, Throwable>() {
@Override
public void accept(Result result, Throwable throwable) {
while (!queue.isEmpty()) {
Entry entry = queue.pop();
Tracer.traceEntry(result.getException(), entry);
entry.exit();
EntryHolder holder = queue.pop();
Tracer.traceEntry(result.getException(), holder.entry);
exitEntry(holder);
}
}
});
return result;
} catch (BlockException e) {
while (!queue.isEmpty()) {
queue.pop().exit();
exitEntry(queue.pop());
}
return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e);
}
}

}
class EntryHolder {

final private Entry entry;

final private Object[] params;

public EntryHolder(Entry entry, Object[] params) {
this.entry = entry;
this.params = params;
}
}

private void exitEntry(EntryHolder holder) {
if (holder.params != null) {
holder.entry.exit(1, holder.params);
} else {
holder.entry.exit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
String resourceName = getResourceName(invoker, invocation, DubboConfig.getDubboConsumerPrefix());
interfaceEntry = SphU.entry(invoker.getInterface().getName(), ResourceTypeConstants.COMMON_RPC,
EntryType.OUT);
methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT);
methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, invocation.getArguments());

Result result = invoker.invoke(invocation);
if (result.hasException()) {
Expand All @@ -77,7 +77,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
throw e;
} finally {
if (methodEntry != null) {
methodEntry.exit();
methodEntry.exit(1, invocation.getArguments());
}
if (interfaceEntry != null) {
interfaceEntry.exit();
Expand Down