You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sui6666666 (via GitHub)" <gi...@apache.org> on 2024/04/09 06:32:26 UTC

[I] database-strategy:none not working [shardingsphere]

sui6666666 opened a new issue, #30818:
URL: https://github.com/apache/shardingsphere/issues/30818

   spring boot 2.3.7.RELEASE + sharding-jdbc 5.2.1 + mybatis plus 3.5.3.1
   
   application.yml
   ```
   
   spring:
     shardingsphere:
       mode:
         type: Standalone
         repository:
           type: JDBC
       datasource:
         names: master,ds0,ds1,dss0,dss1
         master:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: jdbc:mysql://localhost:3306/master?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
           username: root
           password: root
         ds0:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: jdbc:mysql://localhost:3306/ds_0?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
           username: root
           password: root
         ds1:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: jdbc:mysql://localhost:3306/ds_1?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
           username: root
           password: root
         dss0:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: jdbc:mysql://localhost:3306/ds_2?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
           username: root
           password: root
         dss1:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: jdbc:mysql://localhost:3306/ds_3?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
           username: root
           password: root
   
   
       rules:
         sharding:
   
           tables:
             user:
               actual-data-nodes: ds$->{0..1}.user,dss$->{0..1}.user
               key-generate-strategy:
                 column: id
                 key-generator-name: snowflake
             suilang:
               actual-data-nodes: master.suilang
               database-strategy:
                 none: null
               key-generate-strategy:
                 column: id
                 key-generator-name: snowflake
           broadcast-tables: sys_dic
           default-database-strategy:
             standard:
               sharding-column: id
               sharding-algorithm-name: database-precise-algorithm
   #          hint:
   #            sharding-algorithm-name: database-hint-algorithm
           sharding-algorithms:
             database-precise-algorithm:
               type: CLASS_BASED
               props:
                 strategy: STANDARD
                 algorithmClassName: com.cxytiandi.sharding.algorithm.CustomPreciseShardingAlgorithm
             database-hint-algorithm:
               type: CLASS_BASED
               props:
                 strategy: HINT
                 algorithmClassName: com.cxytiandi.sharding.algorithm.CustomHintShardingAlgorithm
           key-generators:
             snowflake:
               type: SNOWFLAKE
       props:
         sql-show: true
   
   
   
   
   ```
   
   CustomPreciseShardingAlgorithm.java
   ```
   public class CustomHintShardingAlgorithm implements HintShardingAlgorithm<String> {
   
   
   	@Override
   	public Collection<String> doSharding(Collection<String> collection, HintShardingValue<String> hintShardingValue) {
   		Collection<String> values = hintShardingValue.getValues();
   		String dbName = values.stream().findFirst().orElseThrow(() -> new IllegalArgumentException("发生异常"));
   		return values;
   	}
   
   	@Override
   	public Properties getProps() {
   		return null;
   	}
   
   	@Override
   	public void init(Properties properties) {
   
   	}
   }
   ```
   
   
   the single talbe suilang only exsit in database master;
   when I excute insert statement to suilang table,
   
   When I execute the insert statement  to table suilang, even though I have configured the suilang table database sharding to be None, it still goes to the default database sharding algorithm


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #30818: database-strategy:none not working
URL: https://github.com/apache/shardingsphere/issues/30818


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "TherChenYang (via GitHub)" <gi...@apache.org>.
TherChenYang commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2046973501

   Hi @sui6666666, thank you for your feedback.  Can you provide an example repository? I want to try to reproduce this exception.


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2106360310

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "sui6666666 (via GitHub)" <gi...@apache.org>.
sui6666666 commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2051065585

   Can someone help me , thank you very much


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "sui6666666 (via GitHub)" <gi...@apache.org>.
sui6666666 commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2051299704

   I upgraded to sharding 5.3.2,and it working


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "sui6666666 (via GitHub)" <gi...@apache.org>.
sui6666666 commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2048854232

   > Hi @sui6666666, thank you for your feedback. Can you provide an example repository? I want to try to reproduce this exception.
   
   thanks , the example repository is [https://github.com/sui6666666/sharding-jdbc.git](url)
   and the project is sjdbc-db-sharding-table-springboot


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "sui6666666 (via GitHub)" <gi...@apache.org>.
sui6666666 commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2044245843

   
   CustomPreciseShardingAlgorithm.java
   code is 
   ```
   public class CustomPreciseShardingAlgorithm implements StandardShardingAlgorithm<Long> {
   
   	private static List<ShardingRangeConfig> configs = new ArrayList<>();
   
   	static {
   		ShardingRangeConfig config = new ShardingRangeConfig();
   		config.setStart(0);
   		config.setEnd(10);
   		config.setDatasourceList(Arrays.asList("ds0", "ds1"));
   		configs.add(config);
   
   		config = new ShardingRangeConfig();
   		config.setStart(11);
   		config.setEnd(20);
   		config.setDatasourceList(Arrays.asList("dss0", "dss1"));
   		configs.add(config);
   	}
   
   
   	@Override
   	public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
   		return null;
   	}
   
   
   	@Override
   	public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {
   		Optional<ShardingRangeConfig> configOptional = configs.stream().filter(
   				c -> preciseShardingValue.getValue() >= c.getStart() && preciseShardingValue.getValue() <= c.getEnd()).findFirst();
   		if (configOptional.isPresent()) {
   			ShardingRangeConfig rangeConfig = configOptional.get();
   			for (String ds : rangeConfig.getDatasourceList()) {
   				if (ds.endsWith(preciseShardingValue.getValue() % 2 + "")) {
   					System.err.println(ds);
   					return ds;
   				}
   			}
   		}
   		System.err.println("发生异常");
   		throw new IllegalArgumentException();
   	}
   
   	@Override
   	public Properties getProps() {
   		return null;
   	}
   
   	@Override
   	public void init(Properties properties) {
   
   	}
   ```


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


Re: [I] database-strategy:none not working [shardingsphere]

Posted by "TherChenYang (via GitHub)" <gi...@apache.org>.
TherChenYang commented on issue #30818:
URL: https://github.com/apache/shardingsphere/issues/30818#issuecomment-2051459932

   @sui6666666 Thank you for your feedback, I will check if the same issue still exists in the latest version.


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