Skip to content

Commit

Permalink
bugfix: fix the problem of building undoLog exception when update joi…
Browse files Browse the repository at this point in the history
…n does not update data (#6994)
  • Loading branch information
GoodBoyCoder authored Nov 11, 2024
1 parent 4fae062 commit 7930f31
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6948](https://github.com/apache/incubator-seata/pull/6948)] Fix the CI build issue on the ARM64 platform
- [[#6947](https://github.com/apache/incubator-seata/pull/6947)] fix npe for nacos registry when look up address
- [[#6984](https://github.com/apache/incubator-seata/pull/6984)] support building docker image on openjdk23
- [[#6994](https://github.com/apache/incubator-seata/pull/6994)] fix the problem of building undoLog exception when update join does not update data

### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] remove the branch registration operation of the XA read-only transaction
Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- [[#6948](https://github.com/apache/incubator-seata/pull/6948)] 修复在ARM64平台下CI构建出错的问题
- [[#6947](https://github.com/apache/incubator-seata/pull/6947)] 修复nacos注册中心查询可用地址时的空指针问题
- [[#6984](https://github.com/apache/incubator-seata/pull/6984)] 修复 openjdk23 版本下无法构建 docker 镜像的问题
- [[#6994](https://github.com/apache/incubator-seata/pull/6994)] 修复updateJoin语句未更新到数据时prepareUndoLog异常


### optimize:
- [[#6826](https://github.com/apache/incubator-seata/pull/6826)] 移除只读XA事务的分支注册操作
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ protected TableRecords beforeImage() throws SQLException {
}
String selectSQL = buildBeforeImageSQL(joinTable, tableItems[i], suffixCommonCondition, itemTableUpdateColumns);
TableRecords tableRecords = buildTableRecords(getTableMeta(tableItems[i]), selectSQL, paramAppenderList);
beforeImagesMap.put(tableItems[i], tableRecords);
if (CollectionUtils.isNotEmpty(tableRecords.getRows())) {
//when building the after image, the table with empty records in before image is skipped
//link issue https://github.com/apache/incubator-seata/issues/6976
beforeImagesMap.put(tableItems[i], tableRecords);
}
}
return null;
}
Expand Down Expand Up @@ -231,6 +235,9 @@ private List<String> getItemUpdateColumns(TableMeta itemTableMeta, List<String>

@Override
protected void prepareUndoLog(TableRecords beforeImage, TableRecords afterImage) throws SQLException {
if (CollectionUtils.isEmpty(beforeImagesMap) && CollectionUtils.isEmpty(afterImagesMap)) {
return;
}
if (CollectionUtils.isEmpty(beforeImagesMap) || CollectionUtils.isEmpty(afterImagesMap)) {
throw new IllegalStateException("images can not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ public void testUpdateJoinUndoLog() throws SQLException {
Assertions.assertDoesNotThrow(()->mySQLUpdateJoinExecutor.prepareUndoLog(beforeImage, afterImage));
}

@Test
public void testEmptyUpdateJoinUndoLog() throws SQLException {
List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
Object[][] columnMetas = new Object[][]{
new Object[]{"", "", "t1", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES"},
new Object[]{"", "", "t1", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO"},
new Object[]{"", "", "t2", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES"},
new Object[]{"", "", "t2", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO"},
new Object[]{"", "", "t1 inner join t2 on t1.id = t2.id", "id", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO"},
new Object[]{"", "", "t1 inner join t2 on t1.id = t2.id", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO"},
};
Object[][] indexMetas = new Object[][]{
new Object[]{"PRIMARY", "id", false, "", 3, 1, "A", 34},
};
Object[][] beforeReturnValue = new Object[][]{};
StatementProxy beforeMockStatementProxy = mockStatementProxy(returnValueColumnLabels, beforeReturnValue, columnMetas, indexMetas);
String sql = "update t1 inner join t2 on t1.id = t2.id set t1.name = 'WILL',t2.name = 'WILL'";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
MySQLUpdateRecognizer recognizer = new MySQLUpdateRecognizer(sql, asts.get(0));
UpdateExecutor mySQLUpdateJoinExecutor = new MySQLUpdateJoinExecutor(beforeMockStatementProxy, (statement, args) -> {
return null;
}, recognizer);
TableRecords beforeImage = mySQLUpdateJoinExecutor.beforeImage();
Object[][] afterReturnValue = new Object[][]{};
StatementProxy afterMockStatementProxy = mockStatementProxy(returnValueColumnLabels, afterReturnValue, columnMetas, indexMetas);
mySQLUpdateJoinExecutor.statementProxy = afterMockStatementProxy;
TableRecords afterImage = mySQLUpdateJoinExecutor.afterImage(beforeImage);
Assertions.assertDoesNotThrow(()->mySQLUpdateJoinExecutor.prepareUndoLog(beforeImage, afterImage));
}

private StatementProxy mockStatementProxy(List<String> returnValueColumnLabels, Object[][] returnValue, Object[][] columnMetas, Object[][] indexMetas) {
MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
DruidDataSource dataSource = new DruidDataSource();
Expand Down

0 comments on commit 7930f31

Please sign in to comment.