当前位置:网站首页>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%,需要缓存下一个号端,避免使用完了,或者是等待中心发号段.
边栏推荐
- 分布式id 生成器实现
- 默默重新开始,第一页也是新的一页
- Error: flask: TypeError: 'function' object is not iterable
- Qt learning (3) - Qt module
- CalBioreagents超全Id 蛋白兔单克隆抗体,助力科研
- 移远EC20 4G模块拨号相关
- [GO], arrays and slices
- Word文件的只读模式没有密码怎么退出?
- The working principle of the transformer (illustration, schematic explanation, understand at a glance)
- db.sqlite3没有“as Data Source“解决方法
猜你喜欢
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
Use baidu EasyDL intelligent bin
缓存技术使用
Altium designer软件常用最全封装库,包含原理图库、PCB库和3D模型库
代码目录结构
db.sqlite3 has no "as Data Source" workaround
leetcode 之 70 爬楼梯问题 (斐波那契数)
ZIP压缩包文件删除密码的方法
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
Excel受保护的工作表怎么操作?
随机推荐
APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
字节跳动面试题之镜像二叉树2020
io.lettuce.core.RedisCommandTimeoutException Command timed out
运放-运算放大器经典应用电路大全-应用电路大全
中英文说明书丨CalBioreagents 醛固酮单克隆抗体
字节跳动笔试题2020 (抖音电商)
Import the pycharm environment package into another environment
DevNet: Deviation Aware Networkfor Lane Detection
Introduction of convenient functions and convenient shortcut keys of vs tomato assistant
默默重新开始,第一页也是新的一页
install flask
Common Oracle Commands
Error: flask: TypeError: 'function' object is not iterable
线程的6种状态
代码目录结构
C语言的内置宏(定义日志宏)
mmdetection源码解析--ResNet18
VS2019常用快捷键
一道很简答但是没答对的SQL题
vim 程序编辑器的基本操作(积累)