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 2021/06/07 07:57:54 UTC

[GitHub] [shardingsphere] stelin opened a new issue #10699: default-database-strategy:hint 不生效

stelin opened a new issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699


   ShardingSphere-JDBC 4.1.1 default-database-strategy:hint can't use
   
   spring:
   shardingsphere:
   sharding:
   default-data-source-name: demo-1
   default-database-strategy:
   hint:
   algorithm-class-name: com.ai94.mysql.annotation.AnnotationHintShardingAlgorithm
   datasource:
   names: demo-1,demo-2
   # 配置第 1 个数据源
   demo-1:
   type: com.zaxxer.hikari.HikariDataSource
   driverClassName: com.mysql.jdbc.Driver
   jdbcUrl: jdbc:mysql://localhost:3306/db_A?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
   username: root
   password: root
   # 配置第 2 个数据源
   demo-2:
   type: com.zaxxer.hikari.HikariDataSource
   driverClassName: com.mysql.jdbc.Driver
   jdbcUrl: jdbc:mysql://localhost:3306/db_B?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
   username: root
   password: root


-- 
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



[GitHub] [shardingsphere] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858539416


   I work will like your method. but I  do not configure `TableRuleConfiguration`,  becase only want to sharding for datasource.If must to configure table runles,It's very troublesome for many tables(200+)


-- 
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



[GitHub] [shardingsphere] tuziaifendou commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
tuziaifendou commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1005350449


   > @stelin In version 4.x, you need to configure `shardingRuleConfig.setDefaultDataSourceName("ds_0");` to meet your needs. In version 5.x, we introduced the concept of [single table](https://shardingsphere.apache.org/document/current/cn/features/sharding/concept/sql/#%E5%8D%95%E8%A1%A8), you can route these tables automatically without any configuration.
   
   In version 4.1.1,when i add spring.shardingsphere.sharding.default-data-source-name=ds0.when start service,meta data load cost about 204022 milliseconds,then service starts very slowly. how to solution?


-- 
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] tuziaifendou commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
tuziaifendou commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1007033723


    
    
   您好,我现在正在工作中,无法亲自回复您的邮件。我将在工作结束后,尽快给您回复。


-- 
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] strongduanmu commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1007033518


   > > @stelin How did you solve it in the end? I have the same problem
   > 
   > I have the same problem too
   
   @tuziaifendou I think you can submit a new issue to describe your problem.


-- 
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] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858544059


   Only one rule for database.Has not table rules.
   ![image](https://user-images.githubusercontent.com/1677543/121518045-9dcba580-ca22-11eb-8439-3abe921da83b.png)
   


-- 
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



[GitHub] [shardingsphere] tuziaifendou commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
tuziaifendou commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1006556303


   > @stelin How did you solve it in the end? I have the same problem
   
   I have the same problem too


-- 
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] strongduanmu commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-859177370






-- 
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



[GitHub] [shardingsphere] wanlongz commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
wanlongz commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1002887670


   @stelin How did you solve it in the end? I have the same problem


-- 
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] strongduanmu commented on issue #10699: default-database-strategy:hint 不生效

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-855712735


   @stelin Can you submit this issue in English?


-- 
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



[GitHub] [shardingsphere] stelin edited a comment on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin edited a comment on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858539416


   I work will like your method. but I  do not configure `TableRuleConfiguration`,  becase only want to sharding for datasource.If must to configure table rules,It's very troublesome for many tables(200+)


-- 
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



