This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new d8176dc fix: avoid duplicate auto-generated id (#3003)
d8176dc is described below
commit d8176dca63ce756b5005b1d1968e81025adc2d0c
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Dec 10 15:13:09 2020 +0800
fix: avoid duplicate auto-generated id (#3003)
Fix #2950
Signed-off-by: spacewander <[email protected]>
---
apisix/core/etcd.lua | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua
index 07af2b0..76484e4 100644
--- a/apisix/core/etcd.lua
+++ b/apisix/core/etcd.lua
@@ -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