Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid duplicate auto-generated id #3003

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apisix/core/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,16 @@ end


function _M.push(key, value, ttl)
local etcd_cli, prefix, err = new()
local etcd_cli, _, err = new()
if not etcd_cli then
return nil, err
end

local res, err = etcd_cli:readdir(prefix .. key)
-- Create a new revision and use it as the id.
-- It will be better if we use snowflake algorithm like manager-api,
-- but we haven't found a good library. It costs too much to write
-- our own one as the admin-api will be replaced by manager-api finally.
local res, err = set("/gen_id", 1)
if not res then
return nil, err
end
Expand Down