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

optimize: kryo 5.4.0 compatibility with jdk17 #5243

Merged
merged 11 commits into from
Jan 29, 2023
3 changes: 3 additions & 0 deletions changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more
- [[#5212](https://github.com/seata/seata/pull/5212)] optimize log message level
- [[#5237](https://github.com/seata/seata/pull/5237)] optimize exception log message print(EnhancedServiceLoader.loadFile#cahtch)
- [[#5243](https://github.com/seata/seata/pull/5243)] optimize kryo 5.4.0 optimize compatibility with jdk17
- [[#5153](https://github.com/seata/seata/pull/5153)] Only AT mode try to get channel with other app
- [[#5177](https://github.com/seata/seata/pull/5177)] If `server.session.enable-branch-async-remove` is true, delete the branch asynchronously and unlock it synchronously.

Expand All @@ -37,8 +38,10 @@ Thanks to these contributors for their code commits. Please report an unintended
- [albumenj](https://github.com/albumenj)
- [PeppaO](https://github.com/PeppaO)
- [yuruixin](https://github.com/yuruixin)
- [CrazyLionLi](https://github.com/JavaLionLi)
- [xingfudeshi](https://github.com/xingfudeshi)
- [Bughue](https://github.com/Bughue)
- [pengten](https://github.com/pengten)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
3 changes: 3 additions & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [[#5208](https://github.com/seata/seata/pull/5208)] 优化多次重复获取Throwable#getCause问题
- [[#5212](https://github.com/seata/seata/pull/5212)] 优化不合理的日志信息级别
- [[#5237](https://github.com/seata/seata/pull/5237)] 优化异常日志打印(EnhancedServiceLoader.loadFile#cahtch)
- [[#5243](https://github.com/seata/seata/pull/5243)] 升级 kryo 5.4.0 优化对jdk17的兼容性
- [[#5153](https://github.com/seata/seata/pull/5153)] 只允许AT去尝试跨RM获取channel
- [[#5177](https://github.com/seata/seata/pull/5177)] 如果 `server.session.enable-branch-async-remove` 为真,异步删除分支,同步解锁。

Expand All @@ -35,8 +36,10 @@
- [albumenj](https://github.com/albumenj)
- [PeppaO](https://github.com/PeppaO)
- [yuruixin](https://github.com/yuruixin)
- [CrazyLionLi](https://github.com/JavaLionLi)
- [xingfudeshi](https://github.com/xingfudeshi)
- [Bughue](https://github.com/Bughue)
- [pengten](https://github.com/pengten)


同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.seata.core.serializer;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Calendar;
Expand Down Expand Up @@ -80,7 +79,6 @@ public class SerializerClassRegistry {
registerClass(Date.class);
registerClass(Calendar.class);
registerClass(ConcurrentHashMap.class);
registerClass(SimpleDateFormat.class);
slievrly marked this conversation as resolved.
Show resolved Hide resolved
registerClass(GregorianCalendar.class);
registerClass(Vector.class);
registerClass(BitSet.class);
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<protobuf.version>3.16.3</protobuf.version>
<grpc.version>1.27.1</grpc.version>
<kryo.version>5.3.0</kryo.version>
<kryo.version>5.4.0</kryo.version>
Copy link
Contributor

Choose a reason for hiding this comment

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

        kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
        kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());

这两段在jdk17使用到KryoSerializerFactory kryo序列化上会报错,有测试过吗?我的另一个pr里改为了
kryo.register(Collections.singletonList("").getClass());
kryo.register(GregorianCalendar.class);
后可兼容jdk17,5.4.0上老的方式,注册了指定的序列化器进去能兼容吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
        kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());

这两段在jdk17使用到KryoSerializerFactory kryo序列化上会报错,有测试过吗?我的另一个pr里改为了 kryo.register(Collections.singletonList("").getClass()); kryo.register(GregorianCalendar.class); 后可兼容jdk17,5.4.0上老的方式,注册了指定的序列化器进去能兼容吗?

我测试一下看看

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
        kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());

这两段在jdk17使用到KryoSerializerFactory kryo序列化上会报错,有测试过吗?我的另一个pr里改为了 kryo.register(Collections.singletonList("").getClass()); kryo.register(GregorianCalendar.class); 后可兼容jdk17,5.4.0上老的方式,注册了指定的序列化器进去能兼容吗?

image

源码中是这样的 单测都是通过的

不过idea报了警告
image

所以我改成如下格式了
image

Copy link
Contributor Author

@JavaLionLi JavaLionLi Jan 10, 2023

Choose a reason for hiding this comment

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

image
这是个什么错呢

Copy link
Contributor

Choose a reason for hiding this comment

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

代码风格问题,看下提示的地方进行code format之类的就像了,往这个日志上面翻翻有具体提示的

Copy link
Contributor

Choose a reason for hiding this comment

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

简单点可以直接不放进去序列化器,让kryo自适应

Copy link
Contributor

Choose a reason for hiding this comment

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

顺便把上面测试jdk17的兼容性代码弄个测试用例放进去吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

顺便把上面测试jdk17的兼容性代码弄个测试用例放进去吧

妥了

Copy link
Contributor

Choose a reason for hiding this comment

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

我看还没提交上来呀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我看还没提交上来呀

刚提交了

<kryo-serializers.version>0.45</kryo-serializers.version>
<hessian.version>4.0.63</hessian.version>
<fst.version>2.57</fst.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
import java.net.URI;
import java.util.Arrays;
import java.util.BitSet;
import java.util.GregorianCalendar;
import java.util.UUID;
import java.util.regex.Pattern;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.serializers.DefaultSerializers;
import com.esotericsoftware.kryo.util.Pool;
import de.javakaffee.kryoserializers.ArraysAsListSerializer;
import de.javakaffee.kryoserializers.BitSetSerializer;
import de.javakaffee.kryoserializers.GregorianCalendarSerializer;
import de.javakaffee.kryoserializers.JdkProxySerializer;
import de.javakaffee.kryoserializers.RegexSerializer;
import de.javakaffee.kryoserializers.URISerializer;
Expand All @@ -52,8 +49,7 @@ protected Kryo create() {
kryo.setRegistrationRequired(false);

// register serializer
kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
kryo.register(Arrays.asList("").getClass());
kryo.register(InvocationHandler.class, new JdkProxySerializer());
kryo.register(BigDecimal.class, new DefaultSerializers.BigDecimalSerializer());
kryo.register(BigInteger.class, new DefaultSerializers.BigIntegerSerializer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.serializer.kryo;

import com.esotericsoftware.kryo.Kryo;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
Expand All @@ -38,6 +39,18 @@ public static void before() {
kryoCodec = new KryoSerializer();
}

/**
* 测试jdk版本对内置对象序列化的兼容性
*/
@Test
public void testSerializerFactory() {
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved
KryoSerializerFactory factory = KryoSerializerFactory.getInstance();
KryoInnerSerializer kryoInnerSerializer = factory.get();
Kryo kryo = kryoInnerSerializer.getKryo();
assertThat(kryo).isNotNull();
factory.returnKryo(kryoInnerSerializer);
}

@Test
public void testBranchCommitRequest() {

Expand Down