This is an automated email from the ASF dual-hosted git repository.

AlinsRan 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 59558bed2 chore(core): remove the dead clean_handlers mechanism 
(#13761)
59558bed2 is described below

commit 59558bed24b7e3f6620ea72087d69497a444b142
Author: AlinsRan <[email protected]>
AuthorDate: Thu Jul 30 13:07:17 2026 +0800

    chore(core): remove the dead clean_handlers mechanism (#13761)
---
 apisix/control/v1.lua         |  2 --
 apisix/core/config_etcd.lua   | 26 ----------------
 apisix/core/config_util.lua   | 72 -------------------------------------------
 apisix/core/config_xds.lua    |  5 ---
 apisix/core/config_yaml.lua   | 13 +-------
 apisix/plugin.lua             |  1 -
 docs/en/latest/control-api.md |  8 -----
 t/core/config_etcd.t          |  1 -
 t/core/config_util.t          | 47 ----------------------------
 9 files changed, 1 insertion(+), 174 deletions(-)

diff --git a/apisix/control/v1.lua b/apisix/control/v1.lua
index f3e2fa071..856bbeea3 100644
--- a/apisix/control/v1.lua
+++ b/apisix/control/v1.lua
@@ -278,7 +278,6 @@ local function iter_add_get_routes_info(values, route_id)
         new_route.checker = nil
         new_route.checker_idx = nil
         new_route.checker_upstream = nil
-        new_route.clean_handlers = nil
         core.table.insert(infos, new_route)
         -- check the route id
         if route_id and route.value.id == route_id then
@@ -361,7 +360,6 @@ local function iter_add_get_services_info(values, svc_id)
         new_svc.checker = nil
         new_svc.checker_idx = nil
         new_svc.checker_upstream = nil
-        new_svc.clean_handlers = nil
         core.table.insert(infos, new_svc)
         -- check the service id
         if svc_id and svc.value.id == svc_id then
diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua
index 79a66bf88..d7d6f1971 100644
--- a/apisix/core/config_etcd.lua
+++ b/apisix/core/config_etcd.lua
@@ -21,7 +21,6 @@
 
 local table        = require("apisix.core.table")
 local config_local = require("apisix.core.config_local")
-local config_util  = require("apisix.core.config_util")
 local log          = require("apisix.core.log")
 local json         = require("apisix.core.json")
 local etcd_apisix  = require("apisix.core.etcd")
@@ -561,9 +560,6 @@ end
 local function load_full_data(self, dir_res, headers, prev_values, 
prev_values_hash)
     local err
     local changed = false
-    -- previous items carried over because their new data failed the check;
-    -- their clean handlers must NOT be fired
-    local carried = {}
 
     if self.single_item then
         self.values = new_tab(1, 0)
@@ -593,8 +589,6 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
             insert_tab(self.values, item)
             self.values_hash[self.key] = #self.values
 
-            item.clean_handlers = {}
-
             if self.filter then
                 self.filter(item)
             end
@@ -609,7 +603,6 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
                          "], keep the previous configuration, err: ", err)
                 insert_tab(self.values, prev_item)
                 self.values_hash[self.key] = #self.values
-                carried[prev_item] = true
             end
         end
 
@@ -662,7 +655,6 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
                 self.values_hash[key] = #self.values
 
                 item.value.id = key
-                item.clean_handlers = {}
 
                 if self.filter then
                     self.filter(item)
@@ -678,7 +670,6 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
                              "], keep the previous configuration, err: ", err)
                     insert_tab(self.values, prev_item)
                     self.values_hash[key] = #self.values
-                    carried[prev_item] = true
                 end
             end
 
