coderMmw opened a new issue #5208: data fragmentation and separation of reading 
and writing problem
URL: https://github.com/apache/incubator-shardingsphere/issues/5208
 
 
   【sharding.xml info】
   `<?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:context="http://www.springframework.org/schema/context";
           
xmlns:master-slave="http://shardingsphere.apache.org/schema/shardingsphere/masterslave";
           
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding";
           xmlns:tx="http://www.springframework.org/schema/tx";
        xmlns:aop="http://www.springframework.org/schema/aop";
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                           
http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context 
                           
http://www.springframework.org/schema/context/spring-context.xsd
                            
http://shardingsphere.apache.org/schema/shardingsphere/masterslave
                           
http://shardingsphere.apache.org/schema/shardingsphere/masterslave/master-slave.xsd
   
                           http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://shardingsphere.apache.org/schema/shardingsphere/sharding
        
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
                           ">
        <!--
                xmlns:rdb="http://www.dangdang.com/schema/ddframe/rdb";
                http://www.dangdang.com/schema/ddframe/rdb
           http://www.dangdang.com/schema/ddframe/rdb/rdb.xsd-->
   
        <!-- <context:property-placeholder 
location="classpath:source.properties" 
                ignore-unresolvable="true"/> -->
        <bean id="defaultDataSource" 
class="com.alibaba.druid.pool.DruidDataSource"
                init-method="init" destroy-method="close">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" 
/>
                <property name="url" value="${master.jdbc.url}" />
                <property name="username" value="${master.jdbc.username}" />
                <property name="password" value="${master.jdbc.password}" />
                <property name="initialSize" value="2" />
                <property name="minIdle" value="2" />
                <property name="maxActive" value="30" />
                <property name="testOnBorrow" value="true" />
                <property name="testWhileIdle" value="true" />
                <property name="testOnReturn" value="false" />
                <property name="validationQuery" value="SELECT 'x'" />
        
                <property name="maxWait" value="5000" />
   
                <property name="minEvictableIdleTimeMillis" value="30000" />
                <property name="removeAbandoned" value="true" />
                <property name="removeAbandonedTimeout" value="10000" />
                <property name="timeBetweenEvictionRunsMillis" value="600000" />
        </bean>
   
        <bean id="readDataSource" class="com.alibaba.druid.pool.DruidDataSource"
                init-method="init" destroy-method="close">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" 
/>
                <property name="url" value="${salve.jdbc.url}" />
                <property name="username" value="${salve.jdbc.username}" />
                <property name="password" value="${salve.jdbc.password}" />
                <property name="initialSize" value="2" />
                <property name="minIdle" value="2" />
                <property name="maxActive" value="30" />
                <property name="testOnBorrow" value="true" />
                <property name="testWhileIdle" value="true" />
                <property name="testOnReturn" value="false" />
                <property name="validationQuery" value="SELECT 'x'" />
                <property name="maxWait" value="5000" />
                <property name="minEvictableIdleTimeMillis" value="30000" />
                <property name="removeAbandoned" value="true" />
                <property name="removeAbandonedTimeout" value="10000" />
                <property name="timeBetweenEvictionRunsMillis" value="600000" />
        </bean>
   
        <!--<master-slave:data-source id="masterSlaveDataSource" 
master-data-source-name="defaultDataSource" 
slave-data-source-names="readDataSource" >-->
                <!--<master-slave:props>-->
                        <!--<prop key="sql.show">true</prop>-->
                        <!--<prop key="executor.size">10</prop>-->
                        <!--<prop key="foo">bar</prop>-->
                <!--</master-slave:props>-->
        <!--</master-slave:data-source>-->
   
        <bean id="singleKeyHashShardingAlgorithm1" 
class="com.pptv.ucm.dao.sharding.SingleKeyHashShardingAlgorithm1" />
   
   
   
   
        <!--<sharding:master-slave-data-source id="masterSlaveDataSource"-->
                <!--master-data-source-ref="defaultDataSource" 
slave-data-sources-ref="readDataSource" />-->
        <sharding:standard-strategy id="orderTableStrategy" 
sharding-column="order_id" 
precise-algorithm-ref="singleKeyHashShardingAlgorithm1" />
        <sharding:standard-strategy id="userTableStrategy" 
sharding-column="user_account" 
precise-algorithm-ref="singleKeyHashShardingAlgorithm1" />
        <sharding:standard-strategy id="macTableStrategy" sharding-column="mac" 
precise-algorithm-ref="singleKeyHashShardingAlgorithm1" />
        <sharding:standard-strategy id="macPointRecordStrategy" 
sharding-column="mac" precise-algorithm-ref="singleKeyHashShardingAlgorithm1" />
        <sharding:standard-strategy id="userPointRecordStrategy" 
sharding-column="user_account" 
precise-algorithm-ref="singleKeyHashShardingAlgorithm1" />
   
        <!--<sharding:inline-strategy id="orderTableStrategy" 
sharding-column="order_id" algorithm-expression=""/>-->
        <!--<sharding:inline-strategy id="userTableStrategy" 
sharding-column="user_account"-->
                                                          
<!--algorithm-expression=""/>-->
        <!--<sharding:inline-strategy id="macTableStrategy" 
sharding-column="mac"-->
                                                          
<!--algorithm-expression=""/>-->
        <!--<sharding:inline-strategy id="macPointRecordStrategy" 
sharding-column="mac"-->
                                                          
<!--algorithm-expression="" />-->
        <!--<sharding:inline-strategy id="userPointRecordStrategy" 
sharding-column="user_account"-->
                                                          
<!--algorithm-expression=""   />-->
   
        <sharding:data-source id="shardingDataSource">
                <sharding:sharding-rule 
data-source-names="defaultDataSource,readDataSource">
                        <sharding:master-slave-rules>
                                <sharding:master-slave-rule  
id="defaultDataSource0" master-data-source-name="defaultDataSource" 
slave-data-source-names="readDataSource"  />
   
                        </sharding:master-slave-rules>
                        <sharding:table-rules>
                                <sharding:table-rule logic-table="ucm_order"
                                                                         
actual-data-nodes="ucm_order_$->{0..9}" table-strategy-ref="orderTableStrategy" 
  />
                                <sharding:table-rule 
logic-table="ucm_subscriber"
                                                                         
actual-data-nodes="ucm_subscriber_$->{0..9}" 
table-strategy-ref="userTableStrategy" />
                                <sharding:table-rule logic-table="ucm_mac_goods"
                                                                         
actual-data-nodes="ucm_mac_goods_$->{0..9}"      
table-strategy-ref="macTableStrategy" />
                                <sharding:table-rule 
logic-table="ucm_mac_points_record"
                                                                         
actual-data-nodes="ucm_mac_points_record_$->{0..9}"      
table-strategy-ref="macPointRecordStrategy" />
                                <sharding:table-rule 
logic-table="ucm_user_points_income_record"
                                                                         
actual-data-nodes="ucm_user_points_income_record_$->{0..9}"      
table-strategy-ref="userPointRecordStrategy" />
                        </sharding:table-rules>
                </sharding:sharding-rule>
        </sharding:data-source>
   
   
        <bean id="sqlSessionFactory" 
class="org.mybatis.spring.SqlSessionFactoryBean">
                <property name="dataSource" ref="shardingDataSource" />
   
                <property name="mapperLocations" 
value="classpath:mapper/*.Mapper.xml"></property>
                <property name="configLocation" 
value="classpath:config/mybatis-config.xml" />
        </bean>
   
   
   
        <bean id="transactionManager"
                
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="shardingDataSource" />
        </bean>
   
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
                <tx:attributes>
                        <tx:method name="get*" read-only="true" />
                        <tx:method name="find*" read-only="true" />
                        <tx:method name="query*" read-only="true" />
                        <tx:method name="is*" read-only="true" />
                        <tx:method name="do*" propagation="REQUIRES_NEW"
                                rollback-for="java.lang.Exception" />
                        <tx:method name="save*" propagation="REQUIRED"
                                rollback-for="java.lang.Exception" />
                        <tx:method name="update*" propagation="REQUIRED"
                                rollback-for="java.lang.Exception" />
                        <tx:method name="insert*" propagation="REQUIRED"
                                rollback-for="java.lang.Exception" />
                        <tx:method name="delete*" propagation="REQUIRED"
                                rollback-for="java.lang.Exception" />
                </tx:attributes>
        </tx:advice>
        <aop:config>
                <aop:pointcut id="pc"
                        expression="execution(* 
com.pptv.ucm.service.impl.*.*(..))" />
                <aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
        </aop:config>
   
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
                <property name="annotationClass" 
value="org.springframework.stereotype.Repository" />
                <property name="basePackage" value="com.pptv.ucm.dao" />
                
                <property name="sqlSessionFactoryBeanName" 
value="sqlSessionFactory" />
        </bean>
   </beans>`
   
   SingleKeyHashShardingAlgorithm1.class
   `package com.pptv.ucm.dao.sharding;
   
   import 
org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
   import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
   import 
org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
   import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
   
   import java.util.Collection;
   import java.util.HashSet;
   import java.util.Set;
   
   import static java.lang.Math.abs;
   /**
    *
    */
   //public class SingleKeyHashShardingAlgorithm1 implements 
/*SingleKeyTableShardingAlgorithm<String>,*/PreciseShardingAlgorithm, 
RangeShardingAlgorithm<Integer> {
   public class SingleKeyHashShardingAlgorithm1  implements 
PreciseShardingAlgorithm<String> {
   
   
        @Override
        public String doSharding(Collection<String> collection, 
PreciseShardingValue<String> preciseShardingValue) {
                int mod = abs(preciseShardingValue.getValue().hashCode()) % 
collection.size();
                System.out.println("SingleKeyHashShardingAlgorithm1 current mod 
= " + mod);
                String suffix = mod + "";
                for(String each: collection) {
                if(each.endsWith(suffix)) {
                return each;
                }
                }
                throw new IllegalArgumentException();
                }
   
   
   
   
   
        public static void main(String[] args) {
                String s = null;
                int i = Math.abs("00:25:92:EE:6F:EE".hashCode()) % 10;
                System.out.println(i);
        }
   
   
   }
   `
   
   
   
   When I started the project,
   
   Caused by: org.springframework.beans.BeanInstantiationException: Failed to 
