zoukankan      html  css  js  c++  java
  • Mycat_枚举分片

    版本:

    Jdk1.8

    Mycat 1.6

    Mysql 5.5.53

     

    运用场景:

    一般用于固定数字或者字符串分类的数据表,例如按省份,区号等分类。

    Rule.xml

    <tableRule name="sharding-by-intfile">

    <rule>

    <columns>name</columns>

    <algorithm>hash-int</algorithm>

    </rule>

    </tableRule>

     

    sharding-by-intfile是规则名,在schema.xml中用

    columns是对指定字段进行分片

    algorithm是算法名,该算法必须在function中定义。

     

    <!--枚举分片函数-->

    <function name="hash-int"

    class="io.mycat.route.function.PartitionByFileMap">

    <property name="mapFile">partition-hash-int.txt</property>

    <property name="type">1</property>

    <property name="defaultNode">0</property>

    </function>

    mapFile是配置文件名

    Type分片类型,默认值为00表示Integer,非零表示String

    defaultNode 默认节点小于0表示不设置默认节点,大于等于0表示设置默认节点

     

    cq=0

    sz=1

    hn=2

     

    Cq会被分发到第一个节点中,sz分发被第二个节点中,hn第三个节点中。

     

    总结:

    1. 刚开始没有指定functiontype的值,即<property name="type">1</property>。导致insert时报以下错误,因为默认的分片类型是integer,而不是string;

     

    2. 如果没有指定functiondefaultNode值,则插入不识别的枚举值时,会报错;

     

    3. MyCAT支持动态加载功能

    defaultNode的值定义到partition-hash-int-test.txt前提注释掉functiondefaultNode值,不然function中的defaultNode值会覆盖掉partition-hash-int-test.txtdefaultNode值。

    cq=0

    sz=1

    hn=2

    defaultNode=2

     

  • 相关阅读:
    BZOJ2243: [SDOI2011]染色
    BZOJ3747: [POI2015]Kinoman
    BZOJ1293: [SCOI2009]生日礼物
    BZOJ3626 [LNOI2014]LCA
    BZOJ3514 Codechef MARCH14 GERALD07加强版
    BZOJ3295 [CQOI2011]动态逆序对
    BZOJ2588 [SPOJ10628]Count on a tree
    BZOJ1036 [ZJOI2008]树的统计Count
    CODEVS1490 [CTSC2008]网络管理
    BZOJ1070 [SCOI2007]修车
  • 原文地址:https://www.cnblogs.com/chensStudy/p/12610923.html
Copyright © 2011-2022 走看看