From 243e817e999324ac8d5b23037876aee7a5720100 Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Wed, 7 Mar 2018 10:43:42 +0800 Subject: Solve IP-Hash issue Use deepcopy to avoid the side effect, which cause the client request is forward to wrong service instance occassionally. Issue-ID: MSB-154 Change-Id: I51e04fb273c2ca13c43b1e66fab44424e6af837e Signed-off-by: HuabingZhao --- .../openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'openresty-ext/src/assembly/resources/openresty') diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua index b3cd46e..344b261 100644 --- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua +++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua @@ -31,7 +31,7 @@ local LUCKY_NUM = 13 local tbl_util = require('lib.utils.table_util') local tbl_isempty = tbl_util.isempty -local tbl_isequal = require('pl.tablex') +local tablex = require('pl.tablex') local peerwatcher = require "core.peerwatcher" local ngx_var = ngx.var local hash_data = {} @@ -73,10 +73,10 @@ end local function update_consistent_hash_state(hash_data,servers,svckey) -- compare servers in ctx with servers in cache -- update the hash data if changes occur - local serverscache = hash_data[svckey].servers + local serverscache = tablex.deepcopy(hash_data[svckey].servers) tab_sort(serverscache, function(a, b) return a.ip < b.ip end) tab_sort(servers, function(a, b) return a.ip < b.ip end) - if not tbl_isequal.deepcompare(serverscache, servers, false) then + if not tablex.deepcompare(serverscache, servers, false) then local tmp_chash = init_consistent_hash_state(servers) hash_data[svckey].servers =servers hash_data[svckey].chash = tmp_chash -- cgit 1.2.3-korg