You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/06/26 08:34:52 UTC
[GitHub] [shardingsphere] gavenpeng opened a new pull request, #18606: Support force route use hint provider sharding value
gavenpeng opened a new pull request, #18606:
URL: https://github.com/apache/shardingsphere/pull/18606
Increment feature: support forced route use hint not influenced with sharding strategy
Changes proposed in this pull request:
support force routing by hint with in code mode,as long as the thread context has the force-routing flag,may be route
to config database or config table,not influenced by sharding strategy config.
demoļ¼
```
public void demoFunc() {
HintManager hintManager = HintManager.getInstance();
//force route to config database
hintManager.addDatabaseShardingValue("logic_table_name", "sharding_value");
// force route to
hintManager.addTableShardingValue("logic_table_name", "sharding_value");
try {
//your code
} catch (Throwable e) {
xxxxxxx
} finally {
// this is must
hintManager.close();
}
```
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] gavenpeng closed pull request #18606: Support force route use hint provider sharding value
Posted by GitBox <gi...@apache.org>.
gavenpeng closed pull request #18606: Support force route use hint provider sharding value
URL: https://github.com/apache/shardingsphere/pull/18606
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #18606: Support force route use hint provider sharding value
Posted by GitBox <gi...@apache.org>.
terrymanu commented on code in PR #18606:
URL: https://github.com/apache/shardingsphere/pull/18606#discussion_r906797347
##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -214,10 +238,23 @@ private Collection<String> routeDataSources(final TableRule tableRule, final Sha
private Collection<DataNode> routeTables(final TableRule tableRule, final String routedDataSource,
final ShardingStrategy tableShardingStrategy, final List<ShardingConditionValue> tableShardingValues) {
- Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
- Collection<String> routedTables = tableShardingValues.isEmpty()
- ? availableTargetTables
- : tableShardingStrategy.doSharding(availableTargetTables, tableShardingValues, tableRule.getTableDataNode(), properties);
+ Collection<String> routedTables = null;
+ if (!(tableShardingStrategy instanceof HintShardingStrategy)) {
+ if (!tableShardingValues.isEmpty()) {
+ ShardingConditionValue shardingConditionValue = tableShardingValues.iterator().next();
+ List<ShardingConditionValue> tableHintShardingValues = getTableShardingValuesFromHint(shardingConditionValue);
+ if (!tableHintShardingValues.isEmpty()) {
+ Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
+ routedTables = new LinkedHashSet<>(tableShardingStrategy.doSharding(availableTargetTables, tableHintShardingValues, tableRule.getTableDataNode(), properties));
+ }
+ }
+ }
+ if (routedTables == null || routedTables.isEmpty()) {
+ Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
+ routedTables = new LinkedHashSet<>(tableShardingValues.isEmpty()
+ ? availableTargetTables
+ : tableShardingStrategy.doSharding(availableTargetTables, tableShardingValues, tableRule.getTableDataNode(), properties));
+ }
Review Comment:
There are too many nested if, could you refactor them?
##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRoutingEngine.java:
##########
@@ -202,10 +214,22 @@ private Collection<DataNode> route0(final TableRule tableRule,
}
private Collection<String> routeDataSources(final TableRule tableRule, final ShardingStrategy databaseShardingStrategy, final List<ShardingConditionValue> databaseShardingValues) {
- if (databaseShardingValues.isEmpty()) {
- return tableRule.getActualDatasourceNames();
+ Collection<String> result = null;
+ if (!(databaseShardingStrategy instanceof HintShardingStrategy)) {
+ if (!databaseShardingValues.isEmpty()) {
+ ShardingConditionValue shardingConditionValue = databaseShardingValues.iterator().next();
+ List<ShardingConditionValue> databaseHintShardingValues = getDatabaseShardingValuesFromHint(shardingConditionValue);
+ if (!databaseHintShardingValues.isEmpty()) {
+ result = databaseShardingStrategy.doSharding(tableRule.getActualDatasourceNames(), databaseHintShardingValues, tableRule.getDataSourceDataNode(), properties);
+ }
+ }
+ }
+ if (result == null) {
+ if (databaseShardingValues.isEmpty()) {
+ return tableRule.getActualDatasourceNames();
+ }
Review Comment:
There are too many nested if, could you refactor them?
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org