Kaynağa Gözat

Improve consumer filter of Dubbo 2.6.x and 2.7.x adapter (#1532)

* entry and exit with params in consumer filter
master
wavesZh GitHub 4 yıl önce
ebeveyn
işleme
f1b63315c1
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
2 değiştirilmiş dosya ile 28 ekleme ve 11 silme
  1. +26
    -9
      sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java
  2. +2
    -2
      sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java

+ 26
- 9
sentinel-adapter/sentinel-apache-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java Dosyayı Görüntüle

@@ -98,7 +98,7 @@ public class SentinelDubboConsumerFilter extends BaseSentinelDubboFilter {
throw e;
} finally {
if (methodEntry != null) {
methodEntry.exit();
methodEntry.exit(1, invocation.getArguments());
}
if (interfaceEntry != null) {
interfaceEntry.exit();
@@ -108,32 +108,49 @@ public class SentinelDubboConsumerFilter extends BaseSentinelDubboFilter {


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();
}
}
}

+ 2
- 2
sentinel-adapter/sentinel-dubbo-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/dubbo/SentinelDubboConsumerFilter.java Dosyayı Görüntüle

@@ -59,7 +59,7 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements
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()) {
@@ -77,7 +77,7 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements
throw e;
} finally {
if (methodEntry != null) {
methodEntry.exit();
methodEntry.exit(1, invocation.getArguments());
}
if (interfaceEntry != null) {
interfaceEntry.exit();


Yükleniyor…
İptal
Kaydet