前言:
现在朋友们对“分区管理算法适应”都比较看重,朋友们都想要剖析一些“分区管理算法适应”的相关内容。那么小编也在网络上搜集了一些关于“分区管理算法适应””的相关内容,希望各位老铁们能喜欢,小伙伴们快快来了解一下吧!DBLE 与 MyCat 对应分片算法名和异同
第七种 DBLE分片算法—jumpStringHash
除了以上六种常见的分片算法之外,DBLE 还独有一种分片算法:跳跃字符串算法。
具体配置如下:
#rule.xml<function name="jumphash" class="jumpStringHash"> <property name="partitionCount">2</property> <property name="hashSlice">0:2</property></function>
partitionCont:分片数量
hashSlice:分片截取长度
该算法来自于 Google 的一篇文章《A Fast, Minimal Memory, Consistent Hash Algorithm》其核心思想是通过概率分布的方法将一个hash值在每个节点分布的概率变成1/n,并且可以通过更简便的方法可以计算得出,而且分布也更加均匀。
注意事项:分片字段值为NULL时,数据恒落在0号节点之上;当真实存在于mysql的字段值为not null的时候,报错 "Sharding column can't be null when the table in MySQL column is not null"
至此,我们DBLE中支持的七种分片算法就介绍完了,相信读者朋友对 DBLE 的使用也慢慢熟悉。
系列文章的最后:
完整分区实例
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE dble:rule SYSTEM "rule.dtd"><dble:rule xmlns:dble="; version="9.9.9.9"> <tableRule name="sharding-by-enum"> <rule> <columns>id</columns> <algorithm>enum</algorithm> </rule> </tableRule> <tableRule name="sharding-by-range"> <rule> <columns>id</columns> <algorithm>rangeLong</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash"> <rule> <columns>id</columns> <algorithm>hashLong</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash2"> <rule> <columns>id</columns> <algorithm>hashLong2</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash3"> <rule> <columns>id</columns> <algorithm>hashLong3</algorithm> </rule> </tableRule> <tableRule name="sharding-by-mod"> <rule> <columns>id</columns> <algorithm>hashmod</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash-str"> <rule> <columns>id</columns> <algorithm>hashString</algorithm> </rule> </tableRule> <tableRule name="sharding-by-date"> <rule> <columns>calldate</columns> <algorithm>partbydate</algorithm> </rule> </tableRule> <tableRule name="sharding-by-pattern"> <rule> <columns>id</columns> <algorithm>pattern</algorithm> </rule> </tableRule> <!-- enum partition --> <function name="enum" class="Enum"> <property name="mapFile">partition-hash-int.txt</property> <property name="defaultNode">0</property><!--the default is -1,means unexpected value will report error--> <property name="type">0</property><!--0 means key is a number, 1 means key is a string--> </function> <!-- number range partition --> <function name="rangeLong" class="NumberRange"> <property name="mapFile">autopartition-long.txt</property> <property name="defaultNode">0</property><!--he default is -1,means unexpected value will report error--> </function> <!-- Hash partition,when partitionLength=1, it is a mod partition--> <!--MAX(sum(count*length[i]) must not more then 2880--> <function name="hashLong" class="Hash"> <property name="partitionCount">8</property> <property name="partitionLength">128</property> <!-- <property name="partitionCount">2,3</property> <property name="partitionLength">4,5</property>--> </function> <!-- Hash partition,when partitionLength=1, it is a mod partition--> <!--MAX(sum(count*length[i]) must not more then 2880--> <function name="hashLong2" class="Hash"> <property name="partitionCount">2</property> <property name="partitionLength">512</property> <!-- <property name="partitionCount">2,3</property> <property name="partitionLength">4,5</property>--> </function> <!-- Hash partition,when partitionLength=1, it is a mod partition--> <!--MAX(sum(count*length[i]) must not more then 2880--> <function name="hashLong3" class="Hash"> <property name="partitionCount">2,1</property> <property name="partitionLength">256,512</property> <!-- <property name="partitionCount">2,3</property> <property name="partitionLength">4,5</property>--> </function> <!-- eg: mod 4 --> <function name="hashmod" class="Hash"> <property name="partitionCount">4</property> <property name="partitionLength">1</property> </function> <!-- Hash partition for string--> <function name="hashString" class="StringHash"> <property name="partitionCount">8</property> <property name="partitionLength">128</property> <property name="hashSlice">0:2</property> <!--<property name="hashSlice">-4:0</property> --> </function> <!-- date partition --> <!-- 4 case: 1.set sEndDate and defaultNode: input <sBeginDate ,router to defaultNode; input>sEndDate ,mod the period 2.set sEndDate, but no defaultNode:input <sBeginDate report error; input>sEndDate ,mod the period 3.set defaultNode without sEndDate: input <sBeginDate router to defaultNode;input>sBeginDate + (node size)*sPartionDay-1 will report error(expected is defaultNode,but can't control now) 4.sEndDate and defaultNode are all not set: input <sBeginDate report error;input>sBeginDate + (node size)*sPartionDay-1 will report error --> <function name="partbydate" class="Date"> <property name="dateFormat">yyyy-MM-dd</property> <property name="sBeginDate">2015-01-01</property> <property name="sEndDate">2015-01-31 </property> <!--if not set sEndDate,then in fact ,the sEndDate = sBeginDate+ (node size)*sPartionDay-1 --> <property name="sPartionDay">10</property> <property name="defaultNode">0</property><!--the default is -1--> </function> <!-- pattern partition --> <!--mapFile must contains all value of 0~patternValue-1,key and value must be Continuous increase--> <function name="pattern" class="PatternRange"> <property name="mapFile">partition-pattern.txt</property> <property name="patternValue">1024</property> <property name="defaultNode">0</property><!--contains string which is not number,router to default node--> </function></dble:rule>
左右滑动进行查看
标签: #分区管理算法适应