分布式 | DBLE 分区算法系列总结

原创: 管长龙mysql


 

咱们已经经过以前的六篇文章,介绍了 DBLE 和 MyCat 常见的六种分片算法,那么咱们来作个总结吧!算法

DBLE 与 MyCat 对应分片算法名和异同sql


第七种 DBLE分片算法—jumpStringHash

除了以上六种常见的分片算法以外,DBLE 还独有一种分片算法:跳跃字符串算法。spa

具体配置以下:code

#rule.xml
<function name="jumphash"
class="jumpStringHash">
<property name="partitionCount">2</property>
<property name="hashSlice">0:2</property>
</function>

partitionCont:分片数量xml

hashSlice:分片截取长度blog

该算法来自于 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"string

至此,咱们DBLE中支持的七种分片算法就介绍完了,相信读者朋友对 DBLE 的使用也慢慢熟悉。hash

系列文章的最后:

完整分区实例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dble:rule SYSTEM "rule.dtd">
<dble:rule xmlns:dble="http://dble.cloud/" 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">12
相关文章
相关标签/搜索