[GitHub] [shardingsphere] strongduanmu commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858518859


   When i set `HintManager.getInstance().setDatabaseShardingValue(1);`, the route result is:
   ```
   [main] INFO ShardingSphere-SQL - Logic SQL: SELECT * FROM t_order
   [main] INFO ShardingSphere-SQL - SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@62b969c4, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@dcc6211), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@dcc6211, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=order_id, alias=Optional.empty), ColumnProjection(owner=null, name=user_id, alias=Optional.empty), ColumnProjection(owner=null, name=status, alias=Optional.empty), ColumnProjection(owner=null, name=content, alias=Optional.empty), ColumnProjection(owner=null, name=content_new, alias=Optional.empty), ColumnProjection(owner=null, name=content_new_2, alias=Optional.empty), ColumnProjection(owner=null, name=order_name, al
 ias=Optional.empty), ColumnProjection(owner=null, name=item_cd, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@47ec7422, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@48535004, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@610df783, containsSubquery=false)
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT * FROM t_order_0
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT * FROM t_order_1
   ```
   
   When i set `HintManager.getInstance().setDatabaseShardingValue(0);`, the route result is:
   ```
   [main] INFO ShardingSphere-SQL - Logic SQL: SELECT * FROM t_order
   [main] INFO ShardingSphere-SQL - SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@4441d567, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3e1624c7), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@3e1624c7, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=order_id, alias=Optional.empty), ColumnProjection(owner=null, name=user_id, alias=Optional.empty), ColumnProjection(owner=null, name=status, alias=Optional.empty), ColumnProjection(owner=null, name=content, alias=Optional.empty), ColumnProjection(owner=null, name=content_new, alias=Optional.empty), ColumnProjection(owner=null, name=content_new_2, alias=Optional.empty), ColumnProjection(owner=null, name=order_name, 
 alias=Optional.empty), ColumnProjection(owner=null, name=item_cd, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@62b969c4, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@dcc6211, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@47ec7422, containsSubquery=false)
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT * FROM t_order_0
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT * FROM t_order_1
   ```
   
   When i don't set `HintManager.getInstance().setDatabaseShardingValue(0);`, the route result is:
   ```
   [main] INFO ShardingSphere-SQL - Logic SQL: SELECT * FROM t_order
   [main] INFO ShardingSphere-SQL - SQLStatement: SelectStatementContext(super=CommonSQLStatementContext(sqlStatement=org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement@6e0cff20, tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@359b650b), tablesContext=org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext@359b650b, projectionsContext=ProjectionsContext(startIndex=7, stopIndex=7, distinctRow=false, projections=[ShorthandProjection(owner=Optional.empty, actualColumns=[ColumnProjection(owner=null, name=order_id, alias=Optional.empty), ColumnProjection(owner=null, name=user_id, alias=Optional.empty), ColumnProjection(owner=null, name=status, alias=Optional.empty), ColumnProjection(owner=null, name=content, alias=Optional.empty), ColumnProjection(owner=null, name=content_new, alias=Optional.empty), ColumnProjection(owner=null, name=content_new_2, alias=Optional.empty), ColumnProjection(owner=null, name=order_name, 
 alias=Optional.empty), ColumnProjection(owner=null, name=item_cd, alias=Optional.empty)])]), groupByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.groupby.GroupByContext@6a9b0a6f, orderByContext=org.apache.shardingsphere.sql.parser.binder.segment.select.orderby.OrderByContext@10667848, paginationContext=org.apache.shardingsphere.sql.parser.binder.segment.select.pagination.PaginationContext@191a709b, containsSubquery=false)
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT * FROM t_order_0
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_0 ::: SELECT * FROM t_order_1
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT * FROM t_order_0
   [main] INFO ShardingSphere-SQL - Actual SQL: ds_1 ::: SELECT * FROM t_order_1
   ```
   
   So I want to know what is your configuration? What is the abnormal phenomenon?


-- 
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



[GitHub] [shardingsphere] strongduanmu edited a comment on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu edited a comment on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858515798


   Hi @stelin, I used the version `4.1.1` of `Sharding-JDBC` to test the Hint feature, and there is no problems. The following is my test demo.
   
   ```java
   public class HintTest {
       
       public static void main(String[] args) throws SQLException {
           DataSource dataSource = new HintTest().getShardingDataSource();
           Connection connection = dataSource.getConnection();
           PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM t_order");
           HintManager.getInstance().setDatabaseShardingValue(1);
           ResultSet resultSet = preparedStatement.executeQuery();
           while (resultSet.next()) {
               System.out.println(resultSet.getString("ORDER_ID") + " " + resultSet.getString("USER_ID"));
           }
           HintManager.getInstance().close();
           resultSet.close();
           preparedStatement.close();
           connection.close();
       }
       
       private DataSource getShardingDataSource() throws SQLException {
           ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
           shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
           shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
           shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
           shardingRuleConfig.getBroadcastTables().add("t_config");
           shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new HintShardingStrategyConfiguration(new AnnotationHintShardingAlgorithm()));
           shardingRuleConfig.setDefaultTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("order_id", "ds_${order_id % 2}"));
           Properties props = new Properties();
           props.setProperty("sql.show", "true");
           return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, props);
       }
       
       private static KeyGeneratorConfiguration getKeyGeneratorConfiguration() {
           KeyGeneratorConfiguration result = new KeyGeneratorConfiguration("SNOWFLAKE", "order_id");
           return result;
       }
       
       TableRuleConfiguration getOrderTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..1}");
           result.setKeyGeneratorConfig(getKeyGeneratorConfiguration());
           return result;
       }
       
       TableRuleConfiguration getOrderItemTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item_${0..1}");
           return result;
       }
       
       Map<String, DataSource> createDataSourceMap() {
           Map<String, DataSource> result = new HashMap<>();
           result.put("ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
           result.put("ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
           return result;
       }
   }
   
   public final class DataSourceUtil {
       
       private static final String HOST = "localhost";
       
       private static final int PORT = 3306;
       
       private static final String USER_NAME = "root";
       
       private static final String PASSWORD = "123456";
       
       public static DataSource createDataSource(final String dataSourceName) {
           HikariDataSource result = new HikariDataSource();
           result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
           result.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8", HOST, PORT, dataSourceName));
           result.setUsername(USER_NAME);
           result.setPassword(PASSWORD);
           return result;
       }
   }
   
   public class AnnotationHintShardingAlgorithm implements HintShardingAlgorithm<Integer> {
       
       @Override
       public Collection<String> doSharding(final Collection<String> availableTargetNames, final HintShardingValue<Integer> shardingValue) {
           for (String each : availableTargetNames) {
               if (each.endsWith(String.valueOf(shardingValue.getValues().iterator().next() % 2))) {
                   return Collections.singletonList(each);
               }
           }
           return null;
       }
   }
   ```