@@ -686,16 +677,6 @@ local function load_full_data(self, dir_res, headers, 
prev_values, prev_values_h
         end
     end
 
-    -- fire the clean handlers of the previous items that were not carried
-    -- over: they were either replaced by a new value or deleted from etcd
-    if prev_values then
-        for _, item in ipairs(prev_values) do
-            if item and not carried[item] then
-                config_util.fire_all_clean_handlers(item)
-            end
-        end
-    end
-
     if headers then
         self.prev_index = tonumber(headers["X-Etcd-Index"]) or 0
         self:upgrade_version(headers["X-Etcd-Index"])
@@ -837,18 +818,12 @@ local function sync_data(self)
 
         local pre_index = self.values_hash[key]
         if pre_index then
-            local pre_val = self.values[pre_index]
-            if pre_val then
-                config_util.fire_all_clean_handlers(pre_val)
-            end
-
             if res.value then
                 if not self.single_item then
                     res.value.id = key
                 end
 
                 self.values[pre_index] = res
-                res.clean_handlers = {}
                 log.info("update data by key: ", key)
 
             else
@@ -859,7 +834,6 @@ local function sync_data(self)
             end
 
         elseif res.value then
-            res.clean_handlers = {}
             insert_tab(self.values, res)
             self.values_hash[key] = #self.values
             if not self.single_item then
diff --git a/apisix/core/config_util.lua b/apisix/core/config_util.lua
index 3ff65796f..358241b3c 100644
--- a/apisix/core/config_util.lua
+++ b/apisix/core/config_util.lua
@@ -19,11 +19,8 @@
 --
 -- @module core.config_util
 
-local core_tab = require("apisix.core.table")
-local log = require("apisix.core.log")
 local str_byte = string.byte
 local str_char = string.char
-local ipairs = ipairs
 local setmetatable = setmetatable
 local tostring = tostring
 local type = type
@@ -52,75 +49,6 @@ function _M.iterate_values(tab)
 end
 
 
--- Add a clean handler to a runtime configuration item.
--- The clean handler will be called when the item is deleted from configuration
--- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
--- Return an index so that we can cancel it later.
-function _M.add_clean_handler(item, func)
-    if not item.clean_handlers then
-        return nil, "clean handlers for the item are nil"
-    end
-
-    if not item.clean_handlers._id then
-        item.clean_handlers._id = 1
-    end
-
-    local id = item.clean_handlers._id
-    item.clean_handlers._id = item.clean_handlers._id + 1
-    core_tab.insert(item.clean_handlers, {f = func, id = id})
-    return id
-end
-
-
--- cancel a clean handler added by add_clean_handler.
--- If `fire` is true, call the clean handler.
-function _M.cancel_clean_handler(item, idx, fire)
-    local pos, f
-    -- the number of pending clean handler is small so we can cancel them in 
O(n)
-    for i, clean_handler in ipairs(item.clean_handlers) do
-        if clean_handler.id == idx then
-            pos = i
-            f = clean_handler.f
-            break
-        end
-    end
-
-    if not pos then
-        log.error("failed to find clean_handler with idx ", idx)
-        return
-    end
-
-    core_tab.remove(item.clean_handlers, pos)
-    if not fire then
-        return
-    end
-
-    if f then
-        f(item)
-    else
-        log.error("The function used to clear the health checker is nil, 
please check")
-    end
-end
-
-
--- fire all clean handlers added by add_clean_handler.
-function _M.fire_all_clean_handlers(item)
-    -- When the key is deleted, the item will be set to false.
-    if not item then
-        return
-    end
-    if not item.clean_handlers then
-        return
-    end
-
-    for _, clean_handler in ipairs(item.clean_handlers) do
-        clean_handler.f(item)
-    end
-
-    item.clean_handlers = {}
-end
-
-
 ---
 -- Convert different time units to seconds as time units.
 -- Time intervals can be specified in milliseconds, seconds, minutes, hours, 
days and so on,
diff --git a/apisix/core/config_xds.lua b/apisix/core/config_xds.lua
index bdb45206a..86fc6ca72 100644
--- a/apisix/core/config_xds.lua
+++ b/apisix/core/config_xds.lua
@@ -20,7 +20,6 @@
 -- @module core.config_xds
 
 local config_local      = require("apisix.core.config_local")
-local config_util       = require("apisix.core.config_util")
 local string            = require("apisix.core.string")
 local log               = require("apisix.core.log")
 local json              = require("apisix.core.json")
@@ -151,9 +150,6 @@ local function sync_data(self)
     end
 
     if self.values then
-        for _, val in ipairs(self.values) do
-            config_util.fire_all_clean_handlers(val)
-        end
         self.values = nil
         self.values_hash = nil
     end
@@ -211,7 +207,6 @@ local function sync_data(self)
                                    key = key}
                 insert_tab(self.values, conf_item)
                 self.values_hash[conf.id] = #self.values
-                conf_item.clean_handlers = {}
 
                 if self.filter then
                     self.filter(conf_item)
diff --git a/apisix/core/config_yaml.lua b/apisix/core/config_yaml.lua
index a57d15dd6..c61f1f362 100644
--- a/apisix/core/config_yaml.lua
+++ b/apisix/core/config_yaml.lua
@@ -20,7 +20,6 @@
 -- @module core.config_yaml
 
 local config_local = require("apisix.core.config_local")
-local config_util  = require("apisix.core.config_util")
 local yaml         = require("lyaml")
 local log          = require("apisix.core.log")
 local json         = require("apisix.core.json")
@@ -244,21 +243,15 @@ local function sync_data(self)
                 exist_items[tostring(item.id)] = true
             end
             -- remove objects that exist in the self.values but do not exist 
in the new items.
-            -- for removed items, trigger cleanup handlers.
             for _, item in ipairs(self.values) do
                 local id = item.value.id
-                if not exist_items[id]  then
-                    config_util.fire_all_clean_handlers(item)
-                else
+                if exist_items[id] then
                     insert_tab(exist_values, item)
                     self.values_hash[id] = #exist_values
                 end
             end
             self.values = exist_values
         else
-            for _, item in ipairs(self.values) do
-                config_util.fire_all_clean_handlers(item)
-            end
             self.values = nil
         end
     end
@@ -296,7 +289,6 @@ local function sync_data(self)
         if data_valid then
             insert_tab(self.values, conf_item)
             self.values_hash[self.key] = #self.values
-            conf_item.clean_handlers = {}
 
             if self.filter then
                 self.filter(conf_item)
@@ -349,16 +341,13 @@ local function sync_data(self)
                     local pre_val = self.values[pre_index]
                     if pre_val and
                         (not item.modifiedIndex or pre_val.modifiedIndex ~= 
item.modifiedIndex) then
-                        config_util.fire_all_clean_handlers(pre_val)
                         self.values[pre_index] = conf_item
                         conf_item.value.id = item_id
-                        conf_item.clean_handlers = {}
                     end
                 else
                     insert_tab(self.values, conf_item)
                     self.values_hash[item_id] = #self.values
                     conf_item.value.id = item_id
-                    conf_item.clean_handlers = {}
                 end
 
                 if self.filter then
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index a2898bc0d..7a0159fd9 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -1494,7 +1494,6 @@ local function merge_global_rules(global_rules, 
conf_version)
         },
         createdIndex = conf_version,
         modifiedIndex = conf_version,
