Skip to content

Commit

Permalink
bugfix: if the connection is autocommit=false will cause fail to dele…
Browse files Browse the repository at this point in the history
…te (apache#1419)
  • Loading branch information
slievrly committed Aug 8, 2019
1 parent 4ba7f46 commit 1dd65b7
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions rm-datasource/src/main/java/io/seata/rm/RMHandlerAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
package io.seata.rm;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;

import io.seata.core.model.BranchType;
import io.seata.core.model.ResourceManager;
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
Expand All @@ -24,11 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;

/**
* The type Rm handler at.
*
Expand All @@ -42,7 +42,7 @@ public class RMHandlerAT extends AbstractRMHandler {

@Override
public void handle(UndoLogDeleteRequest request) {
DataSourceManager dataSourceManager = (DataSourceManager) getResourceManager();
DataSourceManager dataSourceManager = (DataSourceManager)getResourceManager();
DataSourceProxy dataSourceProxy = dataSourceManager.get(request.getResourceId());
if (dataSourceProxy == null) {
LOGGER.warn("Failed to get dataSourceProxy for delete undolog on " + request.getResourceId());
Expand All @@ -52,12 +52,23 @@ public void handle(UndoLogDeleteRequest request) {
Connection conn = null;
try {
conn = dataSourceProxy.getPlainConnection();
int deleteRows;
int deleteRows = 0;
do {
deleteRows = UndoLogManager.deleteUndoLogByLogCreated(logCreatedSave, dataSourceProxy.getDbType(), LIMIT_ROWS, conn);
try {
deleteRows = UndoLogManager.deleteUndoLogByLogCreated(logCreatedSave, dataSourceProxy.getDbType(),
LIMIT_ROWS, conn);
if (deleteRows > 0 && !conn.getAutoCommit()) {
conn.commit();
}
} catch (SQLException exx) {
if (deleteRows > 0 && !conn.getAutoCommit()) {
conn.rollback();
}
throw exx;
}
} while (deleteRows == LIMIT_ROWS);
} catch (Exception e) {
LOGGER.warn("Failed to get connection for delete undolog ", e);
} catch (Exception e) {
LOGGER.error("Failed to delete expired undo_log,error:{}", e.getMessage(), e);
} finally {
if (conn != null) {
try {
Expand Down

0 comments on commit 1dd65b7

Please sign in to comment.