Question 1:
I have configured a strategy of sub table:
The configuration file is as follows:
<bean id="preciseModuloTableShardingAlgorithm"
class="com.jd.bdp.cv.common.PreciseModuloShardingTableAlgorithm" />
<bean id="rangeModuloShardingTableAlgorithm"
class="com.jd.bdp.cv.common.RangeModuloShardingTableAlgorithm" />
<sharding:standard-strategy id="tableShardingStrategy"
sharding-column="task_id"
precise-algorithm-ref="preciseModuloTableShardingAlgorithm"
range-algorithm-ref="rangeModuloShardingTableAlgorithm"/>
<sharding:data-source id="shardingDataSource">
<sharding:sharding-rule data-source-names="cv_dataSource">
<sharding:table-rules>
<sharding:table-rule logic-table="cv_user_task"
actual-data-nodes="cv_dataSource.cv_user_task_${0..1}"
table-strategy-ref="tableShardingStrategy" />
</sharding:table-rules>
<!-- <sharding:binding-table-rules>
<sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
</sharding:binding-table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_address"/>
</sharding:broadcast-table-rules>-->
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">true</prop>
</sharding:props>
</sharding:data-source>
My sub table logic is as follows:
if (shardingValue.getValue()<7800){
return "cv_user_task_0";
}
else {
Long modValue = shardingValue.getValue() % tableNames.size();
String modStr = modValue.toString();
for (String each : tableNames) {
if (each.endsWith(modStr)) {
return each;
}
}
}
throw new IllegalArgumentException();
The specific logic is as follows: in order to be compatible with the old data,
when the shardingvalue is less than a certain value (such as 1230), query the
previous table, and when it is greater than a certain value, use the table
splitting logic. The sub table logic is routed according to the modular
operation. But I found that this logic did not take effect. There are two
specific problems:
1. When debugging, you can only enter the doshading method for the first time,
and then the breakpoint will not enter.
2. All the table fields in my database are smaller than 1230, so the original
table CV user task should be selected according to the logic, but still go to
CV user task 0, CV user task 1 from the console
And no data can be found. So I suspect that if the table is not defined in the
actual data nodes = "cv_datasource. Cv_user_task" ${0.. 1} ", the data cannot
be queried. After testing, I found that my suspicion is correct. It can be
queried to put the historical data into the two tables CV ﹣ user ﹣ task ﹣ 0 and
CV ﹣ user ﹣ task ﹣ 1. But what about my historical data? (must data migration
be performed)
Question two:
After I use sharding, the function now () in SQL is not supported (using
mybatis)
Report errors:
Data truncation: Incorrect datetime value: 'now()' for column 'created'
at row 1
Question three:
To test my sub table logic, it is written as follows:
@Override
public String doSharding(final Collection<String> tableNames, final
PreciseShardingValue<Long> shardingValue) {
return "cv_user_task_0";
}
I configured the return values to cv_user_task_0
But from the console
Both CV user task 0 and CV user task 1 are not valid at all. The queried data
is also in the CV user task table.
Is it because of my configuration?