-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
问题
下面这个生成唯一id的代码, 如果服务器时间突然增加,会导致插入很多未来的 记录.
这些记录在服务器时间修正回来之后长时间不能超时占用内存.
现在的代码
local function next_seq(self, timestamp)
local seq, err_msg = self.guid_dict:incr(timestamp, 1)
if err_msg == nil then
return seq
end
seq = 0
local is_ok = self.guid_dict:safe_add(timestamp, seq, self.key_exptime)
if is_ok == true then
return seq
end
seq, err_msg = self.guid_dict:incr(timestamp, 1)
if err_msg == nil then
return seq
end
return nil, 'IncrSequenceError', err_msg
end
修正
- 这个函数中维护一个进程内的变量, 记录最大见到的时间, 如果遇到时间回退, 直接报错, 避免错误数据扩展.
未完...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels