zoukankan      html  css  js  c++  java
  • Mycat之按照时间进行分片

    一、日期列分区法
    <tableRule name="sharding-by-date">
          <rule>
            <columns>create_time</columns>
            <algorithm>sharding-by-date</algorithm>
          </rule>
       </tableRule> 
    <function name="sharding-by-date" class="io.mycat.route.function..PartitionByDate">
       <property name="dateFormat">yyyy-MM-dd</property>
        <property name="sBeginDate">2014-01-01</property>
        <property name="sPartionDay">10</property>
      </function>
    配置说明:
    上面columns 标识将要分片的表字段,algorithm 分片函数,
    配置中配置了开始日期,分区天数,即默认从开始日期算起,分隔10天一个分区
     
    二、枚举法
    <tableRule name="sharding-by-intfile">
        <rule>
          <columns>user_id</columns>
          <algorithm>hash-int</algorithm>
        </rule>
      </tableRule>
    <function name="hash-int" class="io.mycat.route.function.PartitionByFileMap">
        <property name="mapFile">partition-hash-int.txt</property>
        <property name="type">0</property>
        <property name="defaultNode">0</property>
      </function>
     
    partition-hash-int.txt 配置:
    10000=0
    10010=1
    上面columns 标识将要分片的表字段,algorithm 分片函数,
    其中分片函数配置中,mapFile标识配置文件名称,type默认值为0,0表示Integer,非零表示String,
    所有的节点配置都是从0开始,及0代表节点1
    /**
    *  defaultNode 默认节点:小于0表示不设置默认节点,大于等于0表示设置默认节点,结点为指定的值

    默认节点的作用:枚举分片时,如果碰到不识别的枚举值,就让它路由到默认节点
    *                如果不配置默认节点(defaultNode值小于0表示不配置默认节点),碰到
    *                不识别的枚举值就会报错,
    *                like this:can't find datanode for sharding column:column_name val:ffffffff    
    */
     
    三、通配取模
    <tableRule name="sharding-by-pattern">
          <rule>
            <columns>user_id</columns>
            <algorithm>sharding-by-pattern</algorithm>
          </rule>
       </tableRule>
    <function name="sharding-by-pattern" class="io.mycat.route.function.PartitionByPattern">
        <property name="patternValue">256</property>
        <property name="defaultNode">2</property>
        <property name="mapFile">partition-pattern.txt</property>
     
      </function>
    partition-pattern.txt 
    # id partition range start-end ,data node index
    ###### first host configuration
    1-32=0
    33-64=1
    65-96=2
    97-128=3
    ######## second host configuration
    129-160=4
    161-192=5
    193-224=6
    225-256=7
    0-0=7
    配置说明:
    上面columns 标识将要分片的表字段,algorithm 分片函数,patternValue 即求模基数,defaoultNode 默认节点,如果不配置了默认,则默认是0即第一个结点
    mapFile 配置文件路径
    配置文件中,1-32 即代表id%256后分布的范围,如果在1-32则在分区1,其他类推,如果id非数字数据,则会分配在defaoultNode 默认节点
    四、求模法
    <tableRule name="mod-long">
        <rule>
          <columns>user_id</columns>
          <algorithm>mod-long</algorithm>
        </rule>
      </tableRule>
      <function name="mod-long" class="io.mycat.route.function.PartitionByMod">
       <!-- how many data nodes  -->
        <property name="count">3</property>
      </function>
     
    配置说明:
    上面columns 标识将要分片的表字段,algorithm 分片函数,
    此种配置非常明确即根据id与count(你的结点数)进行求模预算,相比方式1,此种在批量插入时需要切换数据源,id不连续
  • 相关阅读:
    20135313_exp4
    20135313_exp5
    学习分块
    学习BM算法
    学习笛卡尔树
    【数学】Eddy Walker
    【bitset】Kth Minimum Clique
    【搜索】n的约数
    【搜索】Partition problem
    【信息学奥赛一本通 提高组】第四章 广搜的优化技巧
  • 原文地址:https://www.cnblogs.com/juniorMa/p/14338271.html
Copyright © 2011-2022 走看看