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

bugfix: fix getConfig throw ClassCastException when use JDK proxy #5239

Merged
merged 35 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3e2d87e
optimize: get config
wangliang181230 Jan 6, 2023
1c15962
优化。
wangliang181230 Jan 6, 2023
1d3479b
optimize log
wangliang181230 Jan 6, 2023
df2f862
revert
wangliang181230 Jan 6, 2023
fea428c
Merge remote-tracking branch 'upstream/develop' into optimize-getConfig
wangliang181230 Jan 9, 2023
4b52d05
大量调整。
wangliang181230 Jan 9, 2023
e240563
修复配置值。
wangliang181230 Jan 9, 2023
2994da6
优化代码。
wangliang181230 Jan 9, 2023
15e64ab
撤回部分代码。
wangliang181230 Jan 9, 2023
63bb177
移除多余的import
wangliang181230 Jan 9, 2023
941cead
修复另一个BUG。
wangliang181230 Jan 9, 2023
e65d8ec
代码重构。
wangliang181230 Jan 9, 2023
45c39de
修复BUG。
wangliang181230 Jan 9, 2023
f5d67cc
添加日志。
wangliang181230 Jan 10, 2023
8974cab
优化几处代码。
wangliang181230 Jan 10, 2023
52113a9
Merge branch 'develop' into optimize-getConfig
wangliang181230 Jan 10, 2023
fe71844
Merge remote-tracking branch 'upstream/develop' into optimize-getConfig
wangliang181230 Jan 11, 2023
cc1cf71
Merge branch 'develop' into optimize-getConfig
wangliang181230 Jan 16, 2023
ec58bb2
日志小调整。
wangliang181230 Jan 16, 2023
429a29b
再次优化,解决所有ClassCostException的情况。
wangliang181230 Jan 17, 2023
e18d1f2
Merge branch 'develop' into optimize-getConfig
wangliang181230 Jan 28, 2023
e83e6dc
调用方法有误,调整掉。
wangliang181230 Jan 28, 2023
7b5a27d
小调整。
wangliang181230 Jan 28, 2023
887b368
小调整。
wangliang181230 Jan 28, 2023
9ec1baf
类型相同时,不进行类型转换。
wangliang181230 Jan 29, 2023
be334ec
Merge branch 'develop' into optimize-getConfig
wangliang181230 Jan 29, 2023
b61ffbd
fix style
wangliang181230 Jan 29, 2023
528c927
优化单元测试。
wangliang181230 Jan 29, 2023
9ed410c
注释中,添加获取配置的序号。
wangliang181230 Jan 29, 2023
fc60a70
修复一个线程安全问题。
wangliang181230 Jan 29, 2023
4c4d58c
modify develop.md
wangliang181230 Jan 29, 2023
fa1fa81
optimize log
wangliang181230 Jan 29, 2023
66801d6
optimize log
wangliang181230 Jan 29, 2023
a4661a9
Merge branch 'develop' into optimize-getConfig
wangliang181230 Jan 29, 2023
58c0d28
optimize log
wangliang181230 Jan 29, 2023
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
5 changes: 2 additions & 3 deletions changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5224](https://github.com/seata/seata/pull/5224)] fix oracle initialize script index_name is duplicate
- [[#5233](https://github.com/seata/seata/pull/5233)] fix the inconsistent configuration item names related to LoadBalance
- [[#5245](https://github.com/seata/seata/pull/5245)] fix the incomplete dependency of distribution module


- [[#5239](https://github.com/seata/seata/pull/5239)] fix `getConfig` throw `ClassCastException` when use jdk proxy, and optimize some log

### optimize:
- [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more
Expand All @@ -26,7 +25,6 @@ Add changes here for all PR submitted to the develop branch.
### security:
- [[#5172](https://github.com/seata/seata/pull/5172)] fix some security vulnerabilities


### test:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] add test for xxx

Expand All @@ -42,6 +40,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [xingfudeshi](https://github.com/xingfudeshi)
- [Bughue](https://github.com/Bughue)
- [pengten](https://github.com/pengten)
- [wangliang181230](https://github.com/wangliang181230)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
3 changes: 2 additions & 1 deletion changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- [[#5224](https://github.com/seata/seata/pull/5224)] 修复 oracle初始化脚本索引名重复的问题
- [[#5233](https://github.com/seata/seata/pull/5233)] 修复LoadBalance相关配置不一致的问题
- [[#5245](https://github.com/seata/seata/pull/5245)] 修复不完整的distribution模块依赖

- [[#5239](https://github.com/seata/seata/pull/5239)] 修复当使用JDK代理时,`getConfig` 方法获取部分配置时抛出 `ClassCastException` 异常的问题

### optimize:
- [[#5208](https://github.com/seata/seata/pull/5208)] 优化多次重复获取Throwable#getCause问题
Expand Down Expand Up @@ -40,6 +40,7 @@
- [xingfudeshi](https://github.com/xingfudeshi)
- [Bughue](https://github.com/Bughue)
- [pengten](https://github.com/pengten)
- [wangliang181230](https://github.com/wangliang181230)


同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
11 changes: 8 additions & 3 deletions common/src/main/java/io/seata/common/DefaultValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public interface DefaultValues {
int DEFAULT_SERVICE_SESSION_RELOAD_READ_SIZE = 100;

/**
*the constant DEFAULT_PROMETHEUS_PORT
* the constant DEFAULT_PROMETHEUS_PORT
*/
int DEFAULT_PROMETHEUS_PORT = 9898;

Expand All @@ -248,12 +248,12 @@ public interface DefaultValues {
/**
* the const DEFAULT_MAX_COMMIT_RETRY_TIMEOUT
*/
long DEFAULT_MAX_COMMIT_RETRY_TIMEOUT = 100;
long DEFAULT_MAX_COMMIT_RETRY_TIMEOUT = -1L;

/**
* the const DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT
*/
long DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT = 100;
long DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT = -1L;

/**
* the const DEFAULT_ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE
Expand Down Expand Up @@ -281,4 +281,9 @@ public interface DefaultValues {
int DEFAULT_REDIS_MIN_IDLE = 10;

int DEFAULT_QUERY_LIMIT = 1000;

/**
* Default druid location in classpath
*/
String DRUID_LOCATION = "lib/sqlparser/druid.jar";
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,12 @@ private S loadExtension(ClassLoader loader, Class<?>[] argTypes,
loadAllExtensionClass(loader);
ExtensionDefinition<S> defaultExtensionDefinition = getDefaultExtensionDefinition();
return getExtensionInstance(defaultExtensionDefinition, loader, argTypes, args);
} catch (EnhancedServiceNotFoundException e) {
throw e;
} catch (Throwable e) {
if (e instanceof EnhancedServiceNotFoundException) {
throw (EnhancedServiceNotFoundException)e;
} else {
throw new EnhancedServiceNotFoundException(
"not found service provider for : " + type.getName() + " caused by " + ExceptionUtils
.getFullStackTrace(e));
}
throw new EnhancedServiceNotFoundException(
"not found service provider for : " + type.getName()
+ " caused by " + ExceptionUtils.getFullStackTrace(e));
}
}

Expand Down Expand Up @@ -519,7 +517,10 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition<S
urls = ClassLoader.getSystemResources(fileName);
}
if (urls != null) {
boolean hasServiceFile = false;
boolean hasClasses = false;
while (urls.hasMoreElements()) {
hasServiceFile = true;
java.net.URL url = urls.nextElement();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), Constants.DEFAULT_CHARSET))) {
String line;
Expand All @@ -530,6 +531,7 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition<S
}
line = line.trim();
if (line.length() > 0) {
hasClasses = true;
try {
ExtensionDefinition<S> extensionDefinition = getUnloadedExtensionDefinition(line, loader);
if (extensionDefinition == null) {
Expand All @@ -540,17 +542,29 @@ private void loadFile(String dir, ClassLoader loader, List<ExtensionDefinition<S
}
extensions.add(extensionDefinition);
} catch (LinkageError | ClassNotFoundException e) {
LOGGER.warn("Load [{}] class fail. ", line, e);
LOGGER.warn("Load [{}] class fail.", line, e);
} catch (ClassCastException e) {
LOGGER.error("Load [{}] class fail, please make sure the extension" +
" config in {} implements {}.", line, fileName, type.getName());
}
}
}
} catch (Throwable e) {
LOGGER.warn("load clazz instance error: ", e);
LOGGER.warn("load class instance error:", e);
}
}

if (LOGGER.isDebugEnabled()) {
if (!hasServiceFile) {
LOGGER.warn("Load [{}] class fail: no service files found in '{}'.", type.getName(), dir);
} else if (!hasClasses) {
LOGGER.warn("Load [{}] class fail: the service files in '{}' is all empty.", type.getName(), dir);
}
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Load [{}] class fail: no urls found in '{}'.", type.getName(), dir);
}
}
}

Expand Down
40 changes: 40 additions & 0 deletions common/src/main/java/io/seata/common/util/ReflectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,46 @@ public static Class<?> getClassByName(String className) throws ClassNotFoundExce
return Class.forName(className, true, Thread.currentThread().getContextClassLoader());
}

/**
* Get the wrapped class
*
* @param clazz the class
* @return the wrapped class
*/
public static Class<?> getWrappedClass(Class<?> clazz) {
if (clazz.isPrimitive()) {
if (clazz.equals(byte.class)) {
return Byte.class;
}
if (clazz.equals(boolean.class)) {
return Boolean.class;
}
if (clazz.equals(char.class)) {
return Character.class;
}
if (clazz.equals(short.class)) {
return Short.class;
}
if (clazz.equals(int.class)) {
return Integer.class;
}
if (clazz.equals(long.class)) {
return Long.class;
}
if (clazz.equals(float.class)) {
return Float.class;
}
if (clazz.equals(double.class)) {
return Double.class;
}
if (clazz.equals(void.class)) {
return Void.class;
}
}

return clazz;
}

//endregion


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ public Configuration proxy(Configuration originalConfiguration) throws Exception
return new ByteBuddy().subclass(Configuration.class).method(ElementMatchers.any())
.intercept(InvocationHandlerAdapter.of((proxy, method, args) -> {
String methodName = method.getName();
if (methodName.startsWith(METHOD_PREFIX) && !method.getName().equalsIgnoreCase(METHOD_LATEST_CONFIG)) {
if (methodName.startsWith(METHOD_PREFIX) && !methodName.equalsIgnoreCase(METHOD_LATEST_CONFIG)) {
String rawDataId = (String)args[0];
ObjectWrapper wrapper = CONFIG_CACHE.get(rawDataId);
ObjectWrapper.ConfigType type =
ObjectWrapper.getTypeByName(method.getName().substring(METHOD_PREFIX.length()));
ObjectWrapper.getTypeByName(methodName.substring(METHOD_PREFIX.length()));
Object defaultValue = null;
if (args.length > 1
&& method.getParameterTypes()[1].getSimpleName().equalsIgnoreCase(type.name())) {
&& method.getParameterTypes()[1].getSimpleName().equalsIgnoreCase(type.name())) {
defaultValue = args[1];
}
if (null == wrapper
|| (null != defaultValue && !Objects.equals(defaultValue, wrapper.lastDefaultValue))) {
|| (null != defaultValue && !Objects.equals(defaultValue, wrapper.lastDefaultValue))) {
Object result = method.invoke(originalConfiguration, args);
// The wrapper.data only exists in the cache when it is not null.
if (result != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ private static void load() {
LOGGER.info("load Configuration from :{}", extConfiguration == null ?
configuration.getClass().getSimpleName() : "Spring Configuration");
}
} catch (EnhancedServiceNotFoundException ignore) {

} catch (EnhancedServiceNotFoundException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("failed to load extConfiguration: {}", e.getMessage(), e);
}
} catch (Exception e) {
LOGGER.error("failed to load extConfiguration:{}", e.getMessage(), e);
LOGGER.error("failed to load extConfiguration: {}", e.getMessage(), e);
}
CURRENT_FILE_INSTANCE = extConfiguration == null ? configuration : extConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ public abstract class AbstractTableMetaCache implements TableMetaCache {

private static final long EXPIRE_TIME = 900 * 1000;

private static final Cache<String, TableMeta> TABLE_META_CACHE = Caffeine.newBuilder().maximumSize(CACHE_SIZE)
.expireAfterWrite(EXPIRE_TIME, TimeUnit.MILLISECONDS).softValues().build();
private static final Cache<String, TableMeta> TABLE_META_CACHE;

static {
try {
TABLE_META_CACHE = Caffeine.newBuilder().maximumSize(CACHE_SIZE)
.expireAfterWrite(EXPIRE_TIME, TimeUnit.MILLISECONDS).softValues().build();
} catch (Throwable t) {
LOGGER.warn("Build the `TABLE_META_CACHE` failed:", t);
throw t;
}
}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static String buildResourceId(String jdbcUrl) {
}

public static Driver loadDriver(String driverClassName) throws SQLException {
Class clazz = null;
Class<?> clazz = null;
try {
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
if (contextLoader != null) {
Expand All @@ -124,9 +124,7 @@ public static Driver loadDriver(String driverClassName) throws SQLException {

try {
return (Driver)clazz.newInstance();
} catch (IllegalAccessException e) {
throw new SQLException(e.getMessage(), e);
} catch (InstantiationException e) {
} catch (IllegalAccessException | InstantiationException e) {
throw new SQLException(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class ShutdownProperties {
/**
* when destroy server, wait seconds
*/
private long wait = DEFAULT_SHUTDOWN_TIMEOUT_SEC;
private int wait = DEFAULT_SHUTDOWN_TIMEOUT_SEC;

public long getWait() {
public int getWait() {
return wait;
}

public ShutdownProperties setWait(long wait) {
public ShutdownProperties setWait(int wait) {
this.wait = wait;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
@ConfigurationProperties(prefix = CONFIG_ZK_PREFIX)
public class ConfigZooKeeperProperties {
private String serverAddr;
private long sessionTimeout = 6000L;
private long connectTimeout = 2000L;
private int sessionTimeout = 6000;
private int connectTimeout = 2000;
private String username;
private String password;
private String nodePath = "/seata/seata.properties";
Expand All @@ -46,16 +46,16 @@ public long getSessionTimeout() {
return sessionTimeout;
}

public ConfigZooKeeperProperties setSessionTimeout(long sessionTimeout) {
public ConfigZooKeeperProperties setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
return this;
}

public long getConnectTimeout() {
public int getConnectTimeout() {
return connectTimeout;
}

public ConfigZooKeeperProperties setConnectTimeout(long connectTimeout) {
public ConfigZooKeeperProperties setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
public class RegistryZooKeeperProperties {
private String cluster = "default";
private String serverAddr = "127.0.0.1:2181";
private long sessionTimeout = 6000L;
private long connectTimeout = 2000L;
private int sessionTimeout = 6000;
private int connectTimeout = 2000;
private String username;
private String password;

Expand All @@ -51,20 +51,20 @@ public RegistryZooKeeperProperties setServerAddr(String serverAddr) {
return this;
}

public long getSessionTimeout() {
public int getSessionTimeout() {
return sessionTimeout;
}

public RegistryZooKeeperProperties setSessionTimeout(long sessionTimeout) {
public RegistryZooKeeperProperties setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
return this;
}

public long getConnectTimeout() {
public int getConnectTimeout() {
return connectTimeout;
}

public RegistryZooKeeperProperties setConnectTimeout(long connectTimeout) {
public RegistryZooKeeperProperties setConnectTimeout(int connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}
Expand Down
Loading