mycat1.6.5分片(字符串拆分hash)

来源:互联网 发布:2017淘宝活动 编辑:程序博客网 时间:2024/05/16 01:11

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_string" primaryKey="ord_no" dataNode="dn$0-2"   rule="partition-by-string" /></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-string"><rule><columns>ord_no</columns><algorithm>partition-by-string</algorithm></rule></tableRule><function name="partition-by-string"class="io.mycat.route.function.PartitionByString"><property name="partitionLength">512</property> <!-- zero-based --><property name="partitionCount">2</property><property name="hashSlice">-6:0</property></function></mycat:rule>
三、规则文件信息

四、测试用到的sql

=============按照ord_no字段 字符串hash ================CREATE TABLE  partition_by_string  (ord_no varchar(20) NULL,`db_nm`  varchar(20) NULL);INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022237582, database());INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022553756, database());select * from partition_by_string;
五、注意事项

分片数量必须小于等于dataNode数

六、参数说明

length代表字符串hash求模基数,count分区数,其中length*count=1024

hashSlice hash预算位,即根据子字符串中int值 hash运算

0 代表 str.length(), -1 代表 str.length()-1,大于0只代表数字自身

可以理解为substring(start,end),start为0则只表示0

例1:值“45abc”,hash预算位0:2 ,取其中45进行计算

例2:值“aaaabbb2345”,hash预算位-4:0 ,取其中2345进行计算






原创粉丝点击