tokers commented on a change in pull request #6202:
URL: https://github.com/apache/apisix/pull/6202#discussion_r804491664



##########
File path: apisix/plugins/server-info.lua
##########
@@ -132,15 +124,24 @@ local function get_server_info()
 end
 
 
+local function set_lease_id(id)
+        -- update lease_id
+        local _, err = internal_status:set("lease_id", id)
+        if err ~= nil then
+            core.log.error("failed to set lease_id to shdict: ", err)
+        end
+end
+
+
 local function report(premature, report_ttl)
     if premature then
         return
     end
 
+    -- get apisix node info
     local server_info, err = get()
     if not server_info then
         core.log.error("failed to get server_info: ", err)
-        return

Review comment:
       Why removing this?

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +159,65 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, err = core.etcd.get(key)
+    if err ~= nil then
+        core.log.error("failed to get server_info from etcd: ", err)
+    end
+
+    if  not res.body.node then

Review comment:
       ```suggestion
       if not res.body.node then
   ```

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +159,65 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, err = core.etcd.get(key)
+    if err ~= nil then
+        core.log.error("failed to get server_info from etcd: ", err)
+    end
+
+    if  not res.body.node then
+        local res_new, err = core.etcd.set(key, server_info, report_ttl)

Review comment:
       So we don't have two similar code blocks.

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +159,65 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, err = core.etcd.get(key)
+    if err ~= nil then
+        core.log.error("failed to get server_info from etcd: ", err)

Review comment:
       if `err` is not `nil`, why can we go ahead?

##########
File path: apisix/plugins/server-info.lua
##########
@@ -158,25 +159,65 @@ local function report(premature, report_ttl)
         end
     end
 
-    server_info.last_report_time = ngx_time()
-
+    -- get inside etcd data, if not exist, create it
     local key = "/data_plane/server_info/" .. server_info.id
-    local ok, err = core.etcd.set(key, server_info, report_ttl)
+    local res, err = core.etcd.get(key)
+    if err ~= nil then
+        core.log.error("failed to get server_info from etcd: ", err)
+    end
+
+    if  not res.body.node then
+        local res_new, err = core.etcd.set(key, server_info, report_ttl)

Review comment:
       I think the logic for initial setting can be merged to the below logic 
(`modified_version` is zero).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to