-- 
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



[GitHub] [shardingsphere] stelin commented on issue #10699: default-database-strategy:hint 不生效

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-855697279


   like https://github.com/apache/shardingsphere/issues/5970


-- 
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



[GitHub] [shardingsphere] tuziaifendou removed a comment on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
tuziaifendou removed a comment on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1005349766


   > @stelin In version 4.x, you need to configure `shardingRuleConfig.setDefaultDataSourceName("ds_0");` to meet your needs. In version 5.x, we introduced the concept of [single table](https://shardingsphere.apache.org/document/current/cn/features/sharding/concept/sql/#%E5%8D%95%E8%A1%A8), you can route these tables automatically without any configuration.
   
    In version 4.1.1,when i add spring.shardingsphere.sharding.default-data-source-name=ds0,then service starts very slowly.
   
   
   
   > @stelin In version 4.x, you need to configure `shardingRuleConfig.setDefaultDataSourceName("ds_0");` to meet your needs. In version 5.x, we introduced the concept of [single table](https://shardingsphere.apache.org/document/current/cn/features/sharding/concept/sql/#%E5%8D%95%E8%A1%A8), you can route these tables automatically without any configuration.
   
    In version 4.1.1,when i add spring.shardingsphere.sharding.default-data-source-name=ds0.when start service,meta data load cost about 204022 milliseconds,then service starts very slowly. how to solution?


-- 
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] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858545016


   If must to configure table rules like below.
   ![image](https://user-images.githubusercontent.com/1677543/121518217-d0759e00-ca22-11eb-851c-3d6d386f9c8b.png)
   


-- 
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



[GitHub] [shardingsphere] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858546773


   We only want to switch datasource(database), It has nothing to do with tables.


-- 
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



[GitHub] [shardingsphere] strongduanmu edited a comment on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu edited a comment on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858515798


   Hi @stelin, I used the version `4.1.1` of `Sharding-JDBC` to test the Hint feature, and there is no problems. The following is my test demo.
   
   ```java
   public class HintTest {
       
       public static void main(String[] args) throws SQLException {
           DataSource dataSource = new HintTest().getShardingDataSource();
           Connection connection = dataSource.getConnection();
           PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM t_order");
           HintManager.getInstance().setDatabaseShardingValue(1);
           ResultSet resultSet = preparedStatement.executeQuery();
           while (resultSet.next()) {
               System.out.println(resultSet.getString("ORDER_ID") + " " + resultSet.getString("USER_ID"));
           }
           HintManager.getInstance().close();
           resultSet.close();
           preparedStatement.close();
           connection.close();
       }
       
       private DataSource getShardingDataSource() throws SQLException {
           ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
           shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
           shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
           shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
           shardingRuleConfig.getBroadcastTables().add("t_config");
           shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new HintShardingStrategyConfiguration(new AnnotationHintShardingAlgorithm()));
           shardingRuleConfig.setDefaultTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("order_id", "ds_${order_id % 2}"));
           Properties props = new Properties();
           props.setProperty("sql.show", "true");
           return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, props);
       }
       
       private static KeyGeneratorConfiguration getKeyGeneratorConfiguration() {
           KeyGeneratorConfiguration result = new KeyGeneratorConfiguration("SNOWFLAKE", "order_id");
           return result;
       }
       
       TableRuleConfiguration getOrderTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..1}");
           result.setKeyGeneratorConfig(getKeyGeneratorConfiguration());
           return result;
       }
       
       TableRuleConfiguration getOrderItemTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item_${0..1}");
           return result;
       }
       
       Map<String, DataSource> createDataSourceMap() {
           Map<String, DataSource> result = new HashMap<>();
           result.put("ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
           result.put("ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
           return result;
       }
   }
   ```
   
   public final class DataSourceUtil {
       
       private static final String HOST = "localhost";
       
       private static final int PORT = 3306;
       
       private static final String USER_NAME = "root";
       
       private static final String PASSWORD = "123456";
       
       public static DataSource createDataSource(final String dataSourceName) {
           HikariDataSource result = new HikariDataSource();
           result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
           result.setJdbcUrl(String.format("jdbc:mysql://%s:%s/%s?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8", HOST, PORT, dataSourceName));
           result.setUsername(USER_NAME);
           result.setPassword(PASSWORD);
           return result;
       }
   }
   
   public class AnnotationHintShardingAlgorithm implements HintShardingAlgorithm<Integer> {
       
       @Override
       public Collection<String> doSharding(final Collection<String> availableTargetNames, final HintShardingValue<Integer> shardingValue) {
           for (String each : availableTargetNames) {
               if (each.endsWith(String.valueOf(shardingValue.getValues().iterator().next() % 2))) {
                   return Collections.singletonList(each);
               }
           }
           return null;
       }
   }
   


-- 
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



[GitHub] [shardingsphere] tuziaifendou commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
tuziaifendou commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-1005349766


   > @stelin In version 4.x, you need to configure `shardingRuleConfig.setDefaultDataSourceName("ds_0");` to meet your needs. In version 5.x, we introduced the concept of [single table](https://shardingsphere.apache.org/document/current/cn/features/sharding/concept/sql/#%E5%8D%95%E8%A1%A8), you can route these tables automatically without any configuration.
   
    In version 4.1.1,when i add spring.shardingsphere.sharding.default-data-source-name=ds0,then service starts very slowly.
   
   
   
   > @stelin In version 4.x, you need to configure `shardingRuleConfig.setDefaultDataSourceName("ds_0");` to meet your needs. In version 5.x, we introduced the concept of [single table](https://shardingsphere.apache.org/document/current/cn/features/sharding/concept/sql/#%E5%8D%95%E8%A1%A8), you can route these tables automatically without any configuration.
   
    In version 4.1.1,when i add spring.shardingsphere.sharding.default-data-source-name=ds0.when start service,meta data load cost about 204022 milliseconds,then service starts very slowly. how to solution?


-- 
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] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-855934674


   @strongduanmu 
   Only configure default-database-strategy,This method does not seem to be supported!
   


-- 
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



[GitHub] [shardingsphere] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858545679


   It's very troublesome, because every table must to be configured. 


-- 
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



[GitHub] [shardingsphere] strongduanmu commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-858515798


   Hi @stelin, I used the version `4.1.1` of `Sharding-JDBC` to test the Hint feature, and there is no problems. The following is my test demo:
   
   ```java
   public class HintTest {
       
       public static void main(String[] args) throws SQLException {
           DataSource dataSource = new HintTest().getShardingDataSource();
           Connection connection = dataSource.getConnection();
           PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM t_order");
           HintManager.getInstance().setDatabaseShardingValue(1);
           ResultSet resultSet = preparedStatement.executeQuery();
           while (resultSet.next()) {
               System.out.println(resultSet.getString("ORDER_ID") + " " + resultSet.getString("USER_ID"));
           }
           HintManager.getInstance().close();
           resultSet.close();
           preparedStatement.close();
           connection.close();
       }
       
       private DataSource getShardingDataSource() throws SQLException {
           ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
           shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
           shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
           shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
           shardingRuleConfig.getBroadcastTables().add("t_config");
           shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new HintShardingStrategyConfiguration(new AnnotationHintShardingAlgorithm()));
           shardingRuleConfig.setDefaultTableShardingStrategyConfig(new InlineShardingStrategyConfiguration("order_id", "ds_${order_id % 2}"));
           Properties props = new Properties();
           props.setProperty("sql.show", "true");
           return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, props);
       }
       
       private static KeyGeneratorConfiguration getKeyGeneratorConfiguration() {
           KeyGeneratorConfiguration result = new KeyGeneratorConfiguration("SNOWFLAKE", "order_id");
           return result;
       }
       
       TableRuleConfiguration getOrderTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..1}");
           result.setKeyGeneratorConfig(getKeyGeneratorConfiguration());
           return result;
       }
       
       TableRuleConfiguration getOrderItemTableRuleConfiguration() {
           TableRuleConfiguration result = new TableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item_${0..1}");
           return result;
       }
       
       Map<String, DataSource> createDataSourceMap() {
           Map<String, DataSource> result = new HashMap<>();
           result.put("ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
           result.put("ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
           return result;
       }
   }
   ```
   
   


-- 
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



[GitHub] [shardingsphere] strongduanmu closed issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
strongduanmu closed issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699


   


-- 
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



[GitHub] [shardingsphere] stelin commented on issue #10699: default-database-strategy:hint hint can't use

Posted by GitBox <gi...@apache.org>.
stelin commented on issue #10699:
URL: https://github.com/apache/shardingsphere/issues/10699#issuecomment-859212033






-- 
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