Skip to content

Commit c944ddc

Browse files
authored
bugfix: fix memory leak in MySQL XA mode (apache#7683)
1 parent 3af4971 commit c944ddc

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

changes/en-us/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Add changes here for all PR submitted to the 2.x branch.
4444
- [[#7624](https://github.com/apache/incubator-seata/pull/7624)] fix the compatibility issue of yml configuration files
4545
- [[#7644](https://github.com/apache/incubator-seata/pull/7644)] fix the compatibility issue of spotless when java 25
4646
- [[#7662](https://github.com/apache/incubator-seata/pull/7662)] ensure visibility of rm and The methods in MockTest are executed in order
47+
- [[#7683](https://github.com/apache/incubator-seata/pull/7683)] Override XABranchXid equals() and hashCode() to fix memory leak in mysql driver
4748

4849

4950
### optimize:

changes/zh-cn/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- [[#7624](https://github.com/apache/incubator-seata/pull/7624)] 修复yml配置文件中对于整数的兼容问题
4545
- [[#7644](https://github.com/apache/incubator-seata/pull/7644)] 修复JAVA25时spotless的兼容性问题
4646
- [[#7662](https://github.com/apache/incubator-seata/pull/7662)] 确保 rm 的可见性,并且 MockTest 中的方法按顺序执行
47+
- [[#7683](https://github.com/apache/incubator-seata/pull/7683)] 重写 XABranchXid的equals和hashCode,解决mysql driver内存泄漏问题
4748

4849

4950
### optimize:

rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/XABranchXid.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.seata.rm.datasource.xa;
1818

1919
import java.io.UnsupportedEncodingException;
20+
import java.util.Objects;
2021

2122
/**
2223
* Xid in XA Protocol. Wrap info of Seata xid and branchId.
@@ -123,4 +124,21 @@ private void decode() {
123124
public String toString() {
124125
return xid + BRANCH_ID_PREFIX + branchId;
125126
}
127+
128+
@Override
129+
public boolean equals(Object o) {
130+
if (this == o) {
131+
return true;
132+
}
133+
if (o == null || getClass() != o.getClass()) {
134+
return false;
135+
}
136+
XABranchXid that = (XABranchXid) o;
137+
return branchId == that.branchId && Objects.equals(xid, that.xid);
138+
}
139+
140+
@Override
141+
public int hashCode() {
142+
return Objects.hash(xid, branchId);
143+
}
126144
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.xa;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
/**
23+
* Tests for XABranchXid
24+
*/
25+
public class XABranchXidTest {
26+
@Test
27+
void testEquals() throws Exception {
28+
XABranchXid xid1 = new XABranchXid("xid1", 1);
29+
XABranchXid xid2 = new XABranchXid("xid1", 1);
30+
XABranchXid xid3 = new XABranchXid("xid2", 2);
31+
XABranchXid xid4 = null;
32+
33+
Assertions.assertEquals(xid1, xid2);
34+
Assertions.assertNotEquals(xid1, xid3);
35+
Assertions.assertNotEquals(xid1, xid4);
36+
Assertions.assertNotEquals(xid1, new Object());
37+
}
38+
39+
@Test
40+
void testHashCode() throws Exception {
41+
XABranchXid xid1 = new XABranchXid("xid1", 1);
42+
XABranchXid xid2 = new XABranchXid("xid1", 1);
43+
XABranchXid xid3 = new XABranchXid("xid2", 2);
44+
45+
Assertions.assertEquals(xid1.hashCode(), xid2.hashCode());
46+
Assertions.assertNotEquals(xid1.hashCode(), xid3.hashCode());
47+
}
48+
}

0 commit comments

Comments
 (0)