HotDB全局自增序列介绍

2022-03-14 00:00:00 序列 节点 分片 全局 设置为

全局自增序列,是指表的AUTO_INCREMENT列在整个分布式系统中的各个节点间有序自增。HotDB Server提供全局AUTO_INCREMENT的支持,当表中包含AUTO_INCREMENT列,并且在server.xml文件中,将参数autoIncrement设置为非0(1或2))时,即可以像使用MySQL的AUTO_INCRMENT一样使用计算节点的全局AUTO_INCREMENT。配置示例如:

若将参数autoIncrement设置为0,则自增字段在存储节点MySQL内维护;在表类型为分片表时,表现较明显,可能存在同一分片表,不同存储节点间自增序列重复的情况。

例如:customer为auto分片表,分片字段为id,且name定义为自增序列。则name的自增特性由各个存储节点控制:

mysql> create table customer(id int ,name int auto_increment primary key);
mysql> insert into customer values (1,null),(2,null),(3,null),(4,null);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates:0 Warnings: 0
mysql> select * from customer;
±—

±-----±---- +
| id | name | DNID |
±—±-----±---- +
| 4 | 1 | 1001 |
| 2 | 1 | 1006 |
| 3 | 1 | 1004 |
| 1 | 1 | 1008 |
±—±-----±---- +
4 rows in set (0.00 sec)

参数设置为1

若将参数autoIncrement设置为1,则由计算节点接管所有表的自增,可以保证全局自增。

mysql> create table table_test(id tinyint auto_increment primary key);
Query OK, 0 rows affected, 1 warning (0.05 sec)
Warning (Code 10212): auto_increment column must be bigint or int

自增序列1模式可保证全局且严格正向增长,但不保证自增连续性。

来源 https://zhuanlan.zhihu.com/p/396326837


相关文章