You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by Pramy Mr <pr...@gmail.com> on 2019/10/09 13:40:09 UTC

[Discuss] How to design a plan for using now() as sharding key?

hello. I want to solve the issues [1].
I have a idea
1. add a spi for getting date before routing, default value is return new
Date().

I want to add this spi into ConditionValue, return a Date when
expressionSegment is
now() expression

Considering that the date is not accurate to the second level, the date is
allowed to have a slight error.

[1] https://github.com/apache/incubator-shardingsphere/issues/1497

Re: [Discuss] How to design a plan for using now() as sharding key?

Posted by "zhangliang@apache.org" <zh...@apache.org>.
Thank you for focus this issue. This idea is pretty good.

We can define a SPI name as TimeService and provide a default
implementation for return `new Date()` only.
And then we can provide a MySQL implementation for execute `select now()`.
The MySQL configuration can be configured by properties.

A suggestion for using SPI, we may not pass the SPI into `ConditionValue`,
`ConditionValue` should not aware SPI about time result, please make the
current date just a regular sharding value.

------------------

Liang Zhang (John)
Apache ShardingSphere & Dubbo


Pramy Mr <pr...@gmail.com> 于2019年10月9日周三 下午9:40写道:

> hello. I want to solve the issues [1].
> I have a idea
> 1. add a spi for getting date before routing, default value is return new
> Date().
>
> I want to add this spi into ConditionValue, return a Date when
> expressionSegment is
> now() expression
>
> Considering that the date is not accurate to the second level, the date is
> allowed to have a slight error.
>
> [1] https://github.com/apache/incubator-shardingsphere/issues/1497
>