instantiate 
[org.apache.shardingsphere.shardingjdbc.spring.datasource.SpringShardingDataSource]:
 Constructor threw exception; nested exception is 
org.apache.shardingsphere.core.exception.ShardingConfigurationException: 
Invalid format for actual data nodes: 'ucm_order_0'
        at 
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
        at 
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
        at 
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
        ... 113 more
   Caused by: 
org.apache.shardingsphere.core.exception.ShardingConfigurationException: 
Invalid format for actual data nodes: 'ucm_order_0'
        at org.apache.shardingsphere.core.rule.DataNode.<init>(DataNode.java:52)
        at 
org.apache.shardingsphere.core.rule.TableRule.generateDataNodes(TableRule.java:141)
        at 
org.apache.shardingsphere.core.rule.TableRule.<init>(TableRule.java:100)
        at 
org.apache.shardingsphere.core.rule.ShardingRule.createTableRules(ShardingRule.java:99)
        at 
org.apache.shardingsphere.core.rule.ShardingRule.<init>(ShardingRule.java:85)
        at 
org.apache.shardingsphere.shardingjdbc.spring.datasource.SpringShardingDataSource.<init>(SpringShardingDataSource.java:38)
        at sun.reflect.GeneratedConstructorAccessor28.newInstance(Unknown 
Source)
        at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at 
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
   
   
   
   
   
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to