• mycat1.6.5分片(字符串拆分hash)


    https://blog.csdn.net/webnum/article/details/78313525

    分片规则:字符串拆分hash

    一、conf/schema.xml文件

    1.  
      <?xml version="1.0"?>
    2.  
      <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    3.  
      <mycat:schema xmlns:mycat="http://io.mycat/">
    4.  
      <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
    5.  
      <table name="partition_by_string" primaryKey="ord_no" dataNode="dn$0-2"
    6.  
      rule="partition-by-string" />
    7.  
      </schema>
    8.  
      <dataNode name="dn0" dataHost="dh-1" database="db0"/>
    9.  
      <dataNode name="dn1" dataHost="dh-1" database="db1"/>
    10.  
      <dataNode name="dn2" dataHost="dh-1" database="db2"/>
    11.  
      <dataHost name="dh-1" maxCon="1000" minCon="10" balance="0"
    12.  
      writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    13.  
      <heartbeat>select user()</heartbeat>
    14.  
      <writeHost host="hostM1" url="localhost:3306" user="root"
    15.  
      password="123456">
    16.  
      </writeHost>
    17.  
      </dataHost>
    18.  
      </mycat:schema>
    二、conf/rule.xml文件
    1.  
      <?xml version="1.0" encoding="UTF-8"?>
    2.  
      <!DOCTYPE mycat:rule SYSTEM "rule.dtd">
    3.  
      <mycat:rule xmlns:mycat="http://io.mycat/">
    4.  
      <tableRule name="partition-by-string">
    5.  
      <rule>
    6.  
      <columns>ord_no</columns>
    7.  
      <algorithm>partition-by-string</algorithm>
    8.  
      </rule>
    9.  
      </tableRule>
    10.  
      <function name="partition-by-string"
    11.  
      class="io.mycat.route.function.PartitionByString">
    12.  
      <property name="partitionLength">512</property> <!-- zero-based -->
    13.  
      <property name="partitionCount">2</property>
    14.  
      <property name="hashSlice">-6:0</property>
    15.  
      </function>
    16.  
      </mycat:rule>
    三、规则文件信息

    四、测试用到的sql

    1.  
      =============按照ord_no字段 字符串hash ================
    2.  
      CREATE TABLE partition_by_string (ord_no varchar(20) NULL,`db_nm` varchar(20) NULL);
    3.  
      INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022237582, database());
    4.  
      INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022553756, database());
    5.  
      select * from partition_by_string;
    五、注意事项

    分片数量必须小于等于dataNode数

    六、参数说明

    length代表字符串hash求模基数,count分区数,其中length*count=1024

    hashSlice hash预算位,即根据子字符串中int值 hash运算

    0 代表 str.length(), -1 代表 str.length()-1,大于0只代表数字自身

    可以理解为substring(start,end),start为0则只表示0

    例1:值“45abc”,hash预算位0:2 ,取其中45进行计算

    例2:值“aaaabbb2345”,hash预算位-4:0 ,取其中2345进行计算

  • 相关阅读:
    pointer-net
    pytorch0.4版的CNN对minist分类
    python+selenium遍历某一个标签中的内容
    selenium提取不了标签文本
    IndentationError: unindent does not match any outer indentation level
    windows下载安装mysql
    引用opencv异常
    jenkins简单安装及配置(Windows环境)
    多台服务器-SSH免密登录设置
    scheduleAtFixedRate 与 scheduleWithFixedDelay 的区别
  • 原文地址:https://www.cnblogs.com/kelelipeng/p/10345716.html
Copyright © 2020-2023  润新知