您当前的位置: 首页 > 

33MyCat - 分片规则(ASCII码求模范围约束)

杨林伟 发布时间:2019-07-25 17:43:50 ,浏览量:2

此种规则类似于取模范围约束,此规则支持数据符号字母取模。


 
	 user_id
	 sharding-by-prefixpattern
 
 


	 256
	 5
	 partition-pattern.txt
 

partition-pattern.txt:

partition-pattern.txt
# range start-end ,data node index
# ASCII
# 8-57=0-9阿拉伯数字
# 64、65-90=@、A-Z
# 97-122=a-z
###### first host configuration
1-4=0
5-8=1
9-12=2
13-16=3
###### second host configuration
17-20=4
21-24=5
25-28=6
29-32=7
0-0=7

配置说明: 上面columns 标识将要分片的表字段,algorithm 分片函数,patternValue 即求模基数,prefixLength ASCII 截取的位数。

mapFile 配置文件路径: 配置文件中,1-32 即代表id%256后分布的范围,如果在1-32则在分区1,其他类推。

此种方式类似方式6只不过采取的是将列种获取前prefixLength位列所有ASCII码的和进行求模sum%patternValue ,获取的值,在范围内的分片数

String idVal=“gf89f9a”;
Assert.assertEquals(true, 0==autoPartition.calculate(idVal));
idVal=“8df99a”;
Assert.assertEquals(true, 4==autoPartition.calculate(idVal));
idVal=“8dhdf99a”;Assert.assertEquals(true,3==autoPartition.calculate(idVal));
关注
打赏
1688896170
查看更多评论

杨林伟

暂无认证

  • 2浏览

    0关注

    3183博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1236s