You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "kingluo (via GitHub)" <gi...@apache.org> on 2023/04/07 07:32:18 UTC

[GitHub] [apisix] kingluo commented on a diff in pull request #9259: avoid creating the whole radixtree while changing one route

kingluo commented on code in PR #9259:
URL: https://github.com/apache/apisix/pull/9259#discussion_r1160504439


##########
apisix/core/config_etcd.lua:
##########
@@ -463,6 +480,76 @@ local function sync_data(self)
         end
 
         self.conf_version = self.conf_version + 1
+
+        if self.key ~= "/apisix/routes" then
+            goto CONTINUE
+        end
+
+        local route
+        if res.value then
+            local status = table.try_read_attr(res, "value", "status")
+            if status and status == 0 then
+                goto CONTINUE
+            end
+
+            local filter_fun, err
+            if res.value.filter_func then
+                filter_fun, err = loadstring(
+                    "return " .. res.value.filter_func,
+                    "router#" .. res.value.id
+                )
+                if not filter_fun then
+                    log.error("failed to load filter function: ", err, " route id", res.value.id)
+                        goto CONTINUE
+                end
+
+                filter_fun = filter_fun()
+            end
+
+            route = {
+                id = res.value.id,
+                paths = res.value.uris or res.value.uri,
+                methods = res.value.methods,
+                priority = res.value.priority,
+                hosts = res.value.hosts or res.value.host,
+                remote_addrs = res.value.remote_addrs or res.value.remote_addr,
+                vars = res.value.vars,
+                filter_fun = filter_fun,
+                handler = function(api_ctx, match_opts)
+                    api_ctx.matched_params = nil
+                    api_ctx.matched_route = res
+                    api_ctx.curr_req_matched = match_opts.matched
+                end
+            }
+        end
+
+        local router_opts = {
+            no_param_match = true
+        }
+        local router_mod = require("apisix.router")
+        if op == 2 then
+            log.notice("create routes watched from etcd into radixtree.", json.encode(res))
+            err = router_mod.uri_router:add_route(route, router_opts)

Review Comment:
   Where's the source code of the new methods of the router, e.g. `add_route`?



-- 
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