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

     

  • 相关阅读:
    二进制或者其他进制转为十进制
    十进制转为二进制或者其他进制
    0.1 + 0.2 !== 0.3
    [git]删除远程分支
    [git]一个本地仓库,多个远程仓库
    [git]用户名,邮箱
    npm install命令
    常用命令:查看端口
    std::lock_guard 与 std::unique_lock
    std::mutex
  • 原文地址:https://www.cnblogs.com/chensStudy/p/12610923.html
Copyright © 2011-2022 走看看