Skip to content

Commit 2d8da52

Browse files
committed
feature: support Fory serializer and Fory undolog parser
1 parent dc9bf00 commit 2d8da52

File tree

17 files changed

+384
-4
lines changed

17 files changed

+384
-4
lines changed

all/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@
267267
<artifactId>seata-serializer-fury</artifactId>
268268
<version>${project.version}</version>
269269
</dependency>
270+
<dependency>
271+
<groupId>org.apache.seata</groupId>
272+
<artifactId>seata-serializer-fory</artifactId>
273+
<version>${project.version}</version>
274+
</dependency>
270275
<dependency>
271276
<groupId>org.apache.seata</groupId>
272277
<artifactId>seata-serializer-kryo</artifactId>

changes/en-us/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Thanks to these contributors for their code commits. Please report an unintended
135135
- [LegendPei](https://github.com/LegendPei)
136136
- [lokidundun](https://github.com/lokidundun)
137137
- [jsbxyyx](https://github.com/jsbxyyx)
138+
- [diguage](https://github.com/diguage)
138139

139140

140141
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.

changes/zh-cn/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
- [LegendPei](https://github.com/LegendPei)
133133
- [lokidundun](https://github.com/lokidundun)
134134
- [jsbxyyx](https://github.com/jsbxyyx)
135+
- [diguage](https://github.com/diguage)
135136

136137

137138
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

core/src/main/java/org/apache/seata/core/serializer/SerializerServiceLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import static org.apache.seata.core.serializer.SerializerType.FASTJSON2;
36+
import static org.apache.seata.core.serializer.SerializerType.FORY;
3637
import static org.apache.seata.core.serializer.SerializerType.FURY;
3738
import static org.apache.seata.core.serializer.SerializerType.HESSIAN;
3839
import static org.apache.seata.core.serializer.SerializerType.KRYO;
@@ -48,7 +49,7 @@ public final class SerializerServiceLoader {
4849
private static final Configuration CONFIG = ConfigurationFactory.getInstance();
4950

5051
private static final SerializerType[] DEFAULT_SERIALIZER_TYPE =
51-
new SerializerType[] {SEATA, PROTOBUF, KRYO, HESSIAN, FASTJSON2, FURY};
52+
new SerializerType[] {SEATA, PROTOBUF, KRYO, HESSIAN, FASTJSON2, FURY, FORY};
5253

5354
private static final Map<String, Serializer> SERIALIZER_MAP = new HashMap<>();
5455

core/src/main/java/org/apache/seata/core/serializer/SerializerType.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ public enum SerializerType {
6767
/**
6868
* The fury.
6969
*/
70-
FURY((byte) 86);
70+
FURY((byte) 86),
71+
72+
/**
73+
* The fory.
74+
* <p>
75+
* To maintain compatibility with FURY, the FURY code was reused.
76+
*/
77+
FORY((byte) 86);
7178

7279
private final byte code;
7380

dependencies/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
<native-lib-loader.version>2.4.0</native-lib-loader.version>
145145

146146
<!-- for fury -->
147-
<fury.version>0.8.0</fury.version>
147+
<fury.version>0.10.3</fury.version>
148+
<fory.version>0.12.3</fory.version>
148149
</properties>
149150

150151
<dependencyManagement>
@@ -900,6 +901,11 @@
900901
<artifactId>fury-core</artifactId>
901902
<version>${fury.version}</version>
902903
</dependency>
904+
<dependency>
905+
<groupId>org.apache.fory</groupId>
906+
<artifactId>fory-core</artifactId>
907+
<version>${fory.version}</version>
908+
</dependency>
903909
<dependency>
904910
<groupId>commons-io</groupId>
905911
<artifactId>commons-io</artifactId>

rm-datasource/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@
149149
<scope>provided</scope>
150150
<optional>true</optional>
151151
</dependency>
152+
<dependency>
153+
<groupId>org.apache.fory</groupId>
154+
<artifactId>fory-core</artifactId>
155+
<scope>provided</scope>
156+
<optional>true</optional>
157+
</dependency>
152158
<dependency>
153159
<groupId>cn.com.kingbase</groupId>
154160
<artifactId>kingbase8</artifactId>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.rm.datasource.undo.parser;
18+
19+
import org.apache.fory.Fory;
20+
import org.apache.fory.ThreadLocalFory;
21+
import org.apache.fory.ThreadSafeFory;
22+
import org.apache.fory.config.CompatibleMode;
23+
import org.apache.fory.config.Language;
24+
import org.apache.seata.common.executor.Initialize;
25+
import org.apache.seata.common.loader.LoadLevel;
26+
import org.apache.seata.rm.datasource.undo.BranchUndoLog;
27+
import org.apache.seata.rm.datasource.undo.UndoLogParser;
28+
29+
@LoadLevel(name = ForyUndoLogParser.NAME)
30+
public class ForyUndoLogParser implements UndoLogParser, Initialize {
31+
public static final String NAME = "fory";
32+
33+
private static final ThreadSafeFory FORY = new ThreadLocalFory(classLoader -> Fory.builder()
34+
.withLanguage(Language.JAVA)
35+
// In JAVA mode, classes cannot be registered by tag, and the different registration order between the
36+
// server and the client will cause deserialization failure
37+
// In XLANG cross-language mode has problems with Java class serialization, such as enum classes
38+
// [https://github.com/apache/fory/issues/1644].
39+
.requireClassRegistration(false)
40+
// enable reference tracking for shared/circular reference.
41+
.withRefTracking(true)
42+
.withClassLoader(classLoader)
43+
.withCompatibleMode(CompatibleMode.COMPATIBLE)
44+
.build());
45+
46+
@Override
47+
public void init() {}
48+
49+
@Override
50+
public String getName() {
51+
return NAME;
52+
}
53+
54+
@Override
55+
public byte[] getDefaultContent() {
56+
return encode(new BranchUndoLog());
57+
}
58+
59+
@Override
60+
public byte[] encode(BranchUndoLog branchUndoLog) {
61+
return FORY.serializeJavaObject(branchUndoLog);
62+
}
63+
64+
@Override
65+
public BranchUndoLog decode(byte[] bytes) {
66+
return FORY.deserializeJavaObject(bytes, BranchUndoLog.class);
67+
}
68+
}

rm-datasource/src/main/resources/META-INF/services/org.apache.seata.rm.datasource.undo.UndoLogParser

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ org.apache.seata.rm.datasource.undo.parser.JacksonUndoLogParser
1919
org.apache.seata.rm.datasource.undo.parser.ProtostuffUndoLogParser
2020
org.apache.seata.rm.datasource.undo.parser.KryoUndoLogParser
2121
org.apache.seata.rm.datasource.undo.parser.Fastjson2UndoLogParser
22-
org.apache.seata.rm.datasource.undo.parser.FuryUndoLogParser
22+
org.apache.seata.rm.datasource.undo.parser.FuryUndoLogParser
23+
org.apache.seata.rm.datasource.undo.parser.ForyUndoLogParser
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.rm.datasource.undo.parser;
18+
19+
import org.apache.seata.common.loader.EnhancedServiceLoader;
20+
import org.apache.seata.rm.datasource.undo.BaseUndoLogParserTest;
21+
import org.apache.seata.rm.datasource.undo.UndoLogParser;
22+
23+
public class ForyUndoLogParserTest extends BaseUndoLogParserTest {
24+
25+
ForyUndoLogParser parser =
26+
(ForyUndoLogParser) EnhancedServiceLoader.load(UndoLogParser.class, ForyUndoLogParser.NAME);
27+
28+
@Override
29+
public UndoLogParser getParser() {
30+
return parser;
31+
}
32+
33+
@Override
34+
public void testTimestampEncodeAndDecode() {}
35+
}

0 commit comments

Comments
 (0)