Database Middleware points enum piece Algorithms

Foreword

Recently quite anxious, not knowing what to do next, what direction and yes. It can only be used 别慌,月亮也正在大海的某处迷茫。to comfort myself down. But learning of early heart we still do not forget. Today we learned that the enum slice algorithm.

1.hash partitioning algorithm
2.stringhash partitioning algorithm
3.enum分区算法
4.numberrange partitioning algorithm
5.patternrange partitioning algorithm
6.date partitioning algorithm
7.jumpstringhash algorithm

Enum configuration partition algorithm

<tableRule name="rule_enum">
        <rule>
            <columns>code</columns>
            <algorithm>func_enum</algorithm>
        </rule>
    </tableRule>

<function name="enum" class="enum">
<property name="mapFile">partition.txt</property>
<property name="defaultNode">0</property>
<property name="type">0</property>
</function>

enum and the previous hash algorithm is the same. TableRule and function need to be configured in rule.xml in.

  • tableRule tag, name is the name corresponding to the rule, the rule label the corresponding columns fragmentation field, which fields in the table must be consistent. algorithm represents the name's slicing function.
  • function name tag, name represents the name of slicing algorithm, algorithm to be above and tableRule Label, respectively. class: Specifies fragment algorithm classes. property specifies the parameters corresponding to fragmentation algorithm. Different algorithms different parameters.
  • mapFile: Specifies the configuration file name. The format will be described in detail below.
  • defaultNode: Specifies the default node number. The default value is -1, is not specified the default node.
  • type: specifies the type of key profile. 0: Integer; Other: string.

mapfile file format is configured as follows:
a.type = 0,
INT1 = NODE0
INT2 = node1

Other a.type =
string1 = node0
string2 = node1

1. boot loader configuration

When activated, it will first determine the type based on the value of a string or numeric. Then the value configured in mapfile loaded into memory, a mapping table is formed.
For example, in the above configuration type = 0, we can determine a number, and then view the corresponding files mapFile partition.txt, can be found:
10000 = 0
10010 = 1
is enumerated value 10000, it is stored in the slice 1, and enumeration value 10010, it is stored in the slice 2.

2. Run process

When the process is running, if a user by querying code = 10000 or code = 10001 and they will access the enumeration algorithm. According to the above mapping table to get direct access number of slices.

3. We build the table to test.

By creating test_enum table, we insert three data, respectively, code = 10000,10010,10020, 10000 could be seen on the stored slice 1, 10010 is stored in the slice 2. This document and we configured in partition.txt the same. When we insert 10020 when, as enumerated value does not exist, it will select the default slice node dn1. There will not be an error because of an error.
Enumeration when in use, need to be aware of an exhaustive list. But there are also disadvantages, is likely to under-inclusive, not at this time to enumerate the numbers stored in the definition of a default node is not the way, as if suddenly a new version on the line, some new enumerated type and there is no time update, the default node data will lead to rapid expansion. At this point on the need for expansion, then implement local data migration.

Precautions

  1. mapfile file does not contain "=" lines will be skipped.
  2. Repeated partition data node enumeration value subject to a final configuration.
  3. Enumerated type field for fragmentation.
  4. 分片字段为NULL时,数据落在defaultNode节点上,若此时defaultNode没有配置,则会报错;当真实存在于mysql的字段值为not null的时候,报错 "Sharding column can't be null when the table in MySQL column is not null"

后记

今天介绍的枚举算法较为简单。后续将继续带来剩下几种算法,谢谢支持!

Guess you like

Origin www.cnblogs.com/buddy-yuan/p/12159216.html