diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md index 72498a29203..b81fdddf912 100644 --- a/changes/en-us/develop.md +++ b/changes/en-us/develop.md @@ -7,6 +7,7 @@ Add changes here for all PR submitted to the develop branch. - [[#4863](https://github.com/seata/seata/pull/4863)] support oracle and postgresql multi primary key - [[#4649](https://github.com/seata/seata/pull/4649)] seata-server support multiple registry - [[#4479](https://github.com/seata/seata/pull/4479)] TCC mode supports tcc annotation marked on both interface and implementation class +- [[#4468](https://github.com/seata/seata/pull/4968)] support kryo 5.3.0 ### bugfix: @@ -65,5 +66,6 @@ Thanks to these contributors for their code commits. Please report an unintended - [doubleDimple](https://github.com/doubleDimple) - [jsbxyyx](https://github.com/jsbxyyx) - [tuwenlin](https://github.com/tuwenlin) +- [CrazyLionLi](https://github.com/JavaLionLi) Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. diff --git a/changes/zh-cn/develop.md b/changes/zh-cn/develop.md index df1485a24d3..c3f79da2297 100644 --- a/changes/zh-cn/develop.md +++ b/changes/zh-cn/develop.md @@ -7,6 +7,7 @@ - [[#4863](https://github.com/seata/seata/pull/4863)] support oracle and postgresql multi primary key - [[#4649](https://github.com/seata/seata/pull/4649)] seata-server支持多注册中心 - [[#4479](https://github.com/seata/seata/pull/4479)] TCC注解支持添加在实现类及其方法上也生效 +- [[#4468](https://github.com/seata/seata/pull/4968)] 支持kryo 5.3.0 ### bugfix: @@ -65,5 +66,6 @@ - [doubleDimple](https://github.com/doubleDimple) - [jsbxyyx](https://github.com/jsbxyyx) - [tuwenlin](https://github.com/tuwenlin) +- [CrazyLionLi](https://github.com/JavaLionLi) 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。 diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 83f2f47da22..961ead8e3b8 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -68,8 +68,8 @@ 3.7.1 1.17.1 - 4.0.2 - 0.42 + 5.3.0 + 0.45 4.0.63 2.57 2.4.4 diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/KryoSerializerFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/KryoSerializerFactory.java index 6b566928a62..9dc880a593c 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/KryoSerializerFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/KryoSerializerFactory.java @@ -28,8 +28,7 @@ import com.esotericsoftware.kryo.Serializer; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; -import com.esotericsoftware.kryo.pool.KryoFactory; -import com.esotericsoftware.kryo.pool.KryoPool; +import com.esotericsoftware.kryo.util.Pool; import de.javakaffee.kryoserializers.JdkProxySerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,13 +36,42 @@ /** * @author jsbxyyx */ -public class KryoSerializerFactory implements KryoFactory { +public class KryoSerializerFactory { private static final Logger LOGGER = LoggerFactory.getLogger(KryoSerializerFactory.class); private static final KryoSerializerFactory FACTORY = new KryoSerializerFactory(); - private KryoPool pool = new KryoPool.Builder(this).softReferences().build(); + private Pool pool = new Pool(true, true) { + + @Override + public Kryo create() { + Kryo kryo = new Kryo(); + kryo.setRegistrationRequired(false); + + for (Map.Entry entry : TYPE_MAP.entrySet()) { + kryo.register(entry.getKey(), entry.getValue()); + } + + // support clob and blob + kryo.register(SerialBlob.class, new BlobSerializer()); + kryo.register(SerialClob.class, new ClobSerializer()); + + // register sql type + kryo.register(Timestamp.class, new TimestampSerializer()); + kryo.register(InvocationHandler.class, new JdkProxySerializer()); + // register commonly class + UndoLogSerializerClassRegistry.getRegisteredClasses().forEach((clazz, ser) -> { + if (ser == null) { + kryo.register(clazz); + } else { + kryo.register(clazz, (Serializer)ser); + } + }); + return kryo; + } + + }; private static final Map TYPE_MAP = new ConcurrentHashMap<>(); @@ -54,14 +82,14 @@ public static KryoSerializerFactory getInstance() { } public KryoSerializer get() { - return new KryoSerializer(pool.borrow()); + return new KryoSerializer(pool.obtain()); } public void returnKryo(KryoSerializer kryoSerializer) { if (kryoSerializer == null) { throw new IllegalArgumentException("kryoSerializer is null"); } - pool.release(kryoSerializer.getKryo()); + pool.free(kryoSerializer.getKryo()); } public void registerSerializer(Class type, Serializer ser) { @@ -70,33 +98,6 @@ public void registerSerializer(Class type, Serializer ser) { } } - @Override - public Kryo create() { - Kryo kryo = new Kryo(); - kryo.setRegistrationRequired(false); - - for (Map.Entry entry : TYPE_MAP.entrySet()) { - kryo.register(entry.getKey(), entry.getValue()); - } - - // support clob and blob - kryo.register(SerialBlob.class, new BlobSerializer()); - kryo.register(SerialClob.class, new ClobSerializer()); - - // register sql type - kryo.register(Timestamp.class, new TimestampSerializer()); - kryo.register(InvocationHandler.class, new JdkProxySerializer()); - // register commonly class - UndoLogSerializerClassRegistry.getRegisteredClasses().forEach((clazz, ser) -> { - if (ser == null) { - kryo.register(clazz); - } else { - kryo.register(clazz, (Serializer)ser); - } - }); - return kryo; - } - private static class BlobSerializer extends Serializer { @Override @@ -111,7 +112,7 @@ public void write(Kryo kryo, Output output, Blob object) { } @Override - public Blob read(Kryo kryo, Input input, Class type) { + public Blob read(Kryo kryo, Input input, Class type) { int length = input.readInt(true); byte[] bytes = input.readBytes(length); try { @@ -137,7 +138,7 @@ public void write(Kryo kryo, Output output, Clob object) { } @Override - public Clob read(Kryo kryo, Input input, Class type) { + public Clob read(Kryo kryo, Input input, Class type) { try { String s = input.readString(); return new SerialClob(s.toCharArray()); @@ -157,7 +158,7 @@ public void write(Kryo kryo, Output output, Timestamp object) { } @Override - public Timestamp read(Kryo kryo, Input input, Class type) { + public Timestamp read(Kryo kryo, Input input, Class type) { Timestamp timestamp = new Timestamp(input.readLong(true)); timestamp.setNanos(input.readInt(true)); return timestamp; diff --git a/serializer/seata-serializer-kryo/src/main/java/io/seata/serializer/kryo/KryoSerializerFactory.java b/serializer/seata-serializer-kryo/src/main/java/io/seata/serializer/kryo/KryoSerializerFactory.java index 73daf3a58f7..85b6af99427 100644 --- a/serializer/seata-serializer-kryo/src/main/java/io/seata/serializer/kryo/KryoSerializerFactory.java +++ b/serializer/seata-serializer-kryo/src/main/java/io/seata/serializer/kryo/KryoSerializerFactory.java @@ -25,9 +25,8 @@ import java.util.UUID; import java.util.regex.Pattern; import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.pool.KryoFactory; -import com.esotericsoftware.kryo.pool.KryoPool; 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; @@ -40,11 +39,33 @@ /** * @author jsbxyyx */ -public class KryoSerializerFactory implements KryoFactory { +public class KryoSerializerFactory { private static final KryoSerializerFactory FACTORY = new KryoSerializerFactory(); - private KryoPool pool = new KryoPool.Builder(this).softReferences().build(); + private Pool pool = new Pool(true, true) { + + @Override + protected Kryo create() { + Kryo kryo = new Kryo(); + kryo.setRegistrationRequired(false); + + // register serializer + kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); + kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer()); + kryo.register(InvocationHandler.class, new JdkProxySerializer()); + kryo.register(BigDecimal.class, new DefaultSerializers.BigDecimalSerializer()); + kryo.register(BigInteger.class, new DefaultSerializers.BigIntegerSerializer()); + kryo.register(Pattern.class, new RegexSerializer()); + kryo.register(BitSet.class, new BitSetSerializer()); + kryo.register(URI.class, new URISerializer()); + kryo.register(UUID.class, new UUIDSerializer()); + + // register commonly class + SerializerClassRegistry.getRegisteredClasses().keySet().forEach(kryo::register); + return kryo; + } + }; private KryoSerializerFactory() {} @@ -53,35 +74,14 @@ public static KryoSerializerFactory getInstance() { } public KryoInnerSerializer get() { - return new KryoInnerSerializer(pool.borrow()); + return new KryoInnerSerializer(pool.obtain()); } public void returnKryo(KryoInnerSerializer kryoSerializer) { if (kryoSerializer == null) { throw new IllegalArgumentException("kryoSerializer is null"); } - pool.release(kryoSerializer.getKryo()); - } - - @Override - public Kryo create() { - Kryo kryo = new Kryo(); - kryo.setRegistrationRequired(false); - - // register serializer - kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer()); - kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer()); - kryo.register(InvocationHandler.class, new JdkProxySerializer()); - kryo.register(BigDecimal.class, new DefaultSerializers.BigDecimalSerializer()); - kryo.register(BigInteger.class, new DefaultSerializers.BigIntegerSerializer()); - kryo.register(Pattern.class, new RegexSerializer()); - kryo.register(BitSet.class, new BitSetSerializer()); - kryo.register(URI.class, new URISerializer()); - kryo.register(UUID.class, new UUIDSerializer()); - - // register commonly class - SerializerClassRegistry.getRegisteredClasses().keySet().forEach(kryo::register); - return kryo; + pool.free(kryoSerializer.getKryo()); } }