Skip to content

Commit

Permalink
Merge branch 'develop' into 1028
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes authored Aug 8, 2023
2 parents c197c77 + d8c88d4 commit d5e6a51
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 13 deletions.
6 changes: 5 additions & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Add changes here for all PR submitted to the develop branch.
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX

### bugfix:
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX
- [[#5749](https://github.com/seata/seata/pull/5749)] case of the pk col-name in the business sql is inconsistent with the case in the table metadata, resulting in a rollback failure
- [[#5762](https://github.com/seata/seata/pull/5762)] change some fields type of TableMetaCache to avoid integer overflow


### optimize:
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX
Expand All @@ -21,6 +23,8 @@ Thanks to these contributors for their code commits. Please report an unintended

<!-- Please make sure your Github ID is in the list below -->
- [slievrly](https://github.com/slievrly)
- [capthua](https://github.com/capthua)
- [robynron](https://github.com/robynron)
- [XXX](https://github.com/XXX)


Expand Down
5 changes: 4 additions & 1 deletion changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX

### bugfix:
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX
- [[#5749](https://github.com/seata/seata/pull/5749)] 修复在某些情况下,业务sql中主键字段名大小写与表元数据中的不一致,导致回滚失败
- [[#5762](https://github.com/seata/seata/pull/5762)] 修复TableMetaCache的一些字段类型,避免溢出

### optimize:
- [[#XXX](https://github.com/seata/seata/pull/XXX)] XXX
Expand All @@ -21,6 +22,8 @@

<!-- 请确保您的 GitHub ID 在以下列表中 -->
- [slievrly](https://github.com/slievrly)
- [capthua](https://github.com/capthua)
- [robynron](https://github.com/robynron)
- [XXX](https://github.com/XXX)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialClob;
import javax.sql.rowset.serial.SerialDatalink;
Expand Down Expand Up @@ -193,7 +194,7 @@ public static TableRecords empty(TableMeta tableMeta) {
public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) throws SQLException {
TableRecords records = new TableRecords(tmeta);
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
Map<String, ColumnMeta> primaryKeyMap = tmeta.getPrimaryKeyMap();
Set<String> ignoreCasePKs = tmeta.getCaseInsensitivePKs();
int columnCount = resultSetMetaData.getColumnCount();

while (resultSet.next()) {
Expand All @@ -204,7 +205,7 @@ public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) th
int dataType = col.getDataType();
Field field = new Field();
field.setName(col.getColumnName());
if (primaryKeyMap.containsKey(colName)) {
if (ignoreCasePKs.contains(colName)) {
field.setKeyType(KeyType.PRIMARY_KEY);
}
field.setType(dataType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private TableMeta resultSetMetaToSchema(ResultSetMetaData rsmd, DatabaseMetaData
index.setType(rsIndex.getShort("TYPE"));
index.setOrdinalPosition(rsIndex.getShort("ORDINAL_POSITION"));
index.setAscOrDesc(rsIndex.getString("ASC_OR_DESC"));
index.setCardinality(rsIndex.getInt("CARDINALITY"));
index.setCardinality(rsIndex.getLong("CARDINALITY"));
index.getValues().add(col);
if ("PRIMARY".equalsIgnoreCase(indexName)) {
index.setIndextype(IndexType.PRIMARY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private TableMeta resultSetMetaToSchema(DatabaseMetaData dbmd, String tableName)
index.setType(rsIndex.getShort("TYPE"));
index.setOrdinalPosition(rsIndex.getShort("ORDINAL_POSITION"));
index.setAscOrDesc(rsIndex.getString("ASC_OR_DESC"));
index.setCardinality(rsIndex.getInt("CARDINALITY"));
index.setCardinality(rsIndex.getLong("CARDINALITY"));
index.getValues().add(col);
if (!index.isNonUnique()) {
index.setIndextype(IndexType.UNIQUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private TableMeta resultSetMetaToSchema(Connection connection, String tableName)
index.setType(rsIndex.getShort("type"));
index.setOrdinalPosition(rsIndex.getShort("ordinal_position"));
index.setAscOrDesc(rsIndex.getString("asc_or_desc"));
index.setCardinality(rsIndex.getInt("cardinality"));
index.setCardinality(rsIndex.getLong("cardinality"));
index.getValues().add(col);
if (!index.isNonUnique()) {
index.setIndextype(IndexType.UNIQUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public class MysqlTableMetaCacheTest {

private static Object[][] indexMetas =
new Object[][] {
new Object[] {"PRIMARY", "id", false, "", 3, 0, "A", 34},
new Object[] {"name1", "name1", false, "", 3, 1, "A", 34},
new Object[] {"name2", "name2", true, "", 3, 2, "A", 34},
new Object[] {"PRIMARY", "id", false, "", 3, 0, "A", 34L},
new Object[] {"name1", "name1", false, "", 3, 1, "A", 34L},
new Object[] {"name2", "name2", true, "", 3, 2, "A", 34L},
};

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class IndexMeta {
private short type;
private IndexType indextype;
private String ascOrDesc;
private int cardinality;
private long cardinality;
private int ordinalPosition;

/**
Expand Down Expand Up @@ -157,7 +157,7 @@ public void setAscOrDesc(String ascOrDesc) {
*
* @return the cardinality
*/
public int getCardinality() {
public long getCardinality() {
return cardinality;
}

Expand All @@ -166,7 +166,7 @@ public int getCardinality() {
*
* @param cardinality the cardinality
*/
public void setCardinality(int cardinality) {
public void setCardinality(long cardinality) {
this.cardinality = cardinality;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.Collections;
import java.util.Objects;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -150,6 +153,26 @@ public Map<String, ColumnMeta> getPrimaryKeyMap() {
return pk;
}

/**
* Gets case-insensitive primary key set
*
* @return case-insensitive, unmodifiable primary key set
*/
public Set<String> getCaseInsensitivePKs() {
Set<String> pks = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
allIndexes.forEach((key, index) -> {
if (index.getIndextype().value() == IndexType.PRIMARY.value()) {
for (ColumnMeta col : index.getValues()) {
pks.add(col.getColumnName());
}
}
});
if (pks.size() < 1) {
throw new NotSupportYetException(String.format("%s needs to contain the primary key.", tableName));
}
return Collections.unmodifiableSet(pks);
}

/**
* Gets primary key only name.
*
Expand Down

0 comments on commit d5e6a51

Please sign in to comment.