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 2020/02/04 02:52:39 UTC

[GitHub] [incubator-shardingsphere] tmjGitAccount opened a new issue #3964: Hintmanager databaseShardingOnly problem

tmjGitAccount opened a new issue #3964: Hintmanager  databaseShardingOnly problem
URL: https://github.com/apache/incubator-shardingsphere/issues/3964
 
 
   ## Bug Report
   
   Please answer these questions before submitting your issue. Thanks!
   ### Which version of ShardingSphere did you use?
   **4.0.0**
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-JDBC
   ### Expected behavior
   i can hint databases with sth outside my database, for example , i want to get the hint key from my http header ,then route by the key.
   ### Actual behavior
   it route to all my datasources
   ### Reason analyze (If you can)
   maybe the hintmanager has wrong code 
   
   this code is in hintmanager,i use **setDatabaseShardingValue** method to config my shardkey,
   here, it put an empty key for the sharding values. 
   
   ***
       public void setDatabaseShardingValue(final Comparable<?> value) {
           databaseShardingValues.clear();
           tableShardingValues.clear();
           databaseShardingValues.put("", value);
           databaseShardingOnly = true;
       }
   ***
   but when i followed it in the **getDatabaseShardingValues** method, it gets the shardingValues
   by the logicTable, so I can not get the shardingvalues which i configed.
   
   ***
       public static Collection<Comparable<?>> getDatabaseShardingValues(final String logicTable) {
           return null == HINT_MANAGER_HOLDER.get() ? Collections.<Comparable<?>>emptyList() : HINT_MANAGER_HOLDER.get().databaseShardingValues.get(logicTable);
       }
   ***
   
   then  in the **routeDataSources** method of  **StandardRoutingEngine** 
   
   ***
       private Collection<String> routeDataSources(final TableRule tableRule, final List<RouteValue> databaseShardingValues) {
           if (databaseShardingValues.isEmpty()) {
               return tableRule.getActualDatasourceNames();
           }
           Collection<String> result = new LinkedHashSet<>(shardingRule.getDatabaseShardingStrategy(tableRule).doSharding(tableRule.getActualDatasourceNames(), databaseShardingValues));
           Preconditions.checkState(!result.isEmpty(), "no database route info");
           Preconditions.checkState(tableRule.getActualDatasourceNames().containsAll(result), 
                   "Some routed data sources do not belong to configured data sources. routed data sources: `%s`, configured data sources: `%s`", result, tableRule.getActualDatasourceNames());
           return result;
       }
   ***
   the databaseShardingValues is empty , so it returns all the actualDatasources, not only the datasource i conifged.
   
   could you please provide an example for this situation?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services