kimmking commented on a change in pull request #4826: issue-4785: Check
uniformed with all actual tables' meta data in once when loading them
URL:
https://github.com/apache/incubator-shardingsphere/pull/4826#discussion_r394397062
##########
File path:
sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/core/metadata/ShardingMetaDataLoader.java
##########
@@ -103,17 +108,43 @@ private SchemaMetaData loadDefaultSchemaMetaData()
throws SQLException {
return actualDefaultDataSourceName.isPresent()
?
SchemaMetaDataLoader.load(dataSourceMap.get(actualDefaultDataSourceName.get()),
maxConnectionsSizePerQuery) : new SchemaMetaData(Collections.emptyMap());
}
-
- // TODO check all meta data in once
+
private void checkUniformed(final String logicTableName, final Map<String,
TableMetaData> actualTableMetaDataMap) {
ShardingTableMetaDataDecorator decorator = new
ShardingTableMetaDataDecorator();
TableMetaData sample =
decorator.decorate(actualTableMetaDataMap.values().iterator().next(),
logicTableName, shardingRule);
+ Collection<TableMetaDataViolation> metaDataViolations = new
LinkedList<>();
+ compareAllTableMetaData(metaDataViolations, sample, decorator,
logicTableName, actualTableMetaDataMap);
+ throwExceptionIfNecessary(metaDataViolations, logicTableName);
+ }
+
+ private void compareAllTableMetaData(final
Collection<TableMetaDataViolation> metaDataViolations, final TableMetaData
sample,
+ final ShardingTableMetaDataDecorator decorator, final
String logicTableName, final Map<String, TableMetaData> actualTableMetaDataMap)
{
for (Entry<String, TableMetaData> entry :
actualTableMetaDataMap.entrySet()) {
- if (!sample.equals(decorator.decorate(entry.getValue(),
logicTableName, shardingRule))) {
- throw new ShardingSphereException(
- "Cannot get uniformed table structure for logic table
`%s` and actual table `%s`. The different meta data of actual tables are as
follows:\n%s\n%s.",
- logicTableName, entry.getKey(), sample,
entry.getValue());
+ TableMetaData tableMetaData = entry.getValue();
+ if (!sample.equals(decorator.decorate(tableMetaData,
logicTableName, shardingRule))) {
+ metaDataViolations.add(new
TableMetaDataViolation(entry.getKey(), tableMetaData));
}
}
}
+
+ private void throwExceptionIfNecessary(final
Collection<TableMetaDataViolation> metaDataViolations, final String
logicTableName) {
+ if (!metaDataViolations.isEmpty()) {
+ StringBuilder exceptionMessageBuilder = new StringBuilder("Cannot
get uniformed table structure for logic table `%s`,"
+ + " it has different meta data of actual tables are as
follows: ");
+ for (TableMetaDataViolation each : metaDataViolations) {
+ exceptionMessageBuilder.append("\nactual table:
").append(each.getActualTableName())
+ .append(", meta data:
").append(each.getTableMetaData());
+ }
+ throw new
ShardingSphereException(exceptionMessageBuilder.toString(), logicTableName);
+ }
+ }
+
+ @AllArgsConstructor(access = AccessLevel.PACKAGE)
Review comment:
why add accessLevel
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services