You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/11/04 11:29:28 UTC

[GitHub] [apisix] biakecw commented on a diff in pull request #8219: feat: validate the subordinate and check reference when deleting a stream …

biakecw commented on code in PR #8219:
URL: https://github.com/apache/apisix/pull/8219#discussion_r1013903931


##########
apisix/admin/stream_routes.lua:
##########
@@ -25,23 +27,69 @@ local _M = {
     need_v3_filter = true,
 }
 
+local function check_router_refer(items, id)
+    local refer_list = {}
+    local referkey = "/stream_routes_refer/" .. id
+    local _, err = core.etcd.delete(referkey)
+    core.log.warn(err)
+    core.log.warn(items)
+    for _, item in config_util.iterate_values(items) do
+        if item.value == nil then
+            goto CONTINUE
+        end
+        local r_id = string.gsub(item["key"], "/", "_")
+        local route = item.value
+        if route.protocol and route.protocol.superior_id then
+            local data
+            local setkey = "/stream_routes_refer/" .. route.protocol.superior_id
+            local res, err = core.etcd.get(setkey, false)
+            if res then
+                if res.body.node == nil then
+                    data = core.json.decode("{}")
+                    data[r_id] = 1
+                else
+                    data = res.body.node.value
+                    data[r_id] = 1
+                end
+            else
+                core.log.error("In function check_router_refer  error: ", err)
+            end
+            local setres, err = core.etcd.set(setkey, data)

Review Comment:
   The keys  stream_routes_refer/super_ids  will be update   rather than grow .  
   ex:
   
   /apisix/stream_routes_refer/12
   {"_apisix_stream_routes_22":1,"_apisix_stream_routes_23":1}  
   
   it meas the stream_route 22 and 23  have   protocol.superior_id  12; if the stream_routes rule  no change ,the value no change.
    



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org