Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Sharding-jdbc的几点求证和建议? #438

Closed
cocodroid opened this issue Nov 14, 2017 · 4 comments
Closed

关于Sharding-jdbc的几点求证和建议? #438

cocodroid opened this issue Nov 14, 2017 · 4 comments

Comments

@cocodroid
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

Which version of Sharding-Jdbc do you using?

2.0.0.M2

使用mybatis跑了一下,总结出几点,希望有空帮忙确认下是否有问题?
只分表:
1、可以配置分表或不分表,分不分表都走sj的解析(可以用多数据源解决不分表不走sj的解析)。
2、不执行insert values(),()...批量操作,即使是分表或者未分表(由1得知)。
3、使用默认分布式id主键,insert时不能指定id字段。
只分库:
4、默认分布式id主键,生成偶数,数据往一个库倒,另一个库基本没数据,只要使数据奇偶生成均匀,就能均匀分配到两个库。
分库分表:
5、不要使用同一字段作为分片键,分库分表的依据,不然数据更加不均匀分布(可能造成部分表一直没数据)。
Master-Slave:
6、需要自己用外部工具实现主从同步。

麻烦确认下这6点是否正确或者有问题,谢谢。

另外关于数据不均匀的情况,有个建议或者想法吧。我打算在分片算法里面增加ThreadLocal来让其均匀分配,不知是否可以?
如:
`
ThreadLocal threadLocal = new ThreadLocal(){
@OverRide
protected AtomicInteger initialValue() {
return new AtomicInteger(0);
}
};

@Override
public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Long> shardingValue) {
    String s = threadLocal.get().getAndIncrement() % 4 + "";
    for (String each : availableTargetNames) {
        if(each.endsWith(s)){
            return each;
        }
    }
    throw new UnsupportedOperationException();
}`

麻烦有时间回复下,十分感谢!

@terrymanu
Copy link
Member

  1. 已经立项,请参见issue 支持只是读写分离的场景,可以透穿任何sql #439
  2. 已经立项,请参见issue Support batch INSERT #290
  3. 请详细说明,应该是可以的
  4. 请阅读faq第9个问题:http://shardingjdbc.io/docs/01-start/faq/
  5. 分片策略和分片键是应用开发者自己定的,与sharding-jdbc无关,sharding-jdbc只提供分片的平台
  6. 请阅读读写分离文档,不支持项部分:http://shardingjdbc.io/docs/02-guide/master-slave/

关于最后的建议,我们只是忠实的实现了snowflake算法,不会对其进行修改。分布式主键生成策略可以自己定制。再次重申,sharding-jdbc只提供平台,各种需要已预留接口,或算法实现,请自行扩展。

除了第三个问题未确定,其他问题文档和issue中都已提及。因此issue先关闭了。第三个问题请再试试,若有问题,请独立提交issue,并参照issue提交格式填充所需信息,以便于定位。

@cocodroid
Copy link
Contributor Author

@terrymanu 好的,多谢了

@cocodroid
Copy link
Contributor Author

第三个问题:#443

@jimforcode
Copy link

jimforcode commented Jan 2, 2018

问题4 可以用多线程测试, 在一个毫秒内有多条数据生成就不会全是偶数了, 感觉这也是 雪花算法的一个弊端, 就是如果并发弱的情况下,数据就不均衡了,不过这不是sharejdbc 的核心问题,只是不可避免要考虑的因素

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants