You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/04/22 11:41:29 UTC
[pulsar] branch master updated: [Tests] Adapt FastThreadLocalStateCleaner to Netty changes: suppress excessive logging (#15269)
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 2e5309cb748 [Tests] Adapt FastThreadLocalStateCleaner to Netty changes: suppress excessive logging (#15269)
2e5309cb748 is described below
commit 2e5309cb74895cf7a635ee2652dc7cc77a388e72
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Fri Apr 22 14:41:17 2022 +0300
[Tests] Adapt FastThreadLocalStateCleaner to Netty changes: suppress excessive logging (#15269)
- suppresses this warning log entry:
java.lang.RuntimeException: It's not thread-safe to get 'threadLocalMap' which doesn't belong to the caller thread
at io.netty.util.concurrent.FastThreadLocalThread.threadLocalMap(FastThreadLocalThread.java:80) ~[netty-common-4.1.76.Final.jar:4.1.76.Final]
---
.../apache/pulsar/tests/FastThreadLocalStateCleaner.java | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/buildtools/src/main/java/org/apache/pulsar/tests/FastThreadLocalStateCleaner.java b/buildtools/src/main/java/org/apache/pulsar/tests/FastThreadLocalStateCleaner.java
index b16c7b85792..05dbae115f1 100644
--- a/buildtools/src/main/java/org/apache/pulsar/tests/FastThreadLocalStateCleaner.java
+++ b/buildtools/src/main/java/org/apache/pulsar/tests/FastThreadLocalStateCleaner.java
@@ -20,14 +20,12 @@ package org.apache.pulsar.tests;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.ThreadUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.apache.commons.lang3.reflect.MethodUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,13 +38,13 @@ public final class FastThreadLocalStateCleaner {
private static final Logger LOG = LoggerFactory.getLogger(FastThreadLocalStateCleaner.class);
private static final ThreadLocal<?> SLOW_THREAD_LOCAL_MAP = lookupSlowThreadLocalMap();
private static final Class<?> FAST_THREAD_LOCAL_CLASS;
- private static final Method GET_THREAD_LOCAL_MAP;
+ private static final Field THREAD_LOCAL_MAP_FIELD;
private static final Field INDEXED_VARIABLES_FIELD;
private static final Object UNSET_OBJECT;
static {
Class<?> clazz = null;
- Method getThreadLocalMapMethod = null;
+ Field threadLocalMapField = null;
Field indexedVariablesField = null;
Object unsetObject = null;
if (SLOW_THREAD_LOCAL_MAP != null) {
@@ -54,8 +52,8 @@ public final class FastThreadLocalStateCleaner {
clazz = ClassUtils.getClass("io.netty.util.concurrent.FastThreadLocalThread");
Class<?> internalThreadLocalMapClass =
ClassUtils.getClass("io.netty.util.internal.InternalThreadLocalMap");
- getThreadLocalMapMethod = MethodUtils
- .getMatchingAccessibleMethod(clazz, "threadLocalMap");
+ threadLocalMapField = FieldUtils
+ .getDeclaredField(clazz, "threadLocalMap", true);
indexedVariablesField = FieldUtils.getDeclaredField(internalThreadLocalMapClass,
"indexedVariables", true);
Field unsetField = FieldUtils.getField(internalThreadLocalMapClass, "UNSET");
@@ -64,13 +62,13 @@ public final class FastThreadLocalStateCleaner {
// ignore
LOG.debug("Ignoring exception", e);
clazz = null;
- getThreadLocalMapMethod = null;
+ threadLocalMapField = null;
indexedVariablesField = null;
unsetObject = null;
}
}
FAST_THREAD_LOCAL_CLASS = clazz;
- GET_THREAD_LOCAL_MAP = getThreadLocalMapMethod;
+ THREAD_LOCAL_MAP_FIELD = threadLocalMapField;
INDEXED_VARIABLES_FIELD = indexedVariablesField;
UNSET_OBJECT = unsetObject;
}
@@ -104,7 +102,7 @@ public final class FastThreadLocalStateCleaner {
try {
Object internalThreadLocalMap;
if (FAST_THREAD_LOCAL_CLASS.isInstance(thread)) {
- internalThreadLocalMap = GET_THREAD_LOCAL_MAP.invoke(thread);
+ internalThreadLocalMap = THREAD_LOCAL_MAP_FIELD.get(thread);
} else {
internalThreadLocalMap = ThreadLocalStateCleaner.INSTANCE
.getThreadLocalValue(SLOW_THREAD_LOCAL_MAP, thread);