MyCat生产实践--一致性hash分片&扩容


1、 mycat一致性hash算法分片测试结果

配置el_user_user_info表使用一致性hash算法进行分片。
schema.xml



<mycat:schema xmlns:mycat="http://io.mycat/">
        <schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100">
            <table name="el_user_user_info" dataNode="dn$1-2" rule="sharding-by-murmur-userid" />
        schema>
        <dataNode name="dn$1-16" dataHost="localhost1" database="db$1-16" />
                <dataHost name="localhost1" maxCon="500" minCon="100" 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>

rule.xml



<mycat:rule xmlns:mycat="http://io.mycat/">

        <tableRule name="sharding-by-murmur-userid">
                <rule>
                        <columns>UserIDcolumns>
                        <algorithm>murmur-useridalgorithm>
                rule>
        tableRule>
        <function name="murmur-userid" class="io.mycat.route.function.PartitionByMurmurHash">
                <property name="seed">0property>
                <property name="type">1property>
                <property name="count">2property>
                <property name="virtualBucketTimes">160property>
                
                <property name="bucketMapPath">/usr/local/mycat/logs/bucketMapPath-murmur-useridproperty>
                
        function>
mycat:rule>

使用一致性hash算法(murmur),在MyCat中插入49911条数据,分为2个分片,数据量基本平衡。
MyCat生产实践--一致性hash分片&扩容_第1张图片

2、 mycat一致性hash算法扩容测试结果

先看扩容后的结果:
MyCat生产实践--一致性hash分片&扩容_第2张图片

有两种扩容方案:

方案一、

a) 停止数据服务,导出全部分片表数据,进行备份;
b) 清空分片表;
c) 在mycat中重新导入分片表,完成迁移。
这种方案缺点很明显,需要导出导入的数据量大时,操作很费时,且容易出错。

方案二、

a) 修改MyCAT配置,使用扩容后的配置启动;
b) 自己编写脚本,利用MyCAT的explain语法,分析出各个MySQL节点中分片表需要重新hash的数据,并记录ID(或数据)到文件中;
b) 导出各节点中的需要重新hash的数据进行备份,
c) 确认备份无误,清除原节点中的数据记录;
c) 在mycat中重新导入备份的数据,完成迁移。

你可能感兴趣的:(MyCAT)