• Mycat 分片规则详解--ASCII 取模范围分片


    • 实现方式:该算法与取模范围算法类似,该算法支持数值、符号、字母取模。首先截取长度为 prefixLength 的子串,在对子串中每一个字符的 ASCII 码求和,然后对求和值进行取模运算(sum%patternValue),就可以计算出子串的分片数
    • 优点:可以自主决定取模后数据的节点分布
    • 缺点:dataNode 划分节点是事先建好的,需要扩展时比较麻烦。
    • 配置示例

      <tableRule name="rule1">

      <rule>

      <columns>id</columns>

      <algorithm>func1</algorithm>

      </rule>

      </tableRule>

      <function name="func1" class="io.mycat.route.function.PartitionByPrefixPattern">

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

      <property name="patternValue">256</property>

      <property name="prefixLength">5</property>

      </function>

    • 相关属性:
      • mapFile:切分规则配置文件
      • patternValue:求模基数
      • prefixLength:截取的位数
      • partition-pattern.txt 示例:

        #range start-end,data node index

        1-32=1

        33-64=2

        65-128=3

        129-256=4

        0-0=5

      注意:在mapFile配置的文件中,其1-32 表示的为 id%256后分布的范围

  • 相关阅读:
    [BZOJ1303][CQOI2009]中位数图
    [BZOJ1192][HNOI2006]鬼谷子的钱袋
    9.5题解
    9.3题解
    9.2题解
    9.1题解
    8.29题解
    8.28题解
    8.23<2>题解
    8.23<1>题解
  • 原文地址:https://www.cnblogs.com/li3807/p/8461857.html
Copyright © 2020-2023  润新知