当前位置:网站首页>Distributed id generator implementation
Distributed id generator implementation
2022-08-09 06:33:00 【In the history of the strongest disciple】
随着业务的扩展的需要,分库是很多业务必不可少的操作,而分完库之后分布式id 生成缺成了一个问题,需要分布式id 服务生成.
1.获取分布式id 角色会有三个角色,分为:业务服务,分布式id节点服务,分布式id 中心服务.
2. 请求流程两个流程:
业务服务 --> 分布式id节点服务获取号码(根据号码段和号码规则还有set 编号生成id).
业务服务 --> 分布式id节点服务获取号码 ->分布式id 中心服务获取号码段及号码规则.
3.号码规则:
前缀+时间戳+唯一编号
4.数据库设计
4.1 tb_id_config id 配置
Field name | Type | Comment | Remark |
---|---|---|---|
id | PK | ||
table_name | String | 表名 | |
service_name | String | 服务名 | |
colum_name | String | id,number | |
init_number | int | 初始值 | |
add_number | int | 增值 | |
create_time | dateTime | 创建时间 | |
update_time | dateTime | 修改时间 |
4.2.tb_id_config_regular id 配置规则
Field name | Type | Comment | Remark |
---|---|---|---|
id | PK | ||
type | Integer | 1.前缀,2.时间戳,3.号码段 | |
keywords | String | 关键词(前缀时) | |
create_time | dateTime | 创建时间 | |
update_time | dateTime | 修改时间 |
4.3.tb_id_operator_log id 操作log 日志
Field name | Type | Comment | Remark |
---|---|---|---|
id | PK | ||
config_id | FK | tb_id_config id | |
unique_key | String | 唯一key | |
min_number | Integer | 号段最小值 | |
max_number | Integer | 号段最大值 | |
config_number | Integer | 配置号(获取号段的redis 分布式节点服务号) | |
create_time | dateTime | 创建时间 | |
update_time | dateTime | 修改时间 | |
version | Integer | 数据版本 |
4.4 插入log ,在通过unique_key 查询出来,这个是针对每个分布式id节点服务请求生成的唯一键
EXPLAIN
INSERT INTO `tb_id_operator_log` ( `config_id`, `unique_key`, `min_number`, `max_number`, create_time, update_time ) SELECT
1,
2,
min_number + 1000,
max_number + 1000,now(),now()
FROM
tb_id_operator_log
WHERE
config_id = 1
ORDER BY
id DESC
LIMIT 1
4.5分布式id节点服务,会把号段信息以及号配置信息存放到redis 计数器中,业务来一个请求redis 计数器获取后+1,注意这里当号段使用号段到60%,需要缓存下一个号端,避免使用完了,或者是等待中心发号段.
边栏推荐
- Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
- Fragments
- [R language] interaction test data
- el-table缓存数据
- golang zip aes base64
- DevNet: Deviation Aware Networkfor Lane Detection
- Simple Factory Pattern
- 简单工厂模式
- How to find package information and pin definitions for NXP S32K1xx series microcontrollers
- 【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal
猜你喜欢
[GO], arrays and slices
无重复的字符的最长子串
Data center project preliminary summary
ByteDance Interview Questions: Mirror Binary Tree 2020
ZIP压缩包文件删除密码的方法
推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
INSTALL_RPATH and BUILD_RPATH problem in CMake
A test engineer with an annual salary of 35W was laid off. Personal experience: advice that you have to listen to
e-learning summary
随机推荐
Use baidu EasyDL intelligent bin
中英文说明书丨TRC D-阿卓糖(D-Altrose)
常用Oracle命令
GNNExplainer applied to node classification task
crc计算
Service
String.toLowerCase(Locale.ROOT)
普罗米修斯原理及节点发布
golang zip aes base64
电学知识的疑问
P6阿里机试题之2020 斐波那契数
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
Import the pycharm environment package into another environment
Word文件的只读模式没有密码怎么退出?
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
详解C语言中的wait()函数和waitpid()函数
mmdetection源码解析--ResNet18
APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
Silently start over, the first page is also a new page
什么是excel文件保护