mycat1.6.5分片(一致性hash)
程序员文章站
2022-03-14 22:46:03
...
mycat one群:106088787。
分片规则:一致性hash
一、conf/schema.xml文件
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="partition_by_murmur_hash" primaryKey="id" dataNode="dn$0-2"
rule="partition-by-murmur-hash" />
</schema>
<dataNode name="dn0" dataHost="dh-1" database="db0"/>
<dataNode name="dn1" dataHost="dh-1" database="db1"/>
<dataNode name="dn2" dataHost="dh-1" database="db2"/>
<dataHost name="dh-1" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="localhost:3306" user="root"
password="123456">
</writeHost>
</dataHost>
</mycat:schema>
二、conf/rule.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
<tableRule name="partition-by-murmur-hash">
<rule>
<columns>id</columns>
<algorithm>partition-by-murmur-hash</algorithm>
</rule>
</tableRule>
<function name="partition-by-murmur-hash"
class="io.mycat.route.function.PartitionByMurmurHash">
<property name="seed">0</property><!-- 默认是0 -->
<property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
<property name="virtualBucketTimes">160</property><!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 -->
<!-- <property name="weightMapFile">weightMapFile</property> 节点的权重,没有指定权重的节点默认是1。以properties文件的格式填写,以从0开始到count-1的整数值也就是节点索引为key,以节点权重值为值。所有权重值必须是正整数,否则以1代替 -->
<!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property>
用于测试时观察各物理节点与虚拟节点的分布情况,如果指定了这个属性,会把虚拟节点的murmur hash值与物理节点的映射按行输出到这个文件,没有默认值,如果不指定,就不会输出任何东西 -->
</function>
</mycat:rule>
三、规则文件信息
无
四、测试用到的sql
=============按照id字段 一致性hash ================
CREATE TABLE partition_by_murmur_hash (id int(10) null,`db_nm` varchar(20) NULL);
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (1, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (2, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (3, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (4, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (5, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (6, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (7, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (8, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (9, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (10, database());
select * from partition_by_murmur_hash;
五、注意事项
1、数据库节点必须大于等于分片数
六、参数说明
上一篇: golang实现一致性哈希算法