Mycat 分片规则详解--应用指定分片
- 实现方式:根据字符串的子串(必须是数字)计算分区号(由调用方传递参数,显示指定分区号),例如,id=05-12232323,其中 id 是从 startIndex = 0,size=2,即截取的子串是 05 ,05 就是获取的分区,如果大于分区数,则分配到 defaultPartition 分区中
- 优点:可以在运行阶段,由应用自主决定路由到那个分片
- 缺点:需要应用实现分片规则
-
配置示例:
<tableRule name="rule1">
<rule>
<columns>id</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>
<function name="func1" class="io.mycat.route.function.PartitionDirectBySubString">
<property name="startIndex">0</property>
<property name="size">2</property>
<property name="partitionCount">8</property>
<property name="defaultPartition">5</property>
</function>
-
相关属性:
- startIndex:截取子串的开始位置
- size:截取长度
- partitionCount:分区数量
- defaultPartition:默认分区号
本文版权归作者 李雪(博客地址:https://www.cnblogs.wiki)所有,欢迎转载和商用,请在文章页面明显位置给出原文链接并保留此段声明,否则保留追究法律责任的权利,其他事项,可留言咨询。
浙公网安备 33010602011771号