From 4fa071b0bf6528f0df399ec0a9f405033f49d586 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 17 Jan 2025 10:46:00 +0800 Subject: [PATCH] refactor(clustering): use tools.table.EMPTY to avoid overhead --- kong/clustering/control_plane.lua | 3 ++- kong/clustering/services/sync/rpc.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kong/clustering/control_plane.lua b/kong/clustering/control_plane.lua index 9426d38d8660..057e117d259b 100644 --- a/kong/clustering/control_plane.lua +++ b/kong/clustering/control_plane.lua @@ -9,6 +9,7 @@ local compat = require("kong.clustering.compat") local constants = require("kong.constants") local events = require("kong.clustering.events") local calculate_config_hash = require("kong.clustering.config_helper").calculate_config_hash +local EMPTY = require("kong.tools.table").EMPTY local string = string @@ -260,7 +261,7 @@ function _M:handle_cp_websocket(cert) labels = data.labels, cert_details = dp_cert_details, -- only update rpc_capabilities if dp_id is connected - rpc_capabilities = rpc_peers and rpc_peers[dp_id] or {}, + rpc_capabilities = rpc_peers and rpc_peers[dp_id] or EMPTY, }, { ttl = purge_delay, no_broadcast_crud_event = true, }) if not ok then ngx_log(ngx_ERR, _log_prefix, "unable to update clustering data plane status: ", err, log_suffix) diff --git a/kong/clustering/services/sync/rpc.lua b/kong/clustering/services/sync/rpc.lua index 56e2a9f1d271..1d706d4c8ee9 100644 --- a/kong/clustering/services/sync/rpc.lua +++ b/kong/clustering/services/sync/rpc.lua @@ -8,6 +8,7 @@ local constants = require("kong.constants") local concurrency = require("kong.concurrency") local isempty = require("table.isempty") local events = require("kong.runloop.events") +local EMPTY = require("kong.tools.table").EMPTY local insert_entity_for_txn = declarative.insert_entity_for_txn @@ -94,7 +95,7 @@ function _M:init_cp(manager) cert_details = node_info.cert_details, -- get from rpc call sync_status = CLUSTERING_SYNC_STATUS.NORMAL, config_hash = default_namespace_version, - rpc_capabilities = rpc_peers and rpc_peers[node_id] or {}, + rpc_capabilities = rpc_peers and rpc_peers[node_id] or EMPTY, }, { ttl = purge_delay, no_broadcast_crud_event = true, }) if not ok then ngx_log(ngx_ERR, "unable to update clustering data plane status: ", err)