-        clean_handlers = {},
     }
 
     return dummy_global_rule
diff --git a/docs/en/latest/control-api.md b/docs/en/latest/control-api.md
index 4a5e6e9a5..ae7f59d0e 100644
--- a/docs/en/latest/control-api.md
+++ b/docs/en/latest/control-api.md
@@ -231,7 +231,6 @@ Returns all configured [Routes](./terminology/route.md):
       },
       "status": 1
     },
-    "clean_handlers": {},
     "has_domain": false,
     "orig_modifiedIndex": 1631193445,
     "modifiedIndex": 1631193445,
@@ -269,7 +268,6 @@ Returns the Route with the specified `route_id`:
     },
     "status": 1
   },
-  "clean_handlers": {},
   "has_domain": false,
   "orig_modifiedIndex": 1631193445,
   "modifiedIndex": 1631193445,
@@ -287,7 +285,6 @@ Returns all the Services:
 [
   {
     "has_domain": false,
-    "clean_handlers": {},
     "modifiedIndex": 671,
     "key": "/apisix/services/200",
     "createdIndex": 671,
@@ -334,7 +331,6 @@ Returns the Service with the specified `service_id`:
 ```json
 {
   "has_domain": false,
-  "clean_handlers": {},
   "modifiedIndex": 728,
   "key": "/apisix/services/5",
   "createdIndex": 728,
@@ -392,8 +388,6 @@ Dumps all Upstreams:
       },
       "has_domain":true,
       "key":"\/apisix\/upstreams\/1",
-      "clean_handlers":{
-      },
       "createdIndex":938,
       "modifiedIndex":1225
    }
@@ -432,8 +426,6 @@ Dumps the Upstream with the specified `upstream_id`:
    },
    "has_domain":true,
    "key":"\/apisix\/upstreams\/1",
-   "clean_handlers":{
-   },
    "createdIndex":938,
    "modifiedIndex":1225
 }
diff --git a/t/core/config_etcd.t b/t/core/config_etcd.t
index 16deda060..a40f425b6 100644
--- a/t/core/config_etcd.t
+++ b/t/core/config_etcd.t
@@ -747,7 +747,6 @@ nginx_config:
             local stale = {
                 key = "/apisix/global_rules/ghost",
                 modifiedIndex = 1,
-                clean_handlers = {},
                 value = {id = "ghost", plugins = {}},
             }
             core.table.insert(obj.values, stale)
diff --git a/t/core/config_util.t b/t/core/config_util.t
index 6d9e1e2f8..80f01a5d2 100644
--- a/t/core/config_util.t
+++ b/t/core/config_util.t
@@ -70,50 +70,3 @@ __DATA__
             end
         }
     }
-
-
-
-=== TEST 2: add_clean_handler / cancel_clean_handler / fire_all_clean_handlers
---- config
-    location /t {
-        content_by_lua_block {
-            local util = require("apisix.core.config_util")
-            local function setup()
-                local item = {clean_handlers = {}}
-                local idx1 = util.add_clean_handler(item, function()
-                    ngx.log(ngx.WARN, "fire one")
-                end)
-                local idx2 = util.add_clean_handler(item, function()
-                    ngx.log(ngx.WARN, "fire two")
-                end)
-                return item, idx1, idx2
-            end
-
-            local function setup_to_false()
-                local item = false
-                return item
-            end
-
-            local item, idx1, idx2 = setup()
-            util.cancel_clean_handler(item, idx1, true)
-            util.cancel_clean_handler(item, idx2, true)
-
-            local item, idx1, idx2 = setup()
-            util.fire_all_clean_handlers(item)
-
-            local item, idx1, idx2 = setup()
-            util.cancel_clean_handler(item, idx2)
-            util.fire_all_clean_handlers(item)
-
-            local item, idx1, idx2 = setup()
-            util.cancel_clean_handler(item, idx1)
-            util.fire_all_clean_handlers(item)
-
-            local item = setup_to_false()
-            util.fire_all_clean_handlers(item)
-        }
-    }
---- grep_error_log eval
-qr/fire \w+/
---- grep_error_log_out eval
-"fire one\nfire two\n" x 3

Reply via email to