fix:主事务内多个嵌套事务,导致影响主事务提交|回滚 (#533)
Co-authored-by: zhangpeng <xinniankuailezp@163.com>
This commit is contained in:
parent
a37ed90c80
commit
b83572ca2d
@ -117,7 +117,7 @@ public class ConnectionFactory {
|
|||||||
Iterator<SavePointHolder> iterator = savePointHolders.iterator();
|
Iterator<SavePointHolder> iterator = savePointHolders.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
SavePointHolder savePointHolder = iterator.next();
|
SavePointHolder savePointHolder = iterator.next();
|
||||||
if (savePointHolder.releaseSavepoint() <= 0) {
|
if (savePointHolder.releaseSavepoint()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ public class ConnectionFactory {
|
|||||||
SavePointHolder savePointHolder = iterator.next();
|
SavePointHolder savePointHolder = iterator.next();
|
||||||
ConnectionProxy connectionProxy = savePointHolder.getConnectionProxy();
|
ConnectionProxy connectionProxy = savePointHolder.getConnectionProxy();
|
||||||
markedConnectionProxy.add(connectionProxy);
|
markedConnectionProxy.add(connectionProxy);
|
||||||
if (savePointHolder.rollbackSavePoint() <= 0) {
|
if (savePointHolder.rollbackSavePoint()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,15 +221,7 @@ public class ConnectionFactory {
|
|||||||
public static boolean hasSavepoint(String xid) {
|
public static boolean hasSavepoint(String xid) {
|
||||||
Map<String, List<SavePointHolder>> savePointMap = SAVEPOINT_CONNECTION_HOLDER.get();
|
Map<String, List<SavePointHolder>> savePointMap = SAVEPOINT_CONNECTION_HOLDER.get();
|
||||||
List<SavePointHolder> savePointHolders = savePointMap.get(xid);
|
List<SavePointHolder> savePointHolders = savePointMap.get(xid);
|
||||||
if (savePointHolders == null || savePointHolders.isEmpty()) {
|
return !CollectionUtils.isEmpty(savePointHolders);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (SavePointHolder savePointHolder : savePointHolders) {
|
|
||||||
if (!CollectionUtils.isEmpty(savePointHolder.getSavePoints())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,6 +16,8 @@
|
|||||||
package com.baomidou.dynamic.datasource.tx;
|
package com.baomidou.dynamic.datasource.tx;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLTransientConnectionException;
|
import java.sql.SQLTransientConnectionException;
|
||||||
import java.sql.Savepoint;
|
import java.sql.Savepoint;
|
||||||
@ -27,6 +29,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author zp
|
* @author zp
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class SavePointHolder {
|
public class SavePointHolder {
|
||||||
/**
|
/**
|
||||||
* savepoint name prefix
|
* savepoint name prefix
|
||||||
@ -72,14 +75,15 @@ public class SavePointHolder {
|
|||||||
* @return savepoint index
|
* @return savepoint index
|
||||||
* @throws SQLException SQLException
|
* @throws SQLException SQLException
|
||||||
*/
|
*/
|
||||||
public int releaseSavepoint() throws SQLException {
|
public boolean releaseSavepoint() throws SQLException {
|
||||||
Savepoint savepoint = savepoints.pollLast();
|
Savepoint savepoint = savepoints.pollLast();
|
||||||
if (savepoint != null) {
|
if (savepoint != null) {
|
||||||
connectionProxy.releaseSavepoint(savepoint);
|
connectionProxy.releaseSavepoint(savepoint);
|
||||||
String savepointName = savepoint.getSavepointName();
|
String savepointName = savepoint.getSavepointName();
|
||||||
return Integer.parseInt(savepointName.substring(SAVEPOINT_NAME_PREFIX.length()));
|
log.info("dynamic-datasource releaseSavepoint [{}]", savepointName);
|
||||||
|
return savepoints.isEmpty();
|
||||||
}
|
}
|
||||||
return -1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,14 +92,15 @@ public class SavePointHolder {
|
|||||||
* @return savepoint index
|
* @return savepoint index
|
||||||
* @throws SQLException SQLException
|
* @throws SQLException SQLException
|
||||||
*/
|
*/
|
||||||
public int rollbackSavePoint() throws SQLException {
|
public boolean rollbackSavePoint() throws SQLException {
|
||||||
Savepoint savepoint = savepoints.pollLast();
|
Savepoint savepoint = savepoints.pollLast();
|
||||||
if (savepoint != null) {
|
if (savepoint != null) {
|
||||||
connectionProxy.rollback(savepoint);
|
connectionProxy.rollback(savepoint);
|
||||||
String savepointName = savepoint.getSavepointName();
|
String savepointName = savepoint.getSavepointName();
|
||||||
return Integer.parseInt(savepointName.substring(SAVEPOINT_NAME_PREFIX.length()));
|
log.info("dynamic-datasource rollbackSavePoint [{}]", savepointName);
|
||||||
|
return savepoints.isEmpty();
|
||||||
}
|
}
|
||||||
return -1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user