sandynz commented on code in PR #18035:
URL: https://github.com/apache/shardingsphere/pull/18035#discussion_r884196854
##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java:
##########
@@ -75,10 +75,31 @@ public final class
ShardingRuleAlteredJobConfigurationPreparer implements RuleAl
@Override
public void extendJobConfiguration(final YamlRuleAlteredJobConfiguration
yamlJobConfig) {
- Map<String, List<DataNode>> actualDataNodes = getActualDataNodes(new
RuleAlteredJobConfigurationSwapper().swapToObject(yamlJobConfig));
+ RuleAlteredJobConfiguration jobConfig = new
RuleAlteredJobConfigurationSwapper().swapToObject(yamlJobConfig);
+ Map<String, List<DataNode>> actualDataNodes =
getActualDataNodes(jobConfig);
yamlJobConfig.setJobShardingDataNodes(getJobShardingDataNodes(actualDataNodes));
yamlJobConfig.setLogicTables(getLogicTables(actualDataNodes.keySet()));
yamlJobConfig.setTablesFirstDataNodes(getTablesFirstDataNodes(actualDataNodes));
+ ShardingSphereDatabase database =
PipelineContext.getContextManager().getMetaDataContexts().getMetaData().getDatabases().get(jobConfig.getDatabaseName());
+ Map<String, String> tableSchema = new
HashMap<>(actualDataNodes.size(), 1);
+ for (String logicTable : actualDataNodes.keySet()) {
+ tableSchema.put(logicTable,
getLogicTableSchema(database.getSchemas(), new LogicTableName(logicTable)));
+ }
+ yamlJobConfig.setSourceTableSchemaMap(tableSchema);
+ yamlJobConfig.setTargetTableSchemaMap(tableSchema);
+ }
+
+ private static String getLogicTableSchema(final Map<String,
ShardingSphereSchema> schemaMap, final LogicTableName logicTableName) {
+ if (schemaMap == null || schemaMap.isEmpty()) {
+ return null;
+ }
+ // TODO if create same table, will use the first, may cause problem.
+ for (Entry<String, ShardingSphereSchema> entry : schemaMap.entrySet())
{
+ if (entry.getValue().containsTable(logicTableName.getLowercase()))
{
+ return entry.getKey();
+ }
+ }
+ return null;
}
Review Comment:
Seems it still get first schema name by logic table name.
##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/data/pipeline/ShardingRuleAlteredJobConfigurationPreparer.java:
##########
@@ -75,10 +75,31 @@ public final class
ShardingRuleAlteredJobConfigurationPreparer implements RuleAl
@Override
public void extendJobConfiguration(final YamlRuleAlteredJobConfiguration
yamlJobConfig) {
- Map<String, List<DataNode>> actualDataNodes = getActualDataNodes(new
RuleAlteredJobConfigurationSwapper().swapToObject(yamlJobConfig));
+ RuleAlteredJobConfiguration jobConfig = new
RuleAlteredJobConfigurationSwapper().swapToObject(yamlJobConfig);
+ Map<String, List<DataNode>> actualDataNodes =
getActualDataNodes(jobConfig);
yamlJobConfig.setJobShardingDataNodes(getJobShardingDataNodes(actualDataNodes));
yamlJobConfig.setLogicTables(getLogicTables(actualDataNodes.keySet()));
yamlJobConfig.setTablesFirstDataNodes(getTablesFirstDataNodes(actualDataNodes));
+ ShardingSphereDatabase database =
PipelineContext.getContextManager().getMetaDataContexts().getMetaData().getDatabases().get(jobConfig.getDatabaseName());
+ Map<String, String> tableSchema = new
HashMap<>(actualDataNodes.size(), 1);
+ for (String logicTable : actualDataNodes.keySet()) {
+ tableSchema.put(logicTable,
getLogicTableSchema(database.getSchemas(), new LogicTableName(logicTable)));
+ }
+ yamlJobConfig.setSourceTableSchemaMap(tableSchema);
+ yamlJobConfig.setTargetTableSchemaMap(tableSchema);
Review Comment:
For common fields, it could be put in
`RuleAlteredJobWorker.createJobConfig`. `extendJobConfiguration` is used to
extend special fields in SPI impl.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]