Skip to content

Commit

Permalink
Merge pull request #217 from wenki96/hotfix/5.4.19-20240919_fix
Browse files Browse the repository at this point in the history
5.4.19-20240919 fix
  • Loading branch information
vettalwu authored Oct 11, 2024
2 parents 6309889 + f130e25 commit ca00d7f
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,23 @@ protected List<String> getSortedColumns(boolean isFront, TableMeta tableMeta, Fo
return sortedColumns;
}

protected List<String> getUpdateSortedColumns(TableMeta tableMeta, ForeignKeyData data,
List<String> updateColumns) {
Map<String, String> columnMap =
IntStream.range(0, data.columns.size()).collect(TreeMaps::caseInsensitiveMap,
(m, i) -> m.put(data.columns.get(i), data.refColumns.get(i)), Map::putAll);

List<String> sortedColumns = new ArrayList<>();
tableMeta.getAllColumns().forEach(c -> {
if (data.columns.stream().anyMatch(c.getName()::equalsIgnoreCase) &&
updateColumns.stream().anyMatch(c.getName()::equalsIgnoreCase)) {
sortedColumns.add(columnMap.get(c.getName()));
}
});

return sortedColumns;
}

protected Map<String, Map<String, List<Pair<Integer, List<Object>>>>> getShardResults(ForeignKeyData data,
String schemaName,
String tableName,
Expand All @@ -1104,12 +1121,17 @@ protected Map<String, Map<String, List<Pair<Integer, List<Object>>>>> getShardRe
List<List<Object>> values,
PhysicalPlanBuilder builder,
List<String> selectKeys,
List<String> updateColumns,
boolean isFront,
boolean isInsert) {
boolean isInsert,
boolean isUpdateCheck) {
List<String> columns = isInsert ? selectKeys : isFront ? data.refColumns : data.columns;

List<String> sortedColumns;
if (!isInsert) {
if (isUpdateCheck) {
sortedColumns = getUpdateSortedColumns(tableMeta, data, updateColumns);
columns = sortedColumns;
} else if (!isInsert) {
sortedColumns =
isFront ? getSortedColumns(true, tableMeta, data) : getSortedColumns(false, parentTableMeta, data);
} else {
Expand Down Expand Up @@ -1216,9 +1238,10 @@ protected void beforeUpdateFkCheck(TableModify tableModify, String schemaName, S
Map<String, Map<String, List<Pair<Integer, List<Object>>>>> shardResults =
getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta, updateValueList,
builder, null,
true, false);
tableModify.getUpdateColumnList(), true, false, true);

List<String> sortedColumns = getSortedColumns(true, tableMeta, data.getValue());
List<String> sortedColumns =
getUpdateSortedColumns(tableMeta, data.getValue(), tableModify.getUpdateColumnList());

ExecutionContext selectEc = executionContext.copy();
selectEc.setParams(new Parameters(selectEc.getParams().getCurrentParameter(), false));
Expand Down Expand Up @@ -1315,7 +1338,7 @@ protected void beforeUpdateFkCascade(TableModify tableModify, String schemaName,
getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta,
shardConditionValueList, builder,
null,
false, false);
null, false, false, false);

columnMap = IntStream.range(0, data.getValue().columns.size()).collect(TreeMaps::caseInsensitiveMap,
(m, i) -> m.put(data.getValue().refColumns.get(i), data.getValue().columns.get(i)),
Expand Down Expand Up @@ -1454,7 +1477,7 @@ protected void beforeDeleteFkCascade(TableModify logicalModify, String schemaNam
executionContext, false) :
getShardResults(data.getValue(), schemaName, tableName, refTableMeta, tableMeta, conditionValueList,
builder, null,
false, false);
null, false, false, false);

List<String> sortedColumns = getSortedColumns(false, tableMeta, data.getValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ protected void beforeInsertFkCheck(LogicalInsert logicalInsert, String targetTab
Map<String, Map<String, List<Pair<Integer, List<Object>>>>> shardResults =
getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta,
conditionValueList,
builder, sortedColumns, true, true);
builder, sortedColumns, null, true, true, false);

conditionValueList = conditionValueList.stream().distinct().collect(Collectors.toList());

Expand Down Expand Up @@ -519,7 +519,7 @@ protected List<Map<Integer, ParameterContext>> beforeInsertFkCheckIgnore(Logical
Map<String, Map<String, List<Pair<Integer, List<Object>>>>> shardResults =
getShardResults(data.getValue(), schemaName, tableName, tableMeta, parentTableMeta,
conditionValueList,
builder, sortedColumns, true, true);
builder, sortedColumns, null, true, true, false);

List<List<Object>> selectValues = getSelectValues(selectEc, schemaName,
parentTableMeta, conditionValueList, logicalInsert, memoryAllocator, builder, shardResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public static List<List<Object>> getUpdateValueList(ForeignKeyData data, List<St
refColIndex.add(updateColumns.indexOf(columnName));
}
}
;

for (List<Object> row : values) {
List<Object> updateValue = new ArrayList<>();
for (Integer colIndex : refColIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ private boolean checkDdl(String schemaName, String ddlSql, CdcDDLContext cdcDDLC
return false;
}

// 针对mysql系统库,过滤
if (StringUtils.equalsIgnoreCase(schemaName, "mysql") && StringUtils.equalsIgnoreCase("DROP_DATABASE",
sqlKind.toString())) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ public void testFkUpdateCascade() throws SQLException {
JdbcUtil.executeQuerySuccess(tddlConnection, String.format("select * from %s", tableName3));
Assert.assertTrue(rs.next());
assertEquals(rs.getLong(3), 9);

// update one column on child table
sql = String.format("update %s set c = 9 where b = 7", tableName3);
JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql);

break;
case "RESTRICT":
case "NO ACTION":
Expand Down Expand Up @@ -863,6 +868,11 @@ public void testFkUpdateCascade() throws SQLException {
// update one of referenced columns
sql = String.format("update %s set b = 9 where c = 3", tableName1);
JdbcUtil.executeUpdateFailed(tddlConnection, hint + sql, "");

// update one column on child table
sql = String.format("update %s set b = 2 where c = 1", tableName3);
JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql);

break;

case "SET NULL":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,11 @@ public void testFkUpdateCascade() throws SQLException {
JdbcUtil.executeQuerySuccess(tddlConnection, String.format("select * from %s", tableName3));
Assert.assertTrue(rs.next());
assertEquals(rs.getLong(3), 9);

// update one column on child table
sql = String.format("update %s set c = 9 where b = 7", tableName3);
JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql);

break;
case "RESTRICT":
case "NO ACTION":
Expand Down Expand Up @@ -851,6 +856,11 @@ public void testFkUpdateCascade() throws SQLException {
// update one of referenced columns
sql = String.format("update %s set b = 9 where c = 3", tableName1);
JdbcUtil.executeUpdateFailed(tddlConnection, hint + sql, "");

// update one column on child table
sql = String.format("update %s set b = 2 where c = 1", tableName3);
JdbcUtil.executeUpdateSuccess(tddlConnection, hint + sql);

break;

case "SET NULL":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.polardbx.gms.util.JdbcUtil;
import com.alibaba.polardbx.gms.util.PasswdUtil;
import com.alibaba.polardbx.qatest.constant.ConfigConstant;
import com.alibaba.polardbx.qatest.privileges.encdb.EncdbTestBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
Expand Down Expand Up @@ -208,6 +209,9 @@ private void init() {
//ignore
}

//remove encdb jdbc8 driver
EncdbTestBase.cleanJDBC8Driver();

} catch (Throwable t) {
log.error(this.toString(), t);
throw new RuntimeException(t);
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<commons-io.version>2.7</commons-io.version>
<commons-pool.version>1.6</commons-pool.version>
<guava.version>30.1.1-jre</guava.version>
<fastjson.version>1.2.67</fastjson.version>
<fastjson.version>1.2.83</fastjson.version>
<druid.version>1.2.8</druid.version>
<cglib-nodep.version>3.1</cglib-nodep.version>
<jdom.version>2.0.2</jdom.version>
Expand Down

0 comments on commit ca00d7f

Please sign in to comment.