当前位置:网站首页>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%,需要缓存下一个号端,避免使用完了,或者是等待中心发号段.
边栏推荐
- DevNet: Deviation Aware Networkfor Lane Detection
- Program Performance Analysis - Complexity Analysis
- CMake中INSTALL_RPATH与BUILD_RPATH问题
- Built-in macros in C language (define log macros)
- leetcode 之 70 爬楼梯问题 (斐波那契数)
- uniapp实现防抖搜索
- String.toLowerCase(Locale.ROOT)
- 运放-运算放大器经典应用电路大全-应用电路大全
- 移远EC20 4G模块拨号相关
- 推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
猜你喜欢
Fragments
Go lang1.18入门精炼教程——第一章:环境搭建
变压器的工作原理(图解,原理图讲解,一看就懂)
leetcode 之 零移位
Excel受保护的工作表怎么操作?
install flask
安装flask
Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)
无重复的字符的最长子串
The solution that does not work and does not take effect after VScode installs ESlint
随机推荐
Qt learning (3) - Qt module
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
io.lettuce.core。RedisCommandTimeoutException命令超时
Data center project preliminary summary
APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
常用Oracle命令
Explain the wait() function and waitpid() function in C language in detail
Likou Brush Question 180
我入职阿里后,才知道原来简历这么写
The singleton pattern
简单工厂模式
Simple to use Lambda expressions
[R language] interaction test data
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
DDD 领域驱动设计
Invalid argument(s) appears when redis runs lua script
语句加锁分析
变压器的工作原理(图解,原理图讲解,一看就懂)
C语言的内置宏(定义日志宏)