AlinsRan commented on code in PR #12214: URL: https://github.com/apache/apisix/pull/12214#discussion_r2094954939
########## apisix/core/config_yaml.lua: ########## @@ -158,29 +149,59 @@ local function sync_data(self) return nil, "missing 'key' arguments" end - if not apisix_yaml_mtime then - log.warn("wait for more time") - return nil, "failed to read local file " .. apisix_yaml_path + local conf_version + if is_use_admin_api() then + conf_version = apisix_yaml[self.conf_version_key] or 0 + else + if not apisix_yaml_mtime then + log.warn("wait for more time") + return nil, "failed to read local file " .. apisix_yaml_path + end + conf_version = apisix_yaml_mtime end - if self.conf_version == apisix_yaml_mtime then + if not conf_version or conf_version == self.conf_version then return true end local items = apisix_yaml[self.key] - log.info(self.key, " items: ", json.delay_encode(items)) if not items then self.values = new_tab(8, 0) self.values_hash = new_tab(0, 8) - self.conf_version = apisix_yaml_mtime + self.conf_version = conf_version return true end - if self.values then - for _, item in ipairs(self.values) do - config_util.fire_all_clean_handlers(item) + if self.values and #self.values > 0 then + if is_use_admin_api() then + -- used to delete values that do not exist in the new list. + -- only when using modifiedIndex, old values need to be retained. + -- If modifiedIndex changes, old values need to be removed and cleaned up. + local exist_modifiedIndex_items = {} + for _, item in ipairs(items) do + if item.modifiedIndex then + exist_modifiedIndex_items[tostring(item.id)] = true + end + end + + local new_values = new_tab(8, 0) + self.values_hash = new_tab(0, 8) + for _, item in ipairs(self.values) do + local id = item.value.id + if not exist_modifiedIndex_items[id] then + config_util.fire_all_clean_handlers(item) + else Review Comment: Isn't that how we handle it now? The prerequisite for exist_rodifiedIndex_items is to use id as the index, followed by modifiedIndex. -- 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-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org