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 2019/10/02 11:19:31 UTC
[GitHub] [incubator-shardingsphere] Pramy opened a new pull request #3165:
Support time server database for issues 1497
Pramy opened a new pull request #3165: Support time server database for issues 1497
URL: https://github.com/apache/incubator-shardingsphere/pull/3165
Change-Id: I515015c3c9c5d04bd1e0dddec29500d1f5f93064
Support #1497 .
Changes proposed in this pull request:
- [x] Parse now() for MySQL
- [x] Define a datatime database server in configuration
- [x] Get current time from datatime database server
- [x] Route by current time
Changes
Configuration
```
dataSources:
ds_0: !!com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_d_0
username: root
password: root
ds_1: !!com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_d_1
username: root
password: root
shardingRule:
tables:
ts_order:
actualDataNodes: ds_0.ts_order_0000,ds_0.ts_order_0001,ds_1.ts_order_0002,ds_1.ts_order_0003
databaseStrategy:
inline:
shardingColumn: id
algorithmExpression: ds_${new BigDecimal(id).abs().divideAndRemainder(4)[1].longValue().intdiv(2)}
tableStrategy:
inline:
shardingColumn: id
algorithmExpression: ts_order_${String.format("%04d",new BigDecimal(id).abs().divideAndRemainder(4)[1].longValue())}
timeServerDataSourceName: ds_1
props:
sql.show: true
```
Sharding column: `id`
for update
```
Logic SQL: update ts_order set create_time = now() where create_time < now();
Actual SQL: update ts_order_0000 set create_time = '2019-10-02 19:12:20.0' where create_time < '2019-10-02 19:12:20.0';
```
for insert
```
Logic SQL: insert INTO ts_order values (2,2, NOW());
Actual SQL: insert INTO ts_order_0002(id, value, create_time) values (2, 2, '2019-10-02 19:16:37.0')
```
----------------------------------------------------